src/jdk.jfr/share/classes/jdk/jfr/internal/tool/EventPrintWriter.java
changeset 58863 c16ac7a2eba4
parent 52850 f527b24990d7
equal deleted inserted replaced
58861:2c3cc4b01880 58863:c16ac7a2eba4
    28 import java.io.FileNotFoundException;
    28 import java.io.FileNotFoundException;
    29 import java.io.IOException;
    29 import java.io.IOException;
    30 import java.io.PrintWriter;
    30 import java.io.PrintWriter;
    31 import java.nio.file.Path;
    31 import java.nio.file.Path;
    32 import java.util.ArrayList;
    32 import java.util.ArrayList;
       
    33 import java.util.Collections;
    33 import java.util.HashMap;
    34 import java.util.HashMap;
    34 import java.util.List;
    35 import java.util.List;
    35 import java.util.Map;
    36 import java.util.Map;
    36 import java.util.function.Predicate;
    37 import java.util.function.Predicate;
    37 
    38 
    40 import jdk.jfr.Timestamp;
    41 import jdk.jfr.Timestamp;
    41 import jdk.jfr.ValueDescriptor;
    42 import jdk.jfr.ValueDescriptor;
    42 import jdk.jfr.consumer.RecordedEvent;
    43 import jdk.jfr.consumer.RecordedEvent;
    43 import jdk.jfr.consumer.RecordedObject;
    44 import jdk.jfr.consumer.RecordedObject;
    44 import jdk.jfr.consumer.RecordingFile;
    45 import jdk.jfr.consumer.RecordingFile;
    45 import jdk.jfr.internal.consumer.RecordingInternals;
    46 import jdk.jfr.internal.consumer.JdkJfrConsumer;
    46 
    47 
    47 abstract class EventPrintWriter extends StructuredWriter {
    48 abstract class EventPrintWriter extends StructuredWriter {
    48 
    49 
    49     enum ValueType {
    50     enum ValueType {
    50         TIMESPAN, TIMESTAMP, OTHER
    51         TIMESPAN, TIMESTAMP, OTHER
    51     }
    52     }
    52 
    53 
    53     protected static final String STACK_TRACE_FIELD = "stackTrace";
    54     protected static final String STACK_TRACE_FIELD = "stackTrace";
    54     protected static final String EVENT_THREAD_FIELD = "eventThread";
    55     protected static final String EVENT_THREAD_FIELD = "eventThread";
       
    56     private static final JdkJfrConsumer PRIVATE_ACCESS = JdkJfrConsumer.instance();
    55 
    57 
    56     private Predicate<EventType> eventFilter = x -> true;
    58     private Predicate<EventType> eventFilter = x -> true;
    57     private int stackDepth;
    59     private int stackDepth;
    58 
    60 
    59     // cach that will speed up annotation lookup
    61     // cach that will speed up annotation lookup
    72             while (file.hasMoreEvents()) {
    74             while (file.hasMoreEvents()) {
    73                 RecordedEvent event = file.readEvent();
    75                 RecordedEvent event = file.readEvent();
    74                 if (acceptEvent(event)) {
    76                 if (acceptEvent(event)) {
    75                     events.add(event);
    77                     events.add(event);
    76                 }
    78                 }
    77                 if (RecordingInternals.INSTANCE.isLastEventInChunk(file)) {
    79                 if (PRIVATE_ACCESS.isLastEventInChunk(file)) {
    78                     RecordingInternals.INSTANCE.sort(events);
    80                     Collections.sort(events, PRIVATE_ACCESS.eventComparator());
    79                     print(events);
    81                     print(events);
    80                     events.clear();
    82                     events.clear();
    81                 }
    83                 }
    82             }
    84             }
    83         }
    85         }
   119         }
   121         }
   120         switch (valueType) {
   122         switch (valueType) {
   121         case TIMESPAN:
   123         case TIMESPAN:
   122             return object.getDuration(v.getName());
   124             return object.getDuration(v.getName());
   123         case TIMESTAMP:
   125         case TIMESTAMP:
   124             return RecordingInternals.INSTANCE.getOffsetDataTime(object, v.getName());
   126             return PRIVATE_ACCESS.getOffsetDataTime(object, v.getName());
   125         default:
   127         default:
   126             return object.getValue(v.getName());
   128             return object.getValue(v.getName());
   127         }
   129         }
   128     }
   130     }
   129     // It's expensive t check
   131     // It's expensive t check