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