Skip to content

Commit

Permalink
Reporters: report Timer sums in the Timer duration units
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpj committed May 2, 2018
1 parent 5ce9ba3 commit 5660466
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private void printHistogram(Histogram histogram) {
private void printTimer(Timer timer) {
final Snapshot snapshot = timer.getSnapshot();
printIfEnabled(MetricAttribute.COUNT, String.format(locale, " count = %d", timer.getCount()));
printIfEnabled(MetricAttribute.SUM, String.format(locale, " sum = %d", timer.getSum()));
printIfEnabled(MetricAttribute.SUM, String.format(locale, " sum = %2.2f", convertDuration(timer.getSum())));
printIfEnabled(MetricAttribute.MEAN_RATE, String.format(locale, " mean rate = %2.2f calls/%s", convertRate(timer.getMeanRate()), getRateUnit()));
printIfEnabled(MetricAttribute.M1_RATE, String.format(locale, " 1-minute rate = %2.2f calls/%s", convertRate(timer.getOneMinuteRate()), getRateUnit()));
printIfEnabled(MetricAttribute.M5_RATE, String.format(locale, " 5-minute rate = %2.2f calls/%s", convertRate(timer.getFiveMinuteRate()), getRateUnit()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private CsvReporter(MetricRegistry registry,

this.histogramFormat = String.join(separator, "%d", "%d", "%d", "%f", "%d", "%f", "%f", "%f", "%f", "%f", "%f", "%f");
this.meterFormat = String.join(separator, "%d", "%d", "%f", "%f", "%f", "%f", "events/%s");
this.timerFormat = String.join(separator, "%d", "%d", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "calls/%s", "%s");
this.timerFormat = String.join(separator, "%d", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "%f", "calls/%s", "%s");
}

@Override
Expand Down Expand Up @@ -253,7 +253,7 @@ private void reportTimer(long timestamp, MetricName name, Timer timer) {
"count,sum,max,mean,min,stddev,p50,p75,p95,p98,p99,p999,mean_rate,m1_rate,m5_rate,m15_rate,rate_unit,duration_unit",
timerFormat,
timer.getCount(),
timer.getSum(),
convertDuration(timer.getSum()),
convertDuration(snapshot.getMax()),
convertDuration(snapshot.getMean()),
convertDuration(snapshot.getMin()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void reportsMeterValues() throws Exception {
public void reportsTimerValues() throws Exception {
final Timer timer = mock(Timer.class);
when(timer.getCount()).thenReturn(1L);
when(timer.getSum()).thenReturn(5L);
when(timer.getSum()).thenReturn(TimeUnit.MILLISECONDS.toNanos(5));
when(timer.getMeanRate()).thenReturn(2.0);
when(timer.getOneMinuteRate()).thenReturn(3.0);
when(timer.getFiveMinuteRate()).thenReturn(4.0);
Expand Down Expand Up @@ -212,7 +212,7 @@ public void reportsTimerValues() throws Exception {
"-- Timers ----------------------------------------------------------------------",
"test.another.timer",
" count = 1",
" sum = 5",
" sum = 5.00",
" mean rate = 2.00 calls/second",
" 1-minute rate = 3.00 calls/second",
" 5-minute rate = 4.00 calls/second",
Expand Down Expand Up @@ -291,7 +291,7 @@ public void reportTimerWithDisabledAttributes() throws Exception {

final Timer timer = mock(Timer.class);
when(timer.getCount()).thenReturn(1L);
when(timer.getSum()).thenReturn(6L);
when(timer.getSum()).thenReturn(TimeUnit.MILLISECONDS.toNanos(6));
when(timer.getMeanRate()).thenReturn(2.0);
when(timer.getOneMinuteRate()).thenReturn(3.0);
when(timer.getFiveMinuteRate()).thenReturn(4.0);
Expand Down Expand Up @@ -325,7 +325,7 @@ public void reportTimerWithDisabledAttributes() throws Exception {
"-- Timers ----------------------------------------------------------------------",
"test.another.timer",
" count = 1",
" sum = 6",
" sum = 6.00",
" mean rate = 2.00 calls/second",
" 1-minute rate = 3.00 calls/second",
" 15-minute rate = 5.00 calls/second",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void reportsMeterValues() throws Exception {
public void reportsTimerValues() throws Exception {
final Timer timer = mock(Timer.class);
when(timer.getCount()).thenReturn(1L);
when(timer.getSum()).thenReturn(6L);
when(timer.getSum()).thenReturn(TimeUnit.MILLISECONDS.toNanos(6));
when(timer.getMeanRate()).thenReturn(2.0);
when(timer.getOneMinuteRate()).thenReturn(3.0);
when(timer.getFiveMinuteRate()).thenReturn(4.0);
Expand Down Expand Up @@ -162,7 +162,7 @@ public void reportsTimerValues() throws Exception {
assertThat(fileContents("test.another.timer.csv"))
.isEqualTo(csv(
"t,count,sum,max,mean,min,stddev,p50,p75,p95,p98,p99,p999,mean_rate,m1_rate,m5_rate,m15_rate,rate_unit,duration_unit",
"19910191,1,6,100.000000,200.000000,300.000000,400.000000,500.000000,600.000000,700.000000,800.000000,900.000000,1000.000000,2.000000,3.000000,4.000000,5.000000,calls/second,milliseconds"
"19910191,1,6.000000,100.000000,200.000000,300.000000,400.000000,500.000000,600.000000,700.000000,800.000000,900.000000,1000.000000,2.000000,3.000000,4.000000,5.000000,calls/second,milliseconds"
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,11 @@ public double get99thPercentile() {
public double get999thPercentile() {
return metric.getSnapshot().get999thPercentile() * durationFactor;
}

@Override
public long getSum() {
return (long)(super.getSum() * durationFactor);
}

@Override
public long[] values() {
Expand Down

0 comments on commit 5660466

Please sign in to comment.