@@ -71,14 +71,15 @@ public static class Options {
71
71
private final CompilationAlarm previous ;
72
72
73
73
@ SuppressWarnings ("this-escape" )
74
- private CompilationAlarm (double period ) {
74
+ private CompilationAlarm (double period , boolean skipZeros ) {
75
75
this .previous = currentAlarm .get ();
76
76
reset (period );
77
77
JMXService .GCTimeStatistics timing = null ;
78
78
if (period != 0 ) {
79
79
timing = GraalServices .getGCTimeStatistics ();
80
80
}
81
81
this .gcTiming = timing ;
82
+ this .skipZeros = skipZeros ;
82
83
}
83
84
84
85
/**
@@ -113,7 +114,7 @@ public static double scaleExpirationPeriod(double period, OptionValues options)
113
114
*/
114
115
private static final ThreadLocal <CompilationAlarm > currentAlarm = new ThreadLocal <>();
115
116
116
- private static final CompilationAlarm NEVER_EXPIRES = new CompilationAlarm (0 );
117
+ private static final CompilationAlarm NEVER_EXPIRES = new CompilationAlarm (0 , false );
117
118
118
119
/**
119
120
* Gets the current compilation alarm. If there is no current alarm, a non-null value is
@@ -183,7 +184,8 @@ public boolean isEnabled() {
183
184
public void checkExpiration () {
184
185
if (hasExpired ()) {
185
186
186
- setCurrentNodeDuration (currentNode .name );
187
+ // also set all parent node times
188
+ setCurrentNodeDuration (currentNode .name , true );
187
189
188
190
/*
189
191
* We clone the phase tree here for the sake of the error message. We want to fix up the
@@ -194,7 +196,7 @@ public void checkExpiration() {
194
196
StringBuilder sb = new StringBuilder ();
195
197
// also update the root time to be consistent for the error message
196
198
cloneTree .durationNS = elapsed ();
197
- printTree ("" , sb , cloneTree , true );
199
+ printTree ("" , sb , cloneTree , true , skipZeros );
198
200
199
201
// Include information about time spent in the GC if it's available.
200
202
String gcMessage = "" ;
@@ -227,6 +229,11 @@ public void close() {
227
229
*/
228
230
private final JMXService .GCTimeStatistics gcTiming ;
229
231
232
+ /**
233
+ * On timeout skip zero entries.
234
+ */
235
+ private final boolean skipZeros ;
236
+
230
237
/**
231
238
* Signal the execution of the phase identified by {@code name} starts.
232
239
*/
@@ -296,7 +303,7 @@ public void exitPhase(CharSequence name, StructuredGraph graph) {
296
303
currentNode = currentNode .parent ;
297
304
}
298
305
assert currentNode .name .equals (name ) : Assertions .errorMessage ("Must see the same phase that was opened in the close operation" , name , elapsedPhaseTreeAsString ());
299
- setCurrentNodeDuration (name );
306
+ setCurrentNodeDuration (name , false );
300
307
currentNode .closed = true ;
301
308
if (graph != null ) {
302
309
currentNode .graphSizeAfter = graph .getNodeCount ();
@@ -316,9 +323,17 @@ private boolean graphMarksIntermediateRootEnd(StructuredGraph graph) {
316
323
return currentNode instanceof PhaseTreeIntermediateRoot && currentNode .graph != null && graph != null && !currentNode .graph .equals (graph );
317
324
}
318
325
319
- private void setCurrentNodeDuration (CharSequence name ) {
326
+ private void setCurrentNodeDuration (CharSequence name , boolean setParentTime ) {
320
327
assert currentNode .startTimeNS >= 0 : Assertions .errorMessage ("Must have a positive start time" , name , elapsedPhaseTreeAsString ());
321
- currentNode .durationNS = System .nanoTime () - currentNode .startTimeNS ;
328
+ long currentTimeNano = System .nanoTime ();
329
+ currentNode .durationNS = currentTimeNano - currentNode .startTimeNS ;
330
+ if (setParentTime ) {
331
+ PhaseTreeNode node = currentNode .parent ;
332
+ while (node != null ) {
333
+ node .durationNS = currentTimeNano - node .startTimeNS ;
334
+ node = node .parent ;
335
+ }
336
+ }
322
337
}
323
338
324
339
/**
@@ -413,6 +428,10 @@ public String toString() {
413
428
"->" + graphSizeAfter + "]" ;
414
429
}
415
430
431
+ private boolean durationZeroInMS () {
432
+ return TimeUnit .NANOSECONDS .toMillis (durationNS ) == 0 ;
433
+ }
434
+
416
435
}
417
436
418
437
private static class PhaseTreeIntermediateRoot extends PhaseTreeNode {
@@ -449,27 +468,34 @@ private PhaseTreeNode cloneTree(PhaseTreeNode clonee, PhaseTreeNode parent) {
449
468
/**
450
469
* Recursively print the phase tree represented by {@code node}.
451
470
*/
452
- private void printTree (String indent , StringBuilder sb , PhaseTreeNode node , boolean printRoot ) {
471
+ private void printTree (String indent , StringBuilder sb , PhaseTreeNode node , boolean printRoot , boolean skipPrintingZeroSubTree ) {
453
472
if (root == null ) {
454
473
return ;
455
474
}
456
- sb .append (indent );
475
+ boolean skip = skipPrintingZeroSubTree && node .durationZeroInMS ();
476
+ if (!skip ) {
477
+ sb .append (indent );
478
+ }
457
479
if (!printRoot && node == root ) {
458
480
sb .append (node .name );
459
481
} else {
460
- sb .append (node );
482
+ if (!skip ) {
483
+ sb .append (node );
484
+ }
485
+ }
486
+ if (!skip ) {
487
+ sb .append (System .lineSeparator ());
461
488
}
462
- sb .append (System .lineSeparator ());
463
- if (node .children != null ) {
489
+ if (node .children != null && !skip ) {
464
490
for (int i = 0 ; i < node .childIndex ; i ++) {
465
- printTree (indent + "\t " , sb , node .children [i ], printRoot );
491
+ printTree (indent + "\t " , sb , node .children [i ], printRoot , skipPrintingZeroSubTree );
466
492
}
467
493
}
468
494
}
469
495
470
496
public StringBuilder elapsedPhaseTreeAsString () {
471
497
StringBuilder sb = new StringBuilder ();
472
- printTree ("" , sb , root , false );
498
+ printTree ("" , sb , root , false , false );
473
499
return sb ;
474
500
}
475
501
@@ -493,7 +519,7 @@ public static CompilationAlarm trackCompilationPeriod(OptionValues options) {
493
519
}
494
520
CompilationAlarm current = currentAlarm .get ();
495
521
if (current == null ) {
496
- current = new CompilationAlarm (period );
522
+ current = new CompilationAlarm (period , true /* skip 0 entries */ );
497
523
currentAlarm .set (current );
498
524
return current ;
499
525
}
@@ -506,7 +532,7 @@ public static CompilationAlarm trackCompilationPeriod(OptionValues options) {
506
532
* statement to restore the previous alarm state.
507
533
*/
508
534
public static CompilationAlarm disable () {
509
- CompilationAlarm current = new CompilationAlarm (0 );
535
+ CompilationAlarm current = new CompilationAlarm (0 , false );
510
536
currentAlarm .set (current );
511
537
return current ;
512
538
}
0 commit comments