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