Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display duration in most succinct time unit #10576

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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