ThreadAllocationStat.java
net.minecraft.util.profiling.jfr.stats.ThreadAllocationStat
信息
- 全限定名:net.minecraft.util.profiling.jfr.stats.ThreadAllocationStat
- 类型:public record
- 包:net.minecraft.util.profiling.jfr.stats
- 源码路径:src/main/java/net/minecraft/util/profiling/jfr/stats/ThreadAllocationStat.java
- 起始行号:L13
- 职责:
TODO
字段/常量
UNKNOWN_THREAD- 类型:
String - 修饰符:
private static final - 源码定位:
L14 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.util.profiling.jfr.stats.ThreadAllocationStat.Summary- 类型:
record - 修饰符:
public - 源码定位:
L37 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static ThreadAllocationStat from(RecordedEvent event) @ L16
- 方法名:from
- 源码定位:L16
- 返回类型:ThreadAllocationStat
- 修饰符:public static
参数:
- event: RecordedEvent
说明:
TODO
public static ThreadAllocationStat.Summary summary(List<ThreadAllocationStat> stats) @ L22
- 方法名:summary
- 源码定位:L22
- 返回类型:ThreadAllocationStat.Summary
- 修饰符:public static
参数:
- stats: List
说明:
TODO
代码
public record ThreadAllocationStat(Instant timestamp, String threadName, long totalBytes) {
private static final String UNKNOWN_THREAD = "unknown";
public static ThreadAllocationStat from(RecordedEvent event) {
RecordedThread recoredThread = event.getThread("thread");
String threadName = recoredThread == null ? "unknown" : MoreObjects.firstNonNull(recoredThread.getJavaName(), "unknown");
return new ThreadAllocationStat(event.getStartTime(), threadName, event.getLong("allocated"));
}
public static ThreadAllocationStat.Summary summary(List<ThreadAllocationStat> stats) {
Map<String, Double> allocationsPerSecondByThread = new TreeMap<>();
Map<String, List<ThreadAllocationStat>> byThread = stats.stream().collect(Collectors.groupingBy(it -> it.threadName));
byThread.forEach((thread, threadStats) -> {
if (threadStats.size() >= 2) {
ThreadAllocationStat first = threadStats.get(0);
ThreadAllocationStat last = threadStats.get(threadStats.size() - 1);
long duration = Duration.between(first.timestamp, last.timestamp).getSeconds();
long diff = last.totalBytes - first.totalBytes;
allocationsPerSecondByThread.put(thread, (double)diff / duration);
}
});
return new ThreadAllocationStat.Summary(allocationsPerSecondByThread);
}
public record Summary(Map<String, Double> allocationsPerSecondByThread) {
}
}引用的其他类
- 无