8223697: jfr tool can't format duration values greater than 1 minute
authorcito
Tue, 22 Oct 2019 23:55:33 +0200
changeset 58742 a6c56d661d75
parent 58741 62e16c1e0f66
child 58743 083bbca50d2d
8223697: jfr tool can't format duration values greater than 1 minute Reviewed-by: egahlin
src/jdk.jfr/share/classes/jdk/jfr/internal/tool/PrettyWriter.java
--- 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;
         }