Commit | Line | Data |
---|---|---|
9cb4892d WB |
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 | ||
13 | import java.util.ArrayList; | |
14 | import org.eclipse.linuxtools.lttng.jni.JniEvent; | |
15 | import org.eclipse.linuxtools.lttng.jni.JniMarkerField; | |
16 | import org.eclipse.linuxtools.lttng.jni.JniTrace; | |
17 | import org.eclipse.linuxtools.lttng.jni.common.JniTime; | |
18 | import org.eclipse.linuxtools.lttng.jni.factory.JniTraceFactory; | |
19 | ||
20 | ||
3b38ea61 | 21 | @SuppressWarnings("nls") |
9cb4892d WB |
22 | public class JniTraceTest { |
23 | ||
24 | public static void main(String[] args) { | |
25 | ||
26 | // Path of the trace | |
27 | final String TRACE_PATH = "/home/william/trace-614601events-nolost-newformat"; | |
28 | ||
29 | // *** Change this to run several time over the same trace | |
30 | final int NB_OF_PASS = 1; | |
31 | ||
32 | // *** Change this to true to parse all the events in the trace | |
33 | // Otherwise, events are just read | |
34 | final boolean PARSE_EVENTS = true; | |
35 | ||
36 | ||
37 | // Work variables | |
38 | JniTrace tmptrace = null; | |
39 | JniEvent tmpevent = null; | |
40 | Long nbEvent = 0L; | |
41 | ||
42 | try { | |
43 | // Get the trace from the Factory... | |
44 | // This assume the path is correct and that the correct version of the lib is installed | |
45 | tmptrace = JniTraceFactory.getJniTrace(TRACE_PATH, false); | |
46 | ||
47 | // Seek beginning | |
48 | tmptrace.seekToTime(new JniTime(0L)); | |
49 | ||
50 | // Run up to "NB_OF_PASS" on the same trace | |
51 | for (int x=0; x<NB_OF_PASS; x++ ){ | |
52 | tmpevent = tmptrace.readNextEvent(); | |
53 | nbEvent++; | |
54 | ||
55 | while ( tmpevent != null ) { | |
56 | ||
57 | // Parse event if asked | |
58 | if ( PARSE_EVENTS ) { | |
59 | ArrayList<JniMarkerField> tmpFields = tmpevent.getMarkersMap().get(tmpevent.getEventMarkerId()).getMarkerFieldsArrayList(); | |
60 | for ( int pos=0; pos<tmpFields.size(); pos++ ) { | |
61 | @SuppressWarnings("unused") | |
62 | Object newValue = tmpevent.parseFieldById(pos); | |
63 | ||
64 | // *** Uncomment the following to print the parsed content | |
65 | // Warning : this is VERY intensive | |
66 | //if ( pos == (tmpFields.size() -1) ) { | |
2f17867c | 67 | // tmptrace.printC(tmpevent.getEventPtr().getLibraryId(), tmpFields.get(pos).getField() + ":" + newValue + " "); |
9cb4892d | 68 | //} else { |
2f17867c | 69 | // tmptrace.printlnC(tmpevent.getEventPtr().getLibraryId(), tmpFields.get(pos).getField() + ":" + newValue + " "); |
9cb4892d WB |
70 | //} |
71 | } | |
72 | } | |
73 | ||
74 | tmpevent = tmptrace.readNextEvent(); | |
75 | nbEvent++; | |
76 | } | |
77 | } | |
78 | ||
79 | System.out.println("NB Events read : " + nbEvent); | |
80 | } | |
81 | catch (Exception e) { | |
82 | e.printStackTrace(); | |
83 | } | |
84 | } | |
85 | ||
86 | } |