TimedStatSummary .java

net.minecraft.util.profiling.jfr.stats.TimedStatSummary (record, 29 lines): members: fastest, slowest, secondSlowest, count, percentilesNanos, summary.

net.minecraft.util.profiling.jfr.statsrecord29 linescommonextends TimedStat>1.2 KB

API Surface (1)

<T extends TimedStat> Optional<TimedStatSummary<T>> summary(final List<T> values)

Code Graph: Dependencies (1)

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

Full Source

TimedStatSummary.java29 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.profiling.jfr.stats;
2
3
import java.time.Duration;
4
import java.util.Comparator;
5
import java.util.List;
6
import java.util.Map;
7
import java.util.Optional;
8
import net.minecraft.util.profiling.jfr.Percentiles;
9
import org.jspecify.annotations.Nullable;
10
11
public record TimedStatSummary<T extends TimedStat>(
12
	T fastest, T slowest, @Nullable T secondSlowest, int count, Map<Integer, Double> percentilesNanos, Duration totalDuration
13
) {
14
	public static <T extends TimedStat> Optional<TimedStatSummary<T>> summary(final List<T> values) {
15
		if (values.isEmpty()) {
16
			return Optional.empty();
17
		}
18
19
		List<T> sorted = values.stream().sorted(Comparator.comparing(TimedStat::duration)).toList();
20
		Duration totalDuration = sorted.stream().map(TimedStat::duration).reduce(Duration::plus).orElse(Duration.ZERO);
21
		T fastest = (T)sorted.getFirst();
22
		T slowest = (T)sorted.getLast();
23
		T secondSlowest = sorted.size() > 1 ? sorted.get(sorted.size() - 2) : null;
24
		int count = sorted.size();
25
		Map<Integer, Double> percentilesNanos = Percentiles.evaluate(sorted.stream().mapToLong(it -> it.duration().toNanos()).toArray());
26
		return Optional.of(new TimedStatSummary<>(fastest, slowest, secondSlowest, count, percentilesNanos, totalDuration));
27
	}
28
}
29

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