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 |
30 import java.util.List; |
30 import java.util.List; |
31 |
31 |
32 import jdk.jfr.EventType; |
32 import jdk.jfr.EventType; |
33 import jdk.jfr.ValueDescriptor; |
33 import jdk.jfr.ValueDescriptor; |
34 import jdk.jfr.internal.EventInstrumentation; |
34 import jdk.jfr.internal.EventInstrumentation; |
|
35 import jdk.jfr.internal.consumer.ObjectContext; |
35 |
36 |
36 /** |
37 /** |
37 * A recorded event. |
38 * A recorded event. |
38 * |
39 * |
39 * @since 9 |
40 * @since 9 |
40 */ |
41 */ |
41 public final class RecordedEvent extends RecordedObject { |
42 public final class RecordedEvent extends RecordedObject { |
42 private final EventType eventType; |
43 long startTimeTicks; |
43 private final long startTime; |
44 long endTimeTicks; |
44 // package private needed for efficient sorting |
|
45 final long endTime; |
|
46 |
45 |
47 // package private |
46 // package private |
48 RecordedEvent(EventType type, List<ValueDescriptor> vds, Object[] values, long startTime, long endTime, TimeConverter timeConverter) { |
47 RecordedEvent(ObjectContext objectContext, Object[] values, long startTimeTicks, long endTimeTicks) { |
49 super(vds, values, timeConverter); |
48 super(objectContext, values); |
50 this.eventType = type; |
49 this.startTimeTicks = startTimeTicks; |
51 this.startTime = startTime; |
50 this.endTimeTicks = endTimeTicks; |
52 this.endTime = endTime; |
|
53 } |
51 } |
54 |
52 |
55 /** |
53 /** |
56 * Returns the stack trace that was created when the event was committed, or |
54 * Returns the stack trace that was created when the event was committed, or |
57 * {@code null} if the event lacks a stack trace. |
55 * {@code null} if the event lacks a stack trace. |
76 * Returns the event type that describes the event. |
74 * Returns the event type that describes the event. |
77 * |
75 * |
78 * @return the event type, not {@code null} |
76 * @return the event type, not {@code null} |
79 */ |
77 */ |
80 public EventType getEventType() { |
78 public EventType getEventType() { |
81 return eventType; |
79 return objectContext.eventType; |
82 } |
80 } |
83 |
81 |
84 /** |
82 /** |
85 * Returns the start time of the event. |
83 * Returns the start time of the event. |
86 * <p> |
84 * <p> |
87 * If the event is an instant event, then the start time and end time are the same. |
85 * If the event is an instant event, then the start time and end time are the same. |
88 * |
86 * |
89 * @return the start time, not {@code null} |
87 * @return the start time, not {@code null} |
90 */ |
88 */ |
91 public Instant getStartTime() { |
89 public Instant getStartTime() { |
92 return Instant.ofEpochSecond(0, startTime); |
90 return Instant.ofEpochSecond(0, getStartTimeNanos()); |
93 } |
91 } |
94 |
92 |
95 /** |
93 /** |
96 * Returns the end time of the event. |
94 * Returns the end time of the event. |
97 * <p> |
95 * <p> |
98 * If the event is an instant event, then the start time and end time are the same. |
96 * If the event is an instant event, then the start time and end time are the same. |
99 * |
97 * |
100 * @return the end time, not {@code null} |
98 * @return the end time, not {@code null} |
101 */ |
99 */ |
102 public Instant getEndTime() { |
100 public Instant getEndTime() { |
103 return Instant.ofEpochSecond(0, endTime); |
101 return Instant.ofEpochSecond(0, getEndTimeNanos()); |
104 } |
102 } |
105 |
103 |
106 /** |
104 /** |
107 * Returns the duration of the event, measured in nanoseconds. |
105 * Returns the duration of the event, measured in nanoseconds. |
108 * |
106 * |
109 * @return the duration in nanoseconds, not {@code null} |
107 * @return the duration in nanoseconds, not {@code null} |
110 */ |
108 */ |
111 public Duration getDuration() { |
109 public Duration getDuration() { |
112 return Duration.ofNanos(endTime - startTime); |
110 return Duration.ofNanos(getEndTimeNanos() - getStartTimeNanos()); |
113 } |
111 } |
114 |
112 |
115 /** |
113 /** |
116 * Returns the list of descriptors that describes the fields of the event. |
114 * Returns the list of descriptors that describes the fields of the event. |
117 * |
115 * |
118 * @return descriptors, not {@code null} |
116 * @return descriptors, not {@code null} |
119 */ |
117 */ |
120 @Override |
118 @Override |
121 public List<ValueDescriptor> getFields() { |
119 public List<ValueDescriptor> getFields() { |
122 return getEventType().getFields(); |
120 return objectContext.fields; |
|
121 } |
|
122 |
|
123 protected final Object objectAt(int index) { |
|
124 if (index == 0) { |
|
125 return startTimeTicks; |
|
126 } |
|
127 if (hasDuration()) { |
|
128 if (index == 1) { |
|
129 return endTimeTicks - startTimeTicks; |
|
130 } |
|
131 return objects[index - 2]; |
|
132 } |
|
133 return objects[index - 1]; |
|
134 } |
|
135 |
|
136 private boolean hasDuration() { |
|
137 return objects.length + 2 == objectContext.fields.size(); |
|
138 } |
|
139 |
|
140 private long getStartTimeNanos() { |
|
141 return objectContext.convertTimestamp(startTimeTicks); |
|
142 } |
|
143 |
|
144 private long getEndTimeNanos() { |
|
145 return objectContext.convertTimestamp(endTimeTicks); |
123 } |
146 } |
124 } |
147 } |