8223697: jfr tool can't format duration values greater than 1 minute
Reviewed-by: egahlin
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/PrettyWriter.java Tue Oct 22 18:53:28 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/tool/PrettyWriter.java Tue Oct 22 23:55:33 2019 +0200
@@ -57,6 +57,9 @@
* This class is also used by {@link RecordedObject#toString()}
*/
public final class PrettyWriter extends EventPrintWriter {
+ private static final Duration MILLSECOND = Duration.ofMillis(1);
+ private static final Duration SECOND = Duration.ofSeconds(1);
+ private static final Duration MINUTE = Duration.ofMinutes(1);
private static final String TYPE_OLD_OBJECT = Type.TYPES_PREFIX + "OldObject";
private final static DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
private final static Long ZERO = 0L;
@@ -550,19 +553,14 @@
println("N/A");
return true;
}
- double s = d.toNanosPart() / 1000_000_000.0 + d.toSecondsPart();
- if (s < 1.0) {
- if (s < 0.001) {
- println(String.format("%.3f", s * 1_000_000) + " us");
- } else {
- println(String.format("%.3f", s * 1_000) + " ms");
- }
+ if(d.compareTo(MILLSECOND) < 0){
+ println(String.format("%.3f us", (double)d.toNanos() / 1_000));
+ } else if(d.compareTo(SECOND) < 0){
+ println(String.format("%.3f ms", (double)d.toNanos() / 1_000_000));
+ } else if(d.compareTo(MINUTE) < 0){
+ println(String.format("%.3f s", (double)d.toMillis() / 1_000));
} else {
- if (s < 1000.0) {
- println(String.format("%.3f", s) + " s");
- } else {
- println(String.format("%.0f", s) + " s");
- }
+ println(String.format("%d s", d.toSeconds()));
}
return true;
}