diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java index 0fac4116..579e991b 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java @@ -7,12 +7,14 @@ import com.microsoft.gctoolkit.event.GarbageCollectionTypes; import com.microsoft.gctoolkit.event.MemoryPoolSummary; import com.microsoft.gctoolkit.event.ReferenceGCSummary; +import com.microsoft.gctoolkit.event.RegionSummary; import com.microsoft.gctoolkit.event.SurvivorMemoryPoolSummary; import com.microsoft.gctoolkit.time.DateTimeStamp; public abstract class G1GCPauseEvent extends G1GCEvent { - private final MemoryPoolSummary NULL_POOL = new MemoryPoolSummary(-1L, -1L, -1L, -1L); + private static final MemoryPoolSummary NULL_POOL = new MemoryPoolSummary(-1L, -1L, -1L, -1L); + private static final RegionSummary NULL_REGION = new RegionSummary(-1, -1, -1); private MemoryPoolSummary eden; private SurvivorMemoryPoolSummary survivor; @@ -20,6 +22,12 @@ public abstract class G1GCPauseEvent extends G1GCEvent { private MemoryPoolSummary permOrMetaspace; private ReferenceGCSummary referenceGCSummary = null; + private RegionSummary edenRegion; + private RegionSummary survivorRegion; + private RegionSummary oldRegion; + private RegionSummary humongousRegion; + private RegionSummary archiveRegion; + private CPUSummary cpuSummary; public G1GCPauseEvent(DateTimeStamp timeStamp, GarbageCollectionTypes type, GCCause cause, double duration) { @@ -44,6 +52,34 @@ public void addCPUSummary(CPUSummary summary) { this.cpuSummary = summary; } + public void addRegionSummary(RegionSummary eden, RegionSummary survivor, RegionSummary old, RegionSummary humongous, RegionSummary archive) { + this.edenRegion = eden; + this.survivorRegion = survivor; + this.oldRegion = old; + this.humongousRegion = humongous; + this.archiveRegion = archive; + } + + public RegionSummary getEdenRegionSummary() { + return this.edenRegion == null ? NULL_REGION : this.edenRegion; + } + + public RegionSummary getSurvivorRegionSummary() { + return this.survivorRegion == null ? NULL_REGION : this.survivorRegion; + } + + public RegionSummary getOldRegionSummary() { + return this.oldRegion == null ? NULL_REGION : this.oldRegion; + } + + public RegionSummary getHumongousRegionSummary() { + return this.humongousRegion == null ? NULL_REGION : this.humongousRegion; + } + + public RegionSummary getArchiveRegionSummary() { + return this.archiveRegion == null ? NULL_REGION : this.archiveRegion; + } + public MemoryPoolSummary getEden() { return this.eden; } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java index 2c72303c..a6670a15 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java @@ -7,6 +7,7 @@ import com.microsoft.gctoolkit.event.MalformedEvent; import com.microsoft.gctoolkit.event.MemoryPoolSummary; import com.microsoft.gctoolkit.event.ReferenceGCSummary; +import com.microsoft.gctoolkit.event.RegionSummary; import com.microsoft.gctoolkit.event.SurvivorMemoryPoolSummary; import com.microsoft.gctoolkit.event.UnifiedCountSummary; import com.microsoft.gctoolkit.event.UnifiedStatisticalSummary; @@ -31,6 +32,7 @@ import com.microsoft.gctoolkit.parser.jvm.Decorators; import com.microsoft.gctoolkit.time.DateTimeStamp; +import java.util.Arrays; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; @@ -130,7 +132,7 @@ GarbageCollectionTypes getConcurrentPhase() { private static final int YOUNG_OCCUPANCY_BEFORE_COLLECTION = 12; private static final int YOUNG_OCCUPANCY_AFTER_COLLECTION = 13; private static final int YOUNG_SIZE_BEFORE_COLLECTION = 14; - private static final int YOUNG__SIZE_AFTER_COLLECTION = 15; + private static final int YOUNG_SIZE_AFTER_COLLECTION = 15; private static final int OLD_OCCUPANCY_BEFORE_COLLECTION = 16; private static final int OLD_OCCUPANCY_AFTER_COLLECTION = 17; private static final int OLD_SIZE_BEFORE_COLLECTION = 18; @@ -177,6 +179,7 @@ private boolean setMemoryPoolMeasurement(int index, long value) { return false; } + boolean setHeapOccupancyBeforeCollection(long value) { return setMemoryPoolMeasurement(HEAP_OCCUPANCY_BEFORE_COLLECTION, value); } @@ -238,7 +241,7 @@ boolean setYoungSizeBeforeCollection(long value) { } boolean setYoungSizeAfterCollection(long value) { - return setMemoryPoolMeasurement(YOUNG__SIZE_AFTER_COLLECTION, value); + return setMemoryPoolMeasurement(YOUNG_SIZE_AFTER_COLLECTION, value); } boolean setOldOccupancyBeforeCollection(long value) { @@ -564,6 +567,77 @@ private void fillInMetaspaceStats(G1GCPauseEvent collection) { collection.addPermOrMetaSpaceRecord(getMemoryPoolSummary(METASPACE_OCCUPANCY_BEFORE_COLLECTION)); } + + enum REGIONS { + EDEN, + SURVIVOR, + OLD, + HUMONGOUS, + ARCHIVE; + } + + private final RegionSummary[] regionSummaries = new RegionSummary[REGIONS.values().length]; + + void setEdenRegionSummary(RegionSummary summary) { + regionSummaries[REGIONS.EDEN.ordinal()] = summary; + if (heapRegionSize > 0) { + setEdenOccupancyBeforeCollection(summary.getBefore() * heapRegionSize * 1024L); + setEdenOccupancyAfterCollection(summary.getAfter() * heapRegionSize * 1024L); + setEdenSizeBeforeCollection(summary.getBefore() * heapRegionSize * 1024L); + setEdenSizeAfterCollection(summary.getAssigned() * heapRegionSize * 1024L); + } + } + + void setSurvivorRegionSummary(RegionSummary summary) { + regionSummaries[REGIONS.SURVIVOR.ordinal()] = summary; + if (heapRegionSize > 0) { + setSurvivorOccupancyBeforeCollection(summary.getBefore() * heapRegionSize * 1024L); + setSurvivorOccupancyAfterCollection(summary.getAfter() * heapRegionSize * 1024L); + setSurvivorSizeBeforeCollection(summary.getBefore() * heapRegionSize * 1024L); + setSurvivorSizeAfterCollection(summary.getAssigned() * heapRegionSize * 1024L); + } + } + + void setOldRegionSummary(RegionSummary summary) { + regionSummaries[REGIONS.OLD.ordinal()] = summary; + if (heapRegionSize > 0) { + setOldOccupancyBeforeCollection(summary.getBefore() * heapRegionSize * 1024L); + setOldOccupancyAfterCollection(summary.getAfter() * heapRegionSize * 1024L); + setOldSizeBeforeCollection(summary.getBefore() * heapRegionSize * 1024L); + setOldSizeAfterCollection(summary.getAfter() * heapRegionSize * 1024L); + } + } + + void setHumongousRegionSummary(RegionSummary summary) { + regionSummaries[REGIONS.HUMONGOUS.ordinal()] = summary; + if (heapRegionSize > 0) { + setHumongousOccupancyBeforeCollection(summary.getBefore() * heapRegionSize * 1024L); + setHumongousOccupancyAfterCollection(summary.getAfter() * heapRegionSize * 1024L); + setHumongousSizeBeforeCollection(summary.getBefore() * heapRegionSize * 1024L); + setHumongousSizeAfterCollection(summary.getAfter() * heapRegionSize * 1024L); + } + } + + void setArchiveRegionSummary(RegionSummary summary) { + regionSummaries[REGIONS.ARCHIVE.ordinal()] = summary; + if (heapRegionSize > 0) { + setArchiveOccupancyBeforeCollection(summary.getBefore() * heapRegionSize * 1024); + setArchiveOccupancyAfterCollection(summary.getAfter() * heapRegionSize * 1024); + setArchiveSizeBeforeCollection(summary.getBefore() * heapRegionSize * 1024); + setArchiveSizeAfterCollection(summary.getAfter() * heapRegionSize * 1024); + } + } + + private void fillInRegionSummary(G1GCPauseEvent collection) { + collection.addRegionSummary( + regionSummaries[REGIONS.EDEN.ordinal()], + regionSummaries[REGIONS.SURVIVOR.ordinal()], + regionSummaries[REGIONS.OLD.ordinal()], + regionSummaries[REGIONS.HUMONGOUS.ordinal()], + regionSummaries[REGIONS.ARCHIVE.ordinal()] + ); + } + private void fullInInternalPhases(G1FullGC collection) { int index = 0; String key; @@ -696,6 +770,7 @@ G1GCPauseEvent buildEvent() throws MalformedEvent { private G1Young buildYoung(G1Young collection) { fillInMemoryPoolStats(collection); + fillInRegionSummary(collection); fillInMetaspaceStats(collection); fillInPhases(collection); if (toSpaceExhausted) collection.toSpaceExhausted(); diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java index b5b4e4af..417918b7 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java @@ -450,34 +450,19 @@ public void regionSummary(GCLogTrace trace, String line) { RegionSummary summary = trace.regionSummary(); switch (trace.getGroup(1)) { case "Eden": - forwardReference.setEdenOccupancyBeforeCollection(summary.getBefore() * regionSize * 1024); - forwardReference.setEdenOccupancyAfterCollection(summary.getAfter() * regionSize * 1024); - forwardReference.setEdenSizeBeforeCollection(summary.getBefore() * regionSize * 1024); - forwardReference.setEdenSizeAfterCollection(summary.getAssigned() * regionSize * 1024); + forwardReference.setEdenRegionSummary(summary); break; case "Survivor": - forwardReference.setSurvivorOccupancyBeforeCollection(summary.getBefore() * regionSize * 1024); - forwardReference.setSurvivorOccupancyAfterCollection(summary.getAfter() * regionSize * 1024); - forwardReference.setSurvivorSizeBeforeCollection(summary.getBefore() * regionSize * 1024); - forwardReference.setSurvivorSizeAfterCollection(summary.getAssigned() * regionSize * 1024); + forwardReference.setSurvivorRegionSummary(summary); break; case "Old": - forwardReference.setOldOccupancyBeforeCollection(summary.getBefore() * regionSize * 1024); - forwardReference.setOldOccupancyAfterCollection(summary.getAfter() * regionSize * 1024); - forwardReference.setOldSizeBeforeCollection(summary.getBefore() * regionSize * 1024); - forwardReference.setOldSizeAfterCollection(summary.getAfter() * regionSize * 1024); + forwardReference.setOldRegionSummary(summary); break; case "Humongous": - forwardReference.setHumongousOccupancyBeforeCollection(summary.getBefore() * regionSize * 1024); - forwardReference.setHumongousOccupancyAfterCollection(summary.getAfter() * regionSize * 1024); - forwardReference.setHumongousSizeBeforeCollection(summary.getBefore() * regionSize * 1024); - forwardReference.setHumongousSizeAfterCollection(summary.getAfter() * regionSize * 1024); + forwardReference.setHumongousRegionSummary(summary); break; case "Archive": - forwardReference.setArchiveOccupancyBeforeCollection(summary.getBefore() * regionSize * 1024); - forwardReference.setArchiveOccupancyAfterCollection(summary.getAfter() * regionSize * 1024); - forwardReference.setArchiveSizeBeforeCollection(summary.getBefore() * regionSize * 1024); - forwardReference.setArchiveSizeAfterCollection(summary.getAfter() * regionSize * 1024); + forwardReference.setArchiveRegionSummary(summary); break; default: notYetImplemented(trace, line); diff --git a/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCUnifiedParserRulesTest.java b/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCUnifiedParserRulesTest.java index 5ff38a05..0e081dde 100644 --- a/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCUnifiedParserRulesTest.java +++ b/parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCUnifiedParserRulesTest.java @@ -4,6 +4,7 @@ import com.microsoft.gctoolkit.parser.jvm.Decorators; import com.microsoft.gctoolkit.parser.unified.UnifiedG1GCPatterns; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.util.logging.Logger; @@ -47,9 +48,9 @@ public void testUnifiedLoggingDecorators() { } } - // for debugging @Test + @Test @Disabled("used for debug testing") public void testSingeRuleCapture() { - int index = 10; + int index = 6; assertEquals(lines[index].length, captureTest(rules[index], lines[index]), "Miss for " + rules[index].getName()); }