Skip to content

Commit e226885

Browse files
authored
Fix for Gctoolkit #372 - YoungDetails event not published for GC log collected with -Xlog:gc (no *) (#430)
* Fixing #372, Test cases to come * Update existing unified test cases for new Diarizer flag, add non-gc* pattern to rules test.
1 parent 0df38d5 commit e226885

File tree

7 files changed

+38
-10
lines changed

7 files changed

+38
-10
lines changed

api/src/main/java/com/microsoft/gctoolkit/jvm/Diary.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ public boolean isJVMEventsKnown() {
378378
return isApplicationStoppedTimeKnown() && isApplicationRunningTime();
379379
}
380380

381+
public boolean isPrintCPUTimes() {
382+
return isStateKnown(SupportedFlags.PRINT_CPU_TIMES);
383+
}
384+
381385
public void setTimeOfFirstEvent(DateTimeStamp startTime) {
382386
if ( this.timeOfFirstEvent == null)
383387
this.timeOfFirstEvent = startTime;

api/src/main/java/com/microsoft/gctoolkit/jvm/SupportedFlags.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public enum SupportedFlags {
3535
MAX_TENURING_THRESHOLD_VIOLATION, // 24
3636
TLAB_DATA, // 25
3737
PRINT_PROMOTION_FAILURE, // 26
38-
PRINT_FLS_STATISTICS // 27
38+
PRINT_FLS_STATISTICS, // 27
39+
40+
PRINT_CPU_TIMES // 28
3941

4042
}

parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ public void endOfFile(GCLogTrace trace, String line) {
252252
publish(new JVMTermination((jvmTerminationEventTime.hasTimeStamp()) ? jvmTerminationEventTime : getClock(),diary.getTimeOfFirstEvent()));
253253
}
254254

255-
256255
/**
257256
* following records describe heap before the collection
258257
*
@@ -508,12 +507,29 @@ public void unifiedMetaData(GCLogTrace trace, String line) {
508507
forwardReference.setMetaspaceSizeAfterCollection(trace.toKBytes(5));
509508
}
510509
}
511-
510+
512511
public void youngDetails(GCLogTrace trace, String line) {
513512
forwardReference.setHeapOccupancyBeforeCollection(trace.toKBytes(5));
514513
forwardReference.setHeapOccupancyAfterCollection(trace.toKBytes(7));
515514
forwardReference.setHeapSizeAfterCollection(trace.toKBytes(9));
516515
forwardReference.setDuration(trace.getDurationInSeconds());
516+
517+
// Handling -Xlog:gc logs (#372)
518+
// If the GC log was generated using -Xlog:gc instead of -Xlog:gc*, there won't be a CPU breakout
519+
// line that will publish the event. (cpuBreakout() above)
520+
521+
// If we haven't spotted a CPU decorator in the diarizer, we should be able to publish this line
522+
// after filling in the missing info.
523+
if (forwardReference.getGcType() == null && !diary.isPrintCPUTimes()) {
524+
forwardReference.setGcType(GarbageCollectionTypes.Young);
525+
forwardReference.setGCCause(trace.gcCause(-2));
526+
forwardReference.setStartTime(getClock());
527+
try {
528+
publishPauseEvent(forwardReference.buildEvent());
529+
} catch (MalformedEvent malformedEvent) {
530+
LOGGER.warning(malformedEvent.getMessage());
531+
}
532+
}
517533
}
518534

519535
/**

parser/src/main/java/com/microsoft/gctoolkit/parser/jvm/UnifiedDiarizer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ else if (decorators.tagsContain("gc,phases") && logLevel.isGreaterThanOrEqualTo(
117117
diary.setTrue(GC_DETAILS);
118118
else if ( decorators.tagsContain("gc,ergo"))
119119
diary.setTrue(ADAPTIVE_SIZING);
120+
else if (decorators.tagsContain("gc,cpu"))
121+
diary.setTrue(PRINT_CPU_TIMES);
122+
120123
if (decorators.tagsContain("safepoint"))
121124
diary.setTrue(APPLICATION_STOPPED_TIME, APPLICATION_CONCURRENT_TIME);
122125

parser/src/test/java/com/microsoft/gctoolkit/parser/G1GCUnifiedParserRulesTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ private void evaluate(GCParseRule rule, String string, boolean dump) {
215215
"[6.641s][info][gc ] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 23M->6M(64M) 6.302ms",
216216
"[7.965s][info][gc ] GC(415) Pause Young (Concurrent Start) (G1 Evacuation Pause) 49M->30M(64M) 1.965ms",
217217
"[7.981s][info][gc ] GC(419) Pause Young (Prepare Mixed) (G1 Evacuation Pause) 43M->16M(64M) 1.734ms",
218-
"[7.984s][info][gc ] GC(420) Pause Young (Mixed) (G1 Evacuation Pause) 26M->11M(64M) 1.453ms"
218+
"[7.984s][info][gc ] GC(420) Pause Young (Mixed) (G1 Evacuation Pause) 26M->11M(64M) 1.453ms",
219+
"[19.869s][info][gc] GC(8) Pause Young (Normal) (G1 Evacuation Pause) 170M->42M(1024M) 8.502ms"
219220
},
220221
{ // 9
221222
"[2018-03-09T11:14:05.002-0100][12.277s][info ][gc,cpu ] GC(0) User=0.04s Sys=0.01s Real=0.01s"

parser/src/test/java/com/microsoft/gctoolkit/parser/diary/G1DiarizerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ public void testUnifiedG1GC() {
206206
};
207207

208208
private static final boolean[][] unifiedDiary = {
209-
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18, 19, 20, 21, 22, 23, 24, 25, 26, 27
210-
{ true, true, false, false, false, false, false, false, false, true, false, false, true, true, true, false, false, false, false, false, true, false, false, true, false, false, false, false},
211-
{ true, true, false, false, false, false, false, false, false, true, false, false, true, true, true, false, false, false, false, false, true, false, false, true, false, false, false, false}
209+
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
210+
{ true, true, false, false, false, false, false, false, false, true, false, false, true, true, true, false, false, false, false, false, true, false, false, true, false, false, false, false, true},
211+
{ true, true, false, false, false, false, false, false, false, true, false, false, true, true, true, false, false, false, false, false, true, false, false, true, false, false, false, false, true}
212212
};
213213

214214
private static final int[][] unifiedUnknown = {
@@ -217,8 +217,8 @@ public void testUnifiedG1GC() {
217217
};
218218

219219
private static final int[][] unifiedKnown = {
220-
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27},
221-
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27}
220+
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28},
221+
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28}
222222
};
223223

224224
}

parser/src/test/java/com/microsoft/gctoolkit/parser/diary/LogDiaryTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.io.File;
1414
import java.io.IOException;
1515
import java.util.Objects;
16-
import java.util.stream.Stream;
1716

1817
import static org.junit.jupiter.api.Assertions.fail;
1918

@@ -288,6 +287,9 @@ void lookForKnowns(Diarizer jvmConfiguration, String name, int[] knowns) {
288287
case 27:
289288
assertTrue(name + ":PRINT_FLS_STATISTICS should be known", diary.isPrintFLSStatisticsKnown());
290289
break;
290+
case 28:
291+
assertTrue(name + ":PRINT_CPU_TIMES should be known", diary.isPrintCPUTimes());
292+
break;
291293
default:
292294
fail("unknown unknown");
293295
}

0 commit comments

Comments
 (0)