Commit | Line | Data |
---|---|---|
5d10d135 ASL |
1 | package org.eclipse.linuxtools.lttng.event; |
2 | ||
a3fe52fc | 3 | import org.eclipse.linuxtools.lttng.jni.JniEvent; |
5d10d135 | 4 | import org.eclipse.linuxtools.tmf.event.TmfEvent; |
3fbd810a | 5 | import org.eclipse.linuxtools.tmf.event.TmfEventSource; |
b7f0ec69 | 6 | import org.eclipse.linuxtools.tmf.trace.TmfTrace; |
5d10d135 ASL |
7 | |
8 | /** | |
12c155f5 FC |
9 | * <b><u>LttngEvent</u></b> |
10 | * <p> | |
11 | * Lttng specific TmfEvent implementation. | |
12 | * <p> | |
13 | * The main difference from the basic Tmf implementation is that we keep an | |
14 | * internal reference to the JniEvent | |
15 | * <p> | |
07d9e2ee | 16 | * The conversion from this LttngEvent to the JniEvent is then possible. |
5d10d135 ASL |
17 | */ |
18 | public class LttngEvent extends TmfEvent { | |
12c155f5 | 19 | |
28b94d61 | 20 | // Reference to the JNI JniEvent. Should only be used INTERNALLY |
3fbd810a | 21 | private JniEvent jniEventReference = null; |
b7f0ec69 | 22 | |
12c155f5 FC |
23 | // Parameter-less constructor |
24 | public LttngEvent() { | |
25 | super(); | |
4bf17f4a | 26 | fType = LttngEventType.DEFAULT_EVENT_TYPE; |
12c155f5 FC |
27 | } |
28 | ||
5d10d135 | 29 | /** |
12c155f5 FC |
30 | * Constructor with parameters. |
31 | * <p> | |
5d10d135 | 32 | * |
12c155f5 FC |
33 | * @param timestamp The timestamp of this event |
34 | * @param source The source of this event | |
35 | * @param type The type of this event | |
36 | * @param content The content of this event | |
37 | * @param reference The reference of this event | |
38 | * @param lttEvent A reference to a valid JniEvent object | |
5d10d135 ASL |
39 | * |
40 | * @see org.eclipse.linuxtools.tmf.event.TmfTimestamp | |
07d9e2ee | 41 | * @see org.eclipse.linuxtools.tmf.event.TmfEventSource |
5d10d135 ASL |
42 | * @see org.eclipse.linuxtools.lttng.event.LttngEventType |
43 | * @see org.eclipse.linuxtools.lttng.event.LttngEventContent | |
44 | * @see org.eclipse.linuxtools.lttng.event.LttngEventReference | |
28b94d61 | 45 | * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent |
5d10d135 | 46 | */ |
12c155f5 FC |
47 | public LttngEvent(TmfTrace<LttngEvent> parent, LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content, |
48 | LttngEventReference reference, JniEvent lttEvent) { | |
28b94d61 | 49 | super(timestamp, source, type, reference); |
12c155f5 | 50 | |
28b94d61 | 51 | fContent = content; |
5d10d135 | 52 | jniEventReference = lttEvent; |
b7f0ec69 | 53 | setParentTrace(parent); |
5d10d135 | 54 | } |
12c155f5 | 55 | |
3fbd810a | 56 | /** |
12c155f5 FC |
57 | * Copy constructor. |
58 | * <p> | |
3fbd810a | 59 | * |
12c155f5 | 60 | * @param oldEvent Event we want to copy from. |
3fbd810a | 61 | */ |
2c8610f7 | 62 | @SuppressWarnings("unchecked") |
a3fe52fc | 63 | public LttngEvent(LttngEvent oldEvent) { |
b7f0ec69 | 64 | this( |
2c8610f7 | 65 | (TmfTrace<LttngEvent>) oldEvent.getParentTrace(), |
b7f0ec69 | 66 | (LttngTimestamp)oldEvent.getTimestamp(), |
3fbd810a FC |
67 | (TmfEventSource)oldEvent.getSource(), |
68 | (LttngEventType)oldEvent.getType(), | |
69 | (LttngEventContent)oldEvent.getContent(), | |
70 | (LttngEventReference)oldEvent.getReference(), | |
71 | oldEvent.jniEventReference | |
72 | ); | |
73 | } | |
b7f0ec69 WB |
74 | /** |
75 | * Set a new parent trace for this event | |
76 | * | |
12c155f5 | 77 | * @param parentTrace The new parent |
b7f0ec69 WB |
78 | */ |
79 | public void setParentTrace(TmfTrace<LttngEvent> parentTrace) { | |
2c8610f7 | 80 | fParentTrace = parentTrace; |
b7f0ec69 WB |
81 | } |
82 | ||
83 | ||
84 | /** | |
07d9e2ee | 85 | * Return the channel name of this event.<p> |
5d10d135 | 86 | * |
28b94d61 | 87 | * @return Channel (tracefile) for this event |
5d10d135 ASL |
88 | */ |
89 | public String getChannelName() { | |
12c155f5 | 90 | return this.getType().getTracefileName(); |
5d10d135 | 91 | } |
12c155f5 | 92 | |
5d10d135 | 93 | /** |
12c155f5 FC |
94 | * Cpu id number of this event. |
95 | * <p> | |
5d10d135 | 96 | * |
a3fe52fc | 97 | * @return CpuId |
5d10d135 ASL |
98 | */ |
99 | public long getCpuId() { | |
12c155f5 | 100 | return this.getType().getCpuId(); |
5d10d135 | 101 | } |
12c155f5 | 102 | |
5d10d135 | 103 | /** |
12c155f5 FC |
104 | * Marker name of this event. |
105 | * <p> | |
5d10d135 | 106 | * |
28b94d61 | 107 | * @return Marker name |
5d10d135 ASL |
108 | */ |
109 | public String getMarkerName() { | |
12c155f5 | 110 | return this.getType().getMarkerName(); |
5d10d135 | 111 | } |
12c155f5 | 112 | |
b12f4544 | 113 | /** |
12c155f5 FC |
114 | * Marker id of this event. |
115 | * <p> | |
b12f4544 FC |
116 | * |
117 | * @return Marker id | |
118 | */ | |
119 | public int getMarkerId() { | |
12c155f5 | 120 | return this.getType().getMarkerId(); |
b12f4544 | 121 | } |
12c155f5 | 122 | |
28b94d61 FC |
123 | @Override |
124 | public LttngEventContent getContent() { | |
12c155f5 | 125 | return (LttngEventContent) fContent; |
28b94d61 | 126 | } |
12c155f5 | 127 | |
28b94d61 FC |
128 | public void setContent(LttngEventContent newContent) { |
129 | fContent = newContent; | |
130 | } | |
12c155f5 | 131 | |
28b94d61 FC |
132 | @Override |
133 | public LttngEventType getType() { | |
12c155f5 | 134 | return (LttngEventType) fType; |
28b94d61 | 135 | } |
12c155f5 | 136 | |
28b94d61 FC |
137 | public void setType(LttngEventType newType) { |
138 | fType = newType; | |
139 | } | |
12c155f5 | 140 | |
b7f0ec69 | 141 | /** |
12c155f5 FC |
142 | * Set a new JniReference for this event. |
143 | * <p> | |
b7f0ec69 | 144 | * |
12c155f5 FC |
145 | * Note : Reference is used to get back to the Jni during event parsing and |
146 | * need to be consistent. | |
b7f0ec69 | 147 | * |
12c155f5 | 148 | * @param newJniEventReference New reference |
b7f0ec69 WB |
149 | * |
150 | * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent | |
151 | */ | |
47e81b11 | 152 | public synchronized void updateJniEventReference(JniEvent newJniEventReference) { |
b7f0ec69 WB |
153 | this.jniEventReference = newJniEventReference; |
154 | } | |
12c155f5 | 155 | |
5d10d135 | 156 | /** |
12c155f5 FC |
157 | * Convert this event into a Jni JniEvent. |
158 | * <p> | |
07d9e2ee | 159 | * |
12c155f5 FC |
160 | * Note : Some verifications are done to make sure the event is still valid |
161 | * on the Jni side before conversion.<br> | |
162 | * If it is not the case, null will be returned. | |
07d9e2ee FC |
163 | * |
164 | * @return The converted JniEvent | |
5d10d135 | 165 | * |
28b94d61 | 166 | * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent |
5d10d135 | 167 | */ |
a55a769e | 168 | public synchronized JniEvent convertEventTmfToJni() { |
5d10d135 | 169 | JniEvent tmpEvent = null; |
12c155f5 | 170 | |
28b94d61 FC |
171 | // ***TODO*** |
172 | // Should we remove the check to save some time?? | |
12c155f5 FC |
173 | |
174 | // We don't want to send away events that are outdated as their | |
175 | // informations could be invalid | |
176 | // If the timestamp between the event and the trace are not coherent we | |
177 | // will not perform the conversion | |
178 | if (jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime() == getTimestamp().getValue()) { | |
a55a769e | 179 | tmpEvent = jniEventReference; |
12c155f5 FC |
180 | } else { |
181 | System.out | |
182 | .println("convertEventTmfToJni() failed: Unsynced Timestamp > TMF:" + getTimestamp().getValue() + " <--> JNI:" + jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime()); //$NON-NLS-1$//$NON-NLS-2$ | |
a55a769e | 183 | } |
5d10d135 ASL |
184 | return tmpEvent; |
185 | } | |
12c155f5 | 186 | |
3fbd810a | 187 | @Override |
3b38ea61 | 188 | @SuppressWarnings("nls") |
12c155f5 FC |
189 | public String toString() { |
190 | StringBuffer result = new StringBuffer("[LttngEvent("); | |
191 | result.append("Timestamp:" + getTimestamp().getValue()); | |
192 | result.append(",Channel:" + getChannelName()); | |
193 | result.append(",CPU:" + getCpuId()); | |
194 | result.append(",Marker:" + getMarkerName()); | |
195 | result.append(",Content:" + getContent() + ")]"); | |
196 | ||
197 | return result.toString(); | |
3fbd810a | 198 | } |
12c155f5 | 199 | |
f9673903 FC |
200 | @Override |
201 | public LttngEvent clone() { | |
1a971e96 FC |
202 | LttngEvent clone = (LttngEvent) super.clone(); |
203 | clone.getContent().setEvent(clone); | |
1a971e96 FC |
204 | clone.jniEventReference = jniEventReference; |
205 | return clone; | |
f9673903 | 206 | } |
1a971e96 | 207 | |
5d10d135 | 208 | } |