44
55public class PerformanceMetric {
66 private final String name ;
7- private final long maxThreshold ;
7+ private final long maxAllowed ;
88 public final boolean timerEnabled ;
99
1010 public double minValue = Long .MAX_VALUE ;
@@ -17,9 +17,9 @@ public class PerformanceMetric {
1717
1818 private long timeStarted = 0 ;
1919
20- PerformanceMetric (String name , long maxThreshold , boolean timerEnabled ) {
20+ PerformanceMetric (String name , long maxAllowed , boolean timerEnabled ) {
2121 this .name = name ;
22- this .maxThreshold = maxThreshold ;
22+ this .maxAllowed = maxAllowed ;
2323 this .timerEnabled = timerEnabled ;
2424 }
2525
@@ -40,20 +40,19 @@ void startTiming() {
4040 void stopTiming () {
4141 if (!timerEnabled ) return ;
4242 if (timeStarted <= 0 ) return ;
43- // Use nanosecond resolution timer,
44- // and record in units of milliseconds.
43+ // Use nanosecond resolution timer, but record in units of milliseconds.
4544 long timeEnded = System .nanoTime ();
4645 long timeDiff = timeEnded - timeStarted ;
4746 timeStarted = 0 ;
48- record (timeDiff / 1000d );
47+ record (timeDiff / 1000000d );
4948 }
5049
5150 void record (double value ) {
5251 minValue = Math .min (minValue , value );
5352 maxValue = Math .max (maxValue , value );
5453 avgValue = (avgValue * samples + value ) / (samples + 1d );
5554 ++samples ;
56- if (value > maxThreshold ) {
55+ if (value > maxAllowed ) {
5756 avgValueExceeding = (avgValueExceeding * samplesExceeding + value ) / (samplesExceeding + 1d );
5857 ++samplesExceeding ;
5958 }
@@ -64,22 +63,24 @@ public String toString() {
6463 DecimalFormat formatter = new DecimalFormat ("###,###.#" );
6564 return name
6665 + ": "
67- + samples
68- + " averaging "
69- + formatter .format (avgValue )
70- + " ["
71- + formatter .format (minValue )
72- + " - "
73- + formatter .format (maxValue )
74- + "] over "
75- + samples
76- + " samples"
77- + (samplesExceeding > 0
78- ? ". "
79- + samplesExceeding
80- + " violations averaging "
81- + formatter .format (avgValueExceeding )
82- : "" )
66+ + (samples > 0
67+ ? formatter .format (samples )
68+ + " samples averaging "
69+ + formatter .format (avgValue )
70+ + " ["
71+ + formatter .format (minValue )
72+ + " - "
73+ + formatter .format (maxValue )
74+ + "] over "
75+ + samples
76+ + " samples"
77+ + (samplesExceeding > 0
78+ ? ". "
79+ + samplesExceeding
80+ + " violations averaging "
81+ + formatter .format (avgValueExceeding )
82+ : "" )
83+ : "No samples" )
8384 + (interrupted > 0
8485 ? ". Interrupted " + interrupted + " times"
8586 : "" );
0 commit comments