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