equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
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); |
|
63 private static final String TYPE_OLD_OBJECT = Type.TYPES_PREFIX + "OldObject"; |
60 private static final String TYPE_OLD_OBJECT = Type.TYPES_PREFIX + "OldObject"; |
64 private final static DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm:ss.SSS"); |
61 private final static DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm:ss.SSS"); |
65 private final static Long ZERO = 0L; |
62 private final static Long ZERO = 0L; |
66 private boolean showIds; |
63 private boolean showIds; |
67 private RecordedEvent currentEvent; |
64 private RecordedEvent currentEvent; |
551 Duration d = (Duration) value; |
548 Duration d = (Duration) value; |
552 if (d.getSeconds() == Long.MIN_VALUE && d.getNano() == 0) { |
549 if (d.getSeconds() == Long.MIN_VALUE && d.getNano() == 0) { |
553 println("N/A"); |
550 println("N/A"); |
554 return true; |
551 return true; |
555 } |
552 } |
556 if(d.compareTo(MILLSECOND) < 0){ |
553 println(Utils.formatDuration(d)); |
557 println(String.format("%.3f us", (double)d.toNanos() / 1_000)); |
|
558 } else if(d.compareTo(SECOND) < 0){ |
|
559 println(String.format("%.3f ms", (double)d.toNanos() / 1_000_000)); |
|
560 } else if(d.compareTo(MINUTE) < 0){ |
|
561 println(String.format("%.3f s", (double)d.toMillis() / 1_000)); |
|
562 } else { |
|
563 println(String.format("%d s", d.toSeconds())); |
|
564 } |
|
565 return true; |
554 return true; |
566 } |
555 } |
567 if (value instanceof OffsetDateTime) { |
556 if (value instanceof OffsetDateTime) { |
568 OffsetDateTime odt = (OffsetDateTime) value; |
557 OffsetDateTime odt = (OffsetDateTime) value; |
569 if (odt.equals(OffsetDateTime.MIN)) { |
558 if (odt.equals(OffsetDateTime.MIN)) { |