Skip to content

Commit

Permalink
Display duration in most succinct time unit
Browse files Browse the repository at this point in the history
This improves formatting of DurationTiming
in EXPLAIN ANALYZE
  • Loading branch information
sopel39 committed Jan 12, 2022
1 parent 102d35b commit c5274b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public DurationTiming mergeWith(DurationTiming other)
{
long durationNanos = duration.roundTo(NANOSECONDS);
long otherDurationNanos = other.getAirliftDuration().roundTo(NANOSECONDS);
return new DurationTiming(new Duration(durationNanos + otherDurationNanos, NANOSECONDS).convertToMostSuccinctTimeUnit());
return new DurationTiming(new Duration(durationNanos + otherDurationNanos, NANOSECONDS));
}

@Override
Expand All @@ -80,7 +80,7 @@ public int hashCode()
public String toString()
{
return toStringHelper("")
.add("duration", duration)
.add("duration", duration.convertToMostSuccinctTimeUnit())
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,19 @@ public void testMergeHistogram()
@Test
public void testDurationTiming()
{
DurationTiming d1 = new DurationTiming(new Duration(123, NANOSECONDS));
DurationTiming d1 = new DurationTiming(new Duration(1234, NANOSECONDS));
DurationTiming d2 = new DurationTiming(new Duration(1, NANOSECONDS));

assertThat(d1.toString()).matches("\\{duration=1.23us\\}");

Metrics m1 = new Metrics(ImmutableMap.of("a", d1));
Metrics m2 = new Metrics(ImmutableMap.of("a", d2));

DurationTiming merged = (DurationTiming) merge(m1, m2).getMetrics().get("a");

assertThat(merged.getAirliftDuration().roundTo(NANOSECONDS)).isEqualTo(124);
assertThat(merged.getDuration().toNanos()).isEqualTo(124);
assertThat(merged.getAirliftDuration().roundTo(NANOSECONDS)).isEqualTo(1235);
assertThat(merged.getDuration().toNanos()).isEqualTo(1235);
assertThat(merged.toString()).matches("\\{duration=1.24us\\}");
}

@Test
Expand Down

0 comments on commit c5274b9

Please sign in to comment.