SingleTickProfiler .java

net.minecraft.util.profiling.SingleTickProfiler (class): members: createTickProfiler, decorateFiller, saveThreshold, realTime, profiler, endTick, location.

net.minecraft.util.profilingclass51 linescommon1.8 KB

API Surface (3)

ProfilerFiller startTick()
void endTick()
ProfilerFiller decorateFiller(final ProfilerFiller filler, final @Nullable SingleTickProfiler tickProfiler)

Fields & Constants (6)

LOGGER
realTime
saveThreshold
tick
location
profiler

String literals (2)

"tick-results-"
".txt"

Code Graph: Dependencies (5)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SingleTickProfiler.java51 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.profiling;
2
3
import com.mojang.logging.LogUtils;
4
import java.io.File;
5
import java.util.function.LongSupplier;
6
import net.minecraft.SharedConstants;
7
import net.minecraft.util.Util;
8
import org.jspecify.annotations.Nullable;
9
import org.slf4j.Logger;
10
11
public class SingleTickProfiler {
12
	private static final Logger LOGGER = LogUtils.getLogger();
13
	private final LongSupplier realTime;
14
	private final long saveThreshold;
15
	private int tick;
16
	private final File location;
17
	private ProfileCollector profiler = InactiveProfiler.INSTANCE;
18
19
	public SingleTickProfiler(final LongSupplier realTime, final String location, final long saveThresholdNs) {
20
		this.realTime = realTime;
21
		this.location = new File("debug", location);
22
		this.saveThreshold = saveThresholdNs;
23
	}
24
25
	public ProfilerFiller startTick() {
26
		this.profiler = new ActiveProfiler(this.realTime, () -> this.tick, () -> true);
27
		this.tick++;
28
		return this.profiler;
29
	}
30
31
	public void endTick() {
32
		if (this.profiler != InactiveProfiler.INSTANCE) {
33
			ProfileResults results = this.profiler.getResults();
34
			this.profiler = InactiveProfiler.INSTANCE;
35
			if (results.getNanoDuration() >= this.saveThreshold) {
36
				File file = new File(this.location, "tick-results-" + Util.getFilenameFormattedDateTime() + ".txt");
37
				results.saveResults(file.toPath());
38
				LOGGER.info("Recorded long tick -- wrote info to: {}", file.getAbsolutePath());
39
			}
40
		}
41
	}
42
43
	public static @Nullable SingleTickProfiler createTickProfiler(final String name) {
44
		return SharedConstants.DEBUG_MONITOR_TICK_TIMES ? new SingleTickProfiler(Util.timeSource(), name, SharedConstants.MAXIMUM_TICK_TIME_NANOS) : null;
45
	}
46
47
	public static ProfilerFiller decorateFiller(final ProfilerFiller filler, final @Nullable SingleTickProfiler tickProfiler) {
48
		return tickProfiler != null ? ProfilerFiller.combine(tickProfiler.startTick(), filler) : filler;
49
	}
50
}
51

Decompiled Minecraft 26.3 source of SingleTickProfiler (net/minecraft/util/profiling/SingleTickProfiler.java) with Mojang official mappings, stored verbatim on the site.