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