[Bug 303523] LTTng/TMF udpates:
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.jni / src / org / eclipse / linuxtools / lttng / jni / JniTracefile.java
CommitLineData
0152140d
ASL
1package org.eclipse.linuxtools.lttng.jni;
2/*******************************************************************************
3 * Copyright (c) 2009 Ericsson
4 *
5 * All rights reserved. This program and the accompanying materials are
6 * made available under the terms of the Eclipse Public License v1.0 which
7 * accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *
10 * Contributors:
11 * William Bourque (wbourque@gmail.com) - Initial API and implementation
12 *******************************************************************************/
13
14
15import java.util.HashMap;
16
17import org.eclipse.linuxtools.lttng.jni.common.JniTime;
18import org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer;
0152140d
ASL
19import org.eclipse.linuxtools.lttng.jni.exception.JniException;
20import org.eclipse.linuxtools.lttng.jni.exception.JniNoSuchEventException;
21import org.eclipse.linuxtools.lttng.jni.exception.JniTracefileException;
22import org.eclipse.linuxtools.lttng.jni.exception.JniTracefileWithoutEventException;
23
24/**
25 * <b><u>JniTracefile</u></b>
26 * <p>
27 * A tracefile own an event of a certain type.<br>
28 * Provides access to the LttTracefile C structure in java.
29 * <p>
30 * Most important fields in the JniTracefile are :
31 * <ul>
32 * <li> a JniTracefile path (a tracefile <b>file</b> within a JniTrace directory)
33 * <li> a name (basically the name without the directory part)
34 * <li> a reference to a single event object
35 * <li> a HashMap of marker associated with this tracefile
36 * </ul>
0152140d 37 */
a9fcdd8d
WB
38public abstract class JniTracefile extends Jni_C_Common {
39
0152140d 40 // Internal C pointer of the JniTracefile used in LTT
a9fcdd8d 41 private Jni_C_Pointer thisTracefilePtr = new Jni_C_Pointer();
0152140d
ASL
42
43 // Reference to the parent trace
44 private JniTrace parentTrace = null;
45
46 // Data we should populate from LTT
47 // Note that all type have been scaled up as there is no "unsigned" in java
48 // This might be a problem about "unsigned long" as there is no equivalent in java
49 private boolean isCpuOnline = false;
50 private String tracefilePath = "";
51 private String tracefileName = "";
52 private long cpuNumber = 0;
53 private long tid = 0;
54 private long pgid = 0;
55 private long creation = 0;
56
57 // Internal C pointer for trace and marker
0152140d
ASL
58 private Jni_C_Pointer tracePtr = null;
59 private Jni_C_Pointer markerDataPtr = null;
60
61 private int CFileDescriptor = 0;
62 private long fileSize = 0;
63 private long blocksNumber = 0;
64 private boolean isBytesOrderReversed = false;
65 private boolean isFloatWordOrdered = false;
66 private long alignement = 0;
67 private long bufferHeaderSize = 0;
68 private int bitsOfCurrentTimestampCounter = 0;
69 private int bitsOfEvent = 0;
70 private long currentTimestampCounterMask = 0;
71 private long currentTimestampCounterMaskNextBit = 0;
72 private long eventsLost = 0;
73 private long subBufferCorrupt = 0;
74 private JniEvent currentEvent = null;
75
76 // Internal C pointer for trace and marker
0152140d
ASL
77 private Jni_C_Pointer bufferPtr = null;
78
79 private long bufferSize = 0;
80
81 // This map will hold markers_info owned by this tracefile
82 private HashMap<Integer, JniMarker> tracefileMarkersMap = null;
83
84 // Native access functions
a9fcdd8d
WB
85 protected native boolean ltt_getIsCpuOnline(long tracefilePtr);
86 protected native String ltt_getTracefilepath(long tracefilePtr);
87 protected native String ltt_getTracefilename(long tracefilePtr);
88 protected native long ltt_getCpuNumber(long tracefilePtr);
89 protected native long ltt_getTid(long tracefilePtr);
90 protected native long ltt_getPgid(long tracefilePtr);
91 protected native long ltt_getCreation(long tracefilePtr);
92 protected native long ltt_getTracePtr(long tracefilePtr);
93 protected native long ltt_getMarkerDataPtr(long tracefilePtr);
94 protected native int ltt_getCFileDescriptor(long tracefilePtr);
95 protected native long ltt_getFileSize(long tracefilePtr);
96 protected native long ltt_getBlockNumber(long tracefilePtr);
97 protected native boolean ltt_getIsBytesOrderReversed(long tracefilePtr);
98 protected native boolean ltt_getIsFloatWordOrdered(long tracefilePtr);
99 protected native long ltt_getAlignement(long tracefilePtr);
100 protected native long ltt_getBufferHeaderSize(long tracefilePtr);
101 protected native int ltt_getBitsOfCurrentTimestampCounter(long tracefilePtr);
102 protected native int ltt_getBitsOfEvent(long tracefilePtr);
103 protected native long ltt_getCurrentTimestampCounterMask(long tracefilePtr);
104 protected native long ltt_getCurrentTimestampCounterMaskNextBit(long tracefilePtr);
105 protected native long ltt_getEventsLost(long tracefilePtr);
106 protected native long ltt_getSubBufferCorrupt(long tracefilePtr);
107 protected native long ltt_getEventPtr(long tracefilePtr);
108 protected native long ltt_getBufferPtr(long tracefilePtr);
109 protected native long ltt_getBufferSize(long tracefilePtr);
110
0152140d 111 // Method to fill a map with marker object
a9fcdd8d 112 protected native void ltt_feedAllMarkers(long tracefilePtr);
0152140d
ASL
113
114 // Debug native function, ask LTT to print tracefile structure
a9fcdd8d
WB
115 protected native void ltt_printTracefile(long tracefilePtr);
116
df13e29f
WB
117 // *** FIXME ***
118 // To uncomment as soon as the library will be able to load multiple version at once
119 // static {
120 // System.loadLibrary("lttvtraceread_loader");
121 //}
0152140d
ASL
122
123 /*
124 * Default constructor is forbidden
125 */
126 protected JniTracefile() {
127 }
128
129 /**
130 * Copy constructor.<p>
131 *
132 * @param oldTracefile Reference to the JniTracefile you want to copy.
133 */
134 public JniTracefile(JniTracefile oldTracefile) {
135 thisTracefilePtr = oldTracefile.thisTracefilePtr;
136 parentTrace = oldTracefile.parentTrace;
137 tracefileMarkersMap = oldTracefile.tracefileMarkersMap;
138 isCpuOnline = oldTracefile.isCpuOnline;
139 tracefilePath = oldTracefile.tracefilePath;
140 tracefileName = oldTracefile.tracefileName;
141 cpuNumber = oldTracefile.cpuNumber;
142 tid = oldTracefile.tid;
143 pgid = oldTracefile.pgid;
144 creation = oldTracefile.creation;
145 tracePtr = oldTracefile.tracePtr;
146 markerDataPtr = oldTracefile.markerDataPtr;
147 CFileDescriptor = oldTracefile.CFileDescriptor;
148 fileSize = oldTracefile.fileSize;
149 blocksNumber = oldTracefile.blocksNumber;
150 isBytesOrderReversed = oldTracefile.isBytesOrderReversed;
151 isFloatWordOrdered = oldTracefile.isFloatWordOrdered;
152 alignement = oldTracefile.alignement;
153 bufferHeaderSize = oldTracefile.bufferHeaderSize;
154 bitsOfCurrentTimestampCounter = oldTracefile.bitsOfCurrentTimestampCounter;
155 bitsOfEvent = oldTracefile.bitsOfEvent;
156 currentTimestampCounterMask = oldTracefile.currentTimestampCounterMask;
157 currentTimestampCounterMaskNextBit = oldTracefile.currentTimestampCounterMaskNextBit;
158 eventsLost = oldTracefile.eventsLost;
159 subBufferCorrupt = oldTracefile.subBufferCorrupt;
160 currentEvent = oldTracefile.currentEvent;
161 bufferPtr = oldTracefile.bufferPtr;
162 bufferSize = oldTracefile.bufferSize;
163 }
164
165 /**
166 * Constructor, using C pointer.<p>
167 *
a9fcdd8d 168 * @param newPtr The pointer of an already opened LttTracefile C Structure
0152140d
ASL
169 *
170 * @exception JniException
171 *
a9fcdd8d
WB
172 * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTrace
173 * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
0152140d 174 */
a9fcdd8d
WB
175 public JniTracefile(Jni_C_Pointer newPtr, JniTrace newParentTrace) throws JniException {
176 thisTracefilePtr = newPtr;
0152140d
ASL
177 parentTrace = newParentTrace;
178 tracefileMarkersMap = new HashMap<Integer, JniMarker>();
179
180 // Retrieve the trace file information and load the first event.
181 try {
182 populateTracefileInformation();
a9fcdd8d
WB
183 } catch (JniNoSuchEventException e) {
184 throw new JniTracefileWithoutEventException(
185 "JniEvent constructor reported that no event of this type are usable. (Jaf_Tracefile)");
0152140d
ASL
186 }
187 }
188
189 /**
190 * Read the next event of this tracefile.<p>
191 *
192 * Note : If the read succeed, the event will be populated.<p>
193 *
a9fcdd8d 194 * @return LTT read status, as defined in Jni_C_Common
0152140d 195 *
a9fcdd8d 196 * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common
0152140d
ASL
197 */
198 public int readNextEvent() {
199 return currentEvent.readNextEvent();
200 }
201
202 /**
203 * Seek to the given time.<p>
204 *
205 * Note : If the seek succeed, the event will be populated.
206 *
207 * @param seekTime The timestamp where to seek.
208 *
a9fcdd8d 209 * @return LTT read status, as defined in Jni_C_Common
0152140d 210 *
a9fcdd8d 211 * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common
0152140d
ASL
212 */
213 public int seekToTime(JniTime seekTime) {
214 return currentEvent.seekToTime(seekTime);
215 }
216
217 /*
218 * This function populates the tracefile data with data from LTT
219 *
220 * @throws JniException
221 */
222 private void populateTracefileInformation() throws JniException {
223 if (thisTracefilePtr.getPointer() == NULL) {
a9fcdd8d
WB
224 throw new JniTracefileException(
225 "Pointer is NULL, trace closed? (populateTracefileInformation)");
0152140d
ASL
226 }
227
a9fcdd8d
WB
228 isCpuOnline = ltt_getIsCpuOnline( thisTracefilePtr.getPointer() );
229 tracefilePath = ltt_getTracefilepath( thisTracefilePtr.getPointer() );
230 tracefileName = ltt_getTracefilename( thisTracefilePtr.getPointer() );
231 cpuNumber = ltt_getCpuNumber( thisTracefilePtr.getPointer() );
232 tid = ltt_getTid( thisTracefilePtr.getPointer() );
233 pgid = ltt_getPgid( thisTracefilePtr.getPointer() );
234 creation = ltt_getCreation( thisTracefilePtr.getPointer() );
235 tracePtr = new Jni_C_Pointer(ltt_getTracePtr( thisTracefilePtr.getPointer()) );
236 markerDataPtr = new Jni_C_Pointer(ltt_getMarkerDataPtr( thisTracefilePtr.getPointer()) );
237 CFileDescriptor = ltt_getCFileDescriptor( thisTracefilePtr.getPointer() );
238 fileSize = ltt_getFileSize( thisTracefilePtr.getPointer() );
239 blocksNumber = ltt_getBlockNumber( thisTracefilePtr.getPointer() );
240 isBytesOrderReversed = ltt_getIsBytesOrderReversed( thisTracefilePtr.getPointer() );
241 isFloatWordOrdered = ltt_getIsFloatWordOrdered( thisTracefilePtr.getPointer() );
242 alignement = ltt_getAlignement( thisTracefilePtr.getPointer() );
243 bufferHeaderSize = ltt_getBufferHeaderSize( thisTracefilePtr.getPointer() );
244 bitsOfCurrentTimestampCounter = ltt_getBitsOfCurrentTimestampCounter( thisTracefilePtr.getPointer() );
245 bitsOfEvent = ltt_getBitsOfEvent( thisTracefilePtr.getPointer() );
246 currentTimestampCounterMask = ltt_getCurrentTimestampCounterMask( thisTracefilePtr.getPointer() );
247 currentTimestampCounterMaskNextBit = ltt_getCurrentTimestampCounterMaskNextBit( thisTracefilePtr.getPointer() );
248 eventsLost = ltt_getEventsLost( thisTracefilePtr.getPointer() );
249 subBufferCorrupt = ltt_getSubBufferCorrupt( thisTracefilePtr.getPointer() );
250 bufferPtr = new Jni_C_Pointer(ltt_getBufferPtr( thisTracefilePtr.getPointer()) );
251 bufferSize = ltt_getBufferSize( thisTracefilePtr.getPointer() );
0152140d
ASL
252
253 // To fill the map is a bit different
a9fcdd8d 254 ltt_feedAllMarkers( thisTracefilePtr.getPointer() );
0152140d 255
a9fcdd8d 256 Jni_C_Pointer tmpEventPointer = new Jni_C_Pointer(ltt_getEventPtr(thisTracefilePtr.getPointer()));
0152140d
ASL
257 currentEvent = allocateNewJniEvent(tmpEventPointer , tracefileMarkersMap, this);
258 }
259
260 /*
261 * Fills a map of all the markers associated with this tracefile.
262 *
263 * Note: This function is called from C and there is no way to propagate
264 * exception back to the caller without crashing JNI. Therefore, it MUST
265 * catch all exceptions.
266 *
267 * @param markerId Id of the marker (int)
268 * @param markerInfoPtr C Pointer to a marker_info C structure
269 */
a9fcdd8d
WB
270 @SuppressWarnings("unused")
271 private void addMarkersFromC(int markerId, long markerInfoPtr) {
0152140d
ASL
272 // Create a new tracefile object and insert it in the map
273 // the tracefile fill itself with LTT data while being constructed
274 try {
a9fcdd8d 275 JniMarker newMarker = allocateNewJniMarker( new Jni_C_Pointer(markerInfoPtr) );
0152140d
ASL
276
277 tracefileMarkersMap.put(markerId, newMarker);
278 } catch (Exception e) {
a9fcdd8d 279 printlnC("Failed to add marker to tracefileMarkersMap!(addMarkersFromC)\n\tException raised : " + e.toString());
0152140d
ASL
280 }
281 }
282
283 // Access to class variable. Most of them doesn't have setter
284 public boolean getIsCpuOnline() {
285 return isCpuOnline;
286 }
287
288 public String getTracefilePath() {
289 return tracefilePath;
290 }
291
292 public String getTracefileName() {
293 return tracefileName;
294 }
295
296 public long getCpuNumber() {
297 return cpuNumber;
298 }
299
300 public long getTid() {
301 return tid;
302 }
303
304 public long getPgid() {
305 return pgid;
306 }
307
308 public long getCreation() {
309 return creation;
310 }
311
312 public Jni_C_Pointer getTracePtr() {
313 return tracePtr;
314 }
315
316 public Jni_C_Pointer getMarkerDataPtr() {
317 return markerDataPtr;
318 }
319
320 public int getCFileDescriptor() {
321 return CFileDescriptor;
322 }
323
324 public long getFileSize() {
325 return fileSize;
326 }
327
328 public long getBlocksNumber() {
329 return blocksNumber;
330 }
331
332 public boolean getIsBytesOrderReversed() {
333 return isBytesOrderReversed;
334 }
335
336 public boolean getIsFloatWordOrdered() {
337 return isFloatWordOrdered;
338 }
339
340 public long getAlignement() {
341 return alignement;
342 }
343
344 public long getBufferHeaderSize() {
345 return bufferHeaderSize;
346 }
347
348 public int getBitsOfCurrentTimestampCounter() {
349 return bitsOfCurrentTimestampCounter;
350 }
351
352 public int getBitsOfEvent() {
353 return bitsOfEvent;
354 }
355
356 public long getCurrentTimestampCounterMask() {
357 return currentTimestampCounterMask;
358 }
359
360 public long getCurrentTimestampCounterMaskNextBit() {
361 return currentTimestampCounterMaskNextBit;
362 }
363
364 public long getEventsLost() {
365 return eventsLost;
366 }
367
368 public long getSubBufferCorrupt() {
369 return subBufferCorrupt;
370 }
371
372 public JniEvent getCurrentEvent() {
373 return currentEvent;
374 }
375
376 public Jni_C_Pointer getBufferPtr() {
377 return bufferPtr;
378 }
379
380 public long getBufferSize() {
381 return bufferSize;
382 }
383
384 public HashMap<Integer, JniMarker> getTracefileMarkersMap() {
385 return tracefileMarkersMap;
386 }
387
388 /**
389 * Parent trace of this tracefile.<p>
390 *
391 * @return The parent trace
392 *
a9fcdd8d 393 * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTrace
0152140d
ASL
394 */
395 public JniTrace getParentTrace() {
396 return parentTrace;
397 }
398
399 /**
400 * Pointer to the LttTracefile C structure<p>
401 *
402 * The pointer should only be used <u>INTERNALY</u>, do not use unless you
403 * know what you are doing.<p>
404 *
405 * @return The actual (long converted) pointer or NULL.
406 *
a9fcdd8d 407 * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
0152140d 408 */
a9fcdd8d 409 public Jni_C_Pointer getTracefilePtr() {
0152140d
ASL
410 return thisTracefilePtr;
411 }
412
413 /**
414 * Print information for this tracefile.
415 * <u>Intended to debug</u><p>
416 *
417 * This function will call Ltt to print, so information printed will be the
418 * one from the C structure, not the one populated in java.<p>
a9fcdd8d
WB
419 *
420 * This function will not throw but will complain loudly if pointer is NULL.
0152140d
ASL
421 */
422 public void printTracefileInformation() {
a9fcdd8d
WB
423
424 // If null pointer, print a warning!
425 if (thisTracefilePtr.getPointer() == NULL) {
426 printlnC("Pointer is NULL, cannot print. (printTracefileInformation)");
427 }
428 else {
429 ltt_printTracefile( thisTracefilePtr.getPointer() );
430 }
0152140d
ASL
431 }
432
433 /**
434 * toString() method.
435 * <u>Intended to debug</u><p>
436 *
437 * @return Attributes of the object concatenated in String
438 */
439 @Override
440 public String toString() {
441 String returnData = "";
442
443 returnData += "isCpuOnline : " + isCpuOnline + "\n";
444 returnData += "tracefilePath : " + tracefilePath + "\n";
445 returnData += "tracefileName : " + tracefileName + "\n";
446 returnData += "cpuNumber : " + cpuNumber + "\n";
447 returnData += "tid : " + tid + "\n";
448 returnData += "pgid : " + pgid + "\n";
449 returnData += "creation : " + creation + "\n";
450 returnData += "tracePtr : " + tracePtr + "\n";
451 returnData += "markerDataPtr : " + markerDataPtr + "\n";
452 returnData += "CFileDescriptor : " + CFileDescriptor + "\n";
453 returnData += "fileSize : " + fileSize + "\n";
454 returnData += "blocksNumber : " + blocksNumber + "\n";
455 returnData += "isBytesOrderReversed : " + isBytesOrderReversed + "\n";
456 returnData += "isFloatWordOrdered : " + isFloatWordOrdered + "\n";
457 returnData += "alignement : " + alignement + "\n";
458 returnData += "bufferHeaderSize : " + bufferHeaderSize + "\n";
459 returnData += "bitsOfCurrentTimestampCounter : " + bitsOfCurrentTimestampCounter + "\n";
460 returnData += "bitsOfEvent : " + bitsOfEvent + "\n";
461 returnData += "currentTimestampCounterMask : " + currentTimestampCounterMask + "\n";
462 returnData += "currentTimestampCounterMaskNextBit : " + currentTimestampCounterMaskNextBit + "\n";
463 returnData += "eventsLost : " + eventsLost + "\n";
464 returnData += "subBufferCorrupt : " + subBufferCorrupt + "\n";
465 returnData += "currentEvent : " + currentEvent.getReferenceToString() + "\n"; // Hack to avoid ending up with event.toString()
466 returnData += "bufferPtr : " + bufferPtr + "\n";
467 returnData += "bufferSize : " + bufferSize + "\n";
468 returnData += "tracefileMarkersMap : " + tracefileMarkersMap.keySet() + "\n"; // Hack to avoid ending up with tracefileMarkersMap.toString()
469
470 return returnData;
471 }
472
473
a9fcdd8d
WB
474 public abstract JniEvent allocateNewJniEvent(Jni_C_Pointer newEventPtr, HashMap<Integer, JniMarker> newMarkersMap, JniTracefile newParentTracefile) throws JniException;
475 public abstract JniMarker allocateNewJniMarker(Jni_C_Pointer newMarkerPtr) throws JniException;
0152140d
ASL
476
477}
a9fcdd8d 478
This page took 0.043898 seconds and 5 git commands to generate.