equal
deleted
inserted
replaced
55 * Print events in a human-readable format. |
55 * Print events in a human-readable format. |
56 * |
56 * |
57 * This class is also used by {@link RecordedObject#toString()} |
57 * This class is also used by {@link RecordedObject#toString()} |
58 */ |
58 */ |
59 public final class PrettyWriter extends EventPrintWriter { |
59 public final class PrettyWriter extends EventPrintWriter { |
|
60 private static final Duration MILLSECOND = Duration.ofMillis(1); |
|
61 private static final Duration SECOND = Duration.ofSeconds(1); |
|
62 private static final Duration MINUTE = Duration.ofMinutes(1); |
60 private static final String TYPE_OLD_OBJECT = Type.TYPES_PREFIX + "OldObject"; |
63 private static final String TYPE_OLD_OBJECT = Type.TYPES_PREFIX + "OldObject"; |
61 private final static DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm:ss.SSS"); |
64 private final static DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm:ss.SSS"); |
62 private final static Long ZERO = 0L; |
65 private final static Long ZERO = 0L; |
63 private boolean showIds; |
66 private boolean showIds; |
64 private RecordedEvent currentEvent; |
67 private RecordedEvent currentEvent; |
548 Duration d = (Duration) value; |
551 Duration d = (Duration) value; |
549 if (d.getSeconds() == Long.MIN_VALUE && d.getNano() == 0) { |
552 if (d.getSeconds() == Long.MIN_VALUE && d.getNano() == 0) { |
550 println("N/A"); |
553 println("N/A"); |
551 return true; |
554 return true; |
552 } |
555 } |
553 double s = d.toNanosPart() / 1000_000_000.0 + d.toSecondsPart(); |
556 if(d.compareTo(MILLSECOND) < 0){ |
554 if (s < 1.0) { |
557 println(String.format("%.3f us", (double)d.toNanos() / 1_000)); |
555 if (s < 0.001) { |
558 } else if(d.compareTo(SECOND) < 0){ |
556 println(String.format("%.3f", s * 1_000_000) + " us"); |
559 println(String.format("%.3f ms", (double)d.toNanos() / 1_000_000)); |
557 } else { |
560 } else if(d.compareTo(MINUTE) < 0){ |
558 println(String.format("%.3f", s * 1_000) + " ms"); |
561 println(String.format("%.3f s", (double)d.toMillis() / 1_000)); |
559 } |
|
560 } else { |
562 } else { |
561 if (s < 1000.0) { |
563 println(String.format("%d s", d.toSeconds())); |
562 println(String.format("%.3f", s) + " s"); |
|
563 } else { |
|
564 println(String.format("%.0f", s) + " s"); |
|
565 } |
|
566 } |
564 } |
567 return true; |
565 return true; |
568 } |
566 } |
569 if (value instanceof OffsetDateTime) { |
567 if (value instanceof OffsetDateTime) { |
570 OffsetDateTime odt = (OffsetDateTime) value; |
568 OffsetDateTime odt = (OffsetDateTime) value; |