Skip to content

Commit

Permalink
add per region type RegionSummary to G1GCPauseEvent (#286)
Browse files Browse the repository at this point in the history
* add RegionSummary for eden, survivor, old, humongous, archive to G1GCPauseEvent

* address issues from pr 286
  • Loading branch information
dsgrieve authored Apr 6, 2023
1 parent be3117f commit 35cee52
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@
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;
private MemoryPoolSummary heap;
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) {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -177,6 +179,7 @@ private boolean setMemoryPoolMeasurement(int index, long value) {
return false;
}


boolean setHeapOccupancyBeforeCollection(long value) {
return setMemoryPoolMeasurement(HEAP_OCCUPANCY_BEFORE_COLLECTION, value);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

Expand Down

0 comments on commit 35cee52

Please sign in to comment.