tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core / src / org / eclipse / linuxtools / internal / lttng / core / event / LttngEvent.java
1 package org.eclipse.linuxtools.internal.lttng.core.event;
2
3 import org.eclipse.linuxtools.lttng.jni.JniEvent;
4 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
5 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
6 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
7
8 /**
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>
16 * The conversion from this LttngEvent to the JniEvent is then possible.
17 */
18 public class LttngEvent extends TmfEvent {
19
20 // Reference to the JNI JniEvent. Should only be used INTERNALLY
21 private JniEvent jniEventReference = null;
22
23 // Parameter-less constructor
24 public LttngEvent() {
25 super();
26 super.setType(LttngEventType.DEFAULT_EVENT_TYPE);
27 }
28
29 /**
30 * Constructor with parameters.
31 * <p>
32 *
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
39 *
40 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp
41 * @see org.eclipse.linuxtools.tmf.core.event.TmfEventSource
42 * @see org.eclipse.linuxtools.internal.lttng.core.event.LttngEventType
43 * @see org.eclipse.linuxtools.internal.lttng.core.event.LttngEventContent
44 * @see org.eclipse.linuxtools.lttng.core.event.LttngEventReference
45 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
46 */
47 public LttngEvent(TmfTrace parent, LttngTimestamp timestamp, String source, LttngEventType type, LttngEventContent content,
48 String reference, JniEvent lttEvent)
49 {
50 super(parent, timestamp, source, type, content, reference);
51 jniEventReference = lttEvent;
52 super.setTrace(parent);
53 }
54
55 /**
56 * Copy constructor.
57 * <p>
58 *
59 * @param oldEvent Event we want to copy from.
60 */
61 public LttngEvent(ITmfEvent oldEvent) {
62 this(
63 (TmfTrace) oldEvent.getTrace(),
64 (LttngTimestamp)oldEvent.getTimestamp(),
65 oldEvent.getSource(),
66 (LttngEventType)oldEvent.getType(),
67 (LttngEventContent)oldEvent.getContent(),
68 oldEvent.getReference(),
69 ((LttngEvent) oldEvent).jniEventReference
70 );
71 }
72 /**
73 * Set a new parent trace for this event
74 *
75 * @param parentTrace The new parent
76 */
77 public void setParentTrace(TmfTrace parentTrace) {
78 super.setTrace(parentTrace);
79 }
80
81
82 /**
83 * Return the channel name of this event.<p>
84 *
85 * @return Channel (tracefile) for this event
86 */
87 public String getChannelName() {
88 return this.getType().getTracefileName();
89 }
90
91 /**
92 * Cpu id number of this event.
93 * <p>
94 *
95 * @return CpuId
96 */
97 public long getCpuId() {
98 return this.getType().getCpuId();
99 }
100
101 /**
102 * Marker name of this event.
103 * <p>
104 *
105 * @return Marker name
106 */
107 public String getMarkerName() {
108 return this.getType().getMarkerName();
109 }
110
111 /**
112 * Marker id of this event.
113 * <p>
114 *
115 * @return Marker id
116 */
117 public int getMarkerId() {
118 return this.getType().getMarkerId();
119 }
120
121 @Override
122 public LttngEventContent getContent() {
123 return (LttngEventContent) super.getContent();
124 }
125
126 public void setContent(LttngEventContent newContent) {
127 super.setContent(newContent);
128 }
129
130 @Override
131 public void setReference(String reference) {
132 super.setReference(reference);
133 }
134
135 @Override
136 public LttngEventType getType() {
137 return (LttngEventType) super.getType();
138 }
139
140 public void setType(LttngEventType newType) {
141 super.setType(newType);
142 }
143
144 /**
145 * Set a new JniReference for this event.
146 * <p>
147 *
148 * Note : Reference is used to get back to the Jni during event parsing and
149 * need to be consistent.
150 *
151 * @param newJniEventReference New reference
152 *
153 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
154 */
155 public synchronized void updateJniEventReference(JniEvent newJniEventReference) {
156 this.jniEventReference = newJniEventReference;
157 }
158
159 /**
160 * Convert this event into a Jni JniEvent.
161 * <p>
162 *
163 * Note : Some verifications are done to make sure the event is still valid
164 * on the Jni side before conversion.<br>
165 * If it is not the case, null will be returned.
166 *
167 * @return The converted JniEvent
168 *
169 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
170 */
171 public synchronized JniEvent convertEventTmfToJni() {
172 JniEvent tmpEvent = null;
173
174 // ***TODO***
175 // Should we remove the check to save some time??
176
177 // We don't want to send away events that are outdated as their
178 // informations could be invalid
179 // If the timestamp between the event and the trace are not coherent we
180 // will not perform the conversion
181 if (jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime() == getTimestamp().getValue()) {
182 tmpEvent = jniEventReference;
183 } else {
184 System.out
185 .println("convertEventTmfToJni() failed: Unsynced Timestamp > TMF:" + getTimestamp().getValue() + " <--> JNI:" + jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime()); //$NON-NLS-1$//$NON-NLS-2$
186 }
187 return tmpEvent;
188 }
189
190 @Override
191 @SuppressWarnings("nls")
192 public String toString() {
193 StringBuffer result = new StringBuffer("[LttngEvent(");
194 result.append("Timestamp:" + getTimestamp().getValue());
195 result.append(",Channel:" + getChannelName());
196 result.append(",CPU:" + getCpuId());
197 result.append(",Marker:" + getMarkerName());
198 result.append(",Content:" + getContent() + ")]");
199
200 return result.toString();
201 }
202
203 @Override
204 public LttngEvent clone() {
205 LttngEvent clone = (LttngEvent) super.clone();
206 clone.getContent().setEvent(clone);
207 clone.jniEventReference = jniEventReference;
208 return clone;
209 }
210
211 /* (non-Javadoc)
212 * @see java.lang.Object#hashCode()
213 */
214 @Override
215 public synchronized int hashCode() {
216 final int prime = 31;
217 int result = super.hashCode();
218 result = prime * result + ((jniEventReference == null) ? 0 : jniEventReference.hashCode());
219 return result;
220 }
221
222 /* (non-Javadoc)
223 * @see java.lang.Object#equals(java.lang.Object)
224 */
225 @Override
226 public synchronized boolean equals(Object obj) {
227 if (this == obj) {
228 return true;
229 }
230 if (!super.equals(obj)) {
231 return false;
232 }
233 if (!(obj instanceof LttngEvent)) {
234 return false;
235 }
236 LttngEvent other = (LttngEvent) obj;
237 if (jniEventReference == null) {
238 if (other.jniEventReference != null) {
239 return false;
240 }
241 } else if (!jniEventReference.equals(other.jniEventReference)) {
242 return false;
243 }
244 return true;
245 }
246
247 }
This page took 0.038774 seconds and 5 git commands to generate.