GcHeapStat.java

net.minecraft.util.profiling.jfr.stats.GcHeapStat

信息

  • 全限定名:net.minecraft.util.profiling.jfr.stats.GcHeapStat
  • 类型:public record
  • 包:net.minecraft.util.profiling.jfr.stats
  • 源码路径:src/main/java/net/minecraft/util/profiling/jfr/stats/GcHeapStat.java
  • 起始行号:L10
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

  • net.minecraft.util.profiling.jfr.stats.GcHeapStat.Summary

    • 类型: record
    • 修饰符: public
    • 源码定位: L39
    • 说明:

      TODO

  • net.minecraft.util.profiling.jfr.stats.GcHeapStat.Timing

    • 类型: enum
    • 修饰符: static
    • 源码定位: L45
    • 说明:

      TODO

构造器

方法

下面的方法块按源码顺序生成。

public static GcHeapStat from(RecordedEvent event) @ L11

  • 方法名:from
  • 源码定位:L11
  • 返回类型:GcHeapStat
  • 修饰符:public static

参数:

  • event: RecordedEvent

说明:

TODO

public static GcHeapStat.Summary summary(Duration recordingDuration, List<GcHeapStat> heapStats, Duration gcTotalDuration, int totalGCs) @ L19

  • 方法名:summary
  • 源码定位:L19
  • 返回类型:GcHeapStat.Summary
  • 修饰符:public static

参数:

  • recordingDuration: Duration
  • heapStats: List
  • gcTotalDuration: Duration
  • totalGCs: int

说明:

TODO

private static double calculateAllocationRatePerSecond(List<GcHeapStat> heapStats) @ L23

  • 方法名:calculateAllocationRatePerSecond
  • 源码定位:L23
  • 返回类型:double
  • 修饰符:private static

参数:

  • heapStats: List

说明:

TODO

代码

public record GcHeapStat(Instant timestamp, long heapUsed, GcHeapStat.Timing timing) {
    public static GcHeapStat from(RecordedEvent event) {
        return new GcHeapStat(
            event.getStartTime(),
            event.getLong("heapUsed"),
            event.getString("when").equalsIgnoreCase("before gc") ? GcHeapStat.Timing.BEFORE_GC : GcHeapStat.Timing.AFTER_GC
        );
    }
 
    public static GcHeapStat.Summary summary(Duration recordingDuration, List<GcHeapStat> heapStats, Duration gcTotalDuration, int totalGCs) {
        return new GcHeapStat.Summary(recordingDuration, gcTotalDuration, totalGCs, calculateAllocationRatePerSecond(heapStats));
    }
 
    private static double calculateAllocationRatePerSecond(List<GcHeapStat> heapStats) {
        long totalAllocations = 0L;
        Map<GcHeapStat.Timing, List<GcHeapStat>> byTiming = heapStats.stream().collect(Collectors.groupingBy(it -> it.timing));
        List<GcHeapStat> beforeGcs = byTiming.get(GcHeapStat.Timing.BEFORE_GC);
        List<GcHeapStat> afterGcs = byTiming.get(GcHeapStat.Timing.AFTER_GC);
 
        for (int i = 1; i < beforeGcs.size(); i++) {
            GcHeapStat beforeGC = beforeGcs.get(i);
            GcHeapStat previousGC = afterGcs.get(i - 1);
            totalAllocations += beforeGC.heapUsed - previousGC.heapUsed;
        }
 
        Duration totalDuration = Duration.between(heapStats.get(1).timestamp, heapStats.get(heapStats.size() - 1).timestamp);
        return (double)totalAllocations / totalDuration.getSeconds();
    }
 
    public record Summary(Duration duration, Duration gcTotalDuration, int totalGCs, double allocationRateBytesPerSecond) {
        public float gcOverHead() {
            return (float)this.gcTotalDuration.toMillis() / (float)this.duration.toMillis();
        }
    }
 
    static enum Timing {
        BEFORE_GC,
        AFTER_GC;
    }
}

引用的其他类