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 } |