Skip to content

Commit f3e0588

Browse files
committed
8361338: JFR: Min and max time in MethodTime event is confusing
Reviewed-by: mgronlun
1 parent f2d2eef commit f3e0588

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

src/jdk.jfr/share/classes/jdk/jfr/events/MethodTimingEvent.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
import jdk.jfr.Name;
3030
import jdk.jfr.Timespan;
3131
import jdk.jfr.internal.RemoveFields;
32+
import jdk.jfr.Description;
3233

3334
@Name("jdk.MethodTiming")
3435
@Label("Method Timing")
3536
@Category({ "Java Virtual Machine", "Method Tracing" })
3637
@RemoveFields({ "duration", "eventThread", "stackTrace" })
38+
@Description("Measures the approximate time it takes for a method to execute, including all delays, not just CPU processing time")
3739
public final class MethodTimingEvent extends AbstractJDKEvent {
3840

3941
@Label("Method")
@@ -43,14 +45,17 @@ public final class MethodTimingEvent extends AbstractJDKEvent {
4345
public long invocations;
4446

4547
@Label("Minimum Time")
48+
@Description("The value may be missing (Long.MIN_VALUE) if the clock-resolution is too low to establish a minimum time")
4649
@Timespan(Timespan.TICKS)
4750
public long minimum;
4851

4952
@Label("Average Time")
53+
@Description("The value may be missing (Long.MIN_VALUE) if the clock-resolution is too low to establish an average time")
5054
@Timespan(Timespan.TICKS)
5155
public long average;
5256

5357
@Label("Maximum Time")
58+
@Description("The value may be missing (Long.MIN_VALUE) if the clock-resolution is too low to establish a maximum time")
5459
@Timespan(Timespan.TICKS)
5560
public long maximum;
5661

src/jdk.jfr/share/classes/jdk/jfr/internal/query/view.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,9 @@ table = "COLUMN 'Alloc. Time', 'Application Method', 'Object Age', 'Heap Usage'
471471

472472
[application.method-timing]
473473
label = "Method Timing"
474-
table = "COLUMN 'Timed Method', 'Invocations', 'Min. Time', 'Max. Time', 'Average Time'
474+
table = "COLUMN 'Timed Method', 'Invocations', 'Minimum Time', 'Average Time', 'Maximum Time'
475475
FORMAT none, none, ms-precision:6, ms-precision:6, ms-precision:6
476-
SELECT LAST_BATCH(method) AS M, LAST_BATCH(invocations), LAST_BATCH(minimum), LAST_BATCH(maximum), LAST_BATCH(average)
476+
SELECT LAST_BATCH(method) AS M, LAST_BATCH(invocations), LAST_BATCH(minimum), LAST_BATCH(average), LAST_BATCH(maximum)
477477
FROM jdk.MethodTiming GROUP BY method ORDER BY average"
478478

479479
[application.method-calls]

src/jdk.jfr/share/classes/jdk/jfr/internal/tracing/TimedClass.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* Holds timed method for a class. Used when publishing method ids.
3434
*/
3535
public final class TimedClass {
36+
private static final long MISSING = Long.MIN_VALUE;
3637
private final ConcurrentHashMap<Long, TimedMethod> methods = new ConcurrentHashMap<>();
3738

3839
public TimedMethod add(Method method) {
@@ -60,13 +61,23 @@ public void emit(long timestamp) {
6061
long methodId = tm.method().methodId();
6162
long invocations = tm.invocations().get();
6263
long time = tm.time().get();
63-
long average = invocations == 0 ? Long.MIN_VALUE : time / invocations;
6464
long min = tm.minimum().get();
65-
if (min == Long.MAX_VALUE) {
66-
min = Long.MIN_VALUE; // Signals that the value is missing
67-
}
6865
long max = tm.maximum().get();
69-
MethodTimingEvent.commit(timestamp, methodId, invocations, min, average, max);
66+
if (time == 0 || invocations == 0) {
67+
// If time is zero, it's a low resolution clock and more invocations are needed.
68+
MethodTimingEvent.commit(timestamp, methodId, invocations, MISSING, MISSING, MISSING);
69+
} else {
70+
long average = (time + invocations / 2) / invocations;
71+
if (min == Long.MAX_VALUE) {
72+
min = average;
73+
}
74+
if (max == Long.MIN_VALUE) {
75+
max = average;
76+
}
77+
min = Math.min(min, average);
78+
max = Math.max(max, average);
79+
MethodTimingEvent.commit(timestamp, methodId, invocations, min, average, max);
80+
}
7081
tm.method().log("Emitted event");
7182
}
7283
}

src/jdk.jfr/share/classes/jdk/jfr/internal/tracing/TimedMethod.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ record TimedMethod(AtomicLong invocations, AtomicLong time, AtomicLong minimum,
3939
}
4040

4141
public void updateMinMax(long duration) {
42+
if (duration == 0) {
43+
return; // Ignore data due to low-resolution clock
44+
}
4245
if (duration > maximum.getPlain()) {
4346
while (true) {
4447
long max = maximum.get();

0 commit comments

Comments
 (0)