June 4, 2010
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.headless / src / LttngTraceTest.java
CommitLineData
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
13import org.eclipse.linuxtools.lttng.event.LttngEvent;
14import org.eclipse.linuxtools.lttng.event.LttngLocation;
15import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
16import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace;
17import org.eclipse.linuxtools.lttng.trace.LTTngTrace;
18import org.eclipse.linuxtools.tmf.trace.TmfContext;
19import org.eclipse.linuxtools.tmf.trace.TmfTrace;
20
21
22public class LttngTraceTest {
23
24 /**
25 * @param args
26 */
27 public static void main(String[] args) {
28
29 // Path of the trace
30 final String TRACE_PATH = "/home/william/trace-614601events-nolost-newformat";
31
32 // *** Change to true to use the "fake" LttngTextTrace instead of LTTngTrace
33 // To use this, you need a ".txt" trace.
34 // You can get it using LTTv with the command "lttv -m textDump -t /tmp/sometrace > mytrace.txt"
35 final boolean USE_TEXT_TRACE = false;
36
37 // *** Change this to run several time over the same trace
38 final int NB_OF_PASS = 1;
39
40 // *** Change this to true to parse all the events in the trace
41 // Otherwise, events are just read
42 final boolean PARSE_EVENTS = true;
43
44
45 // Work variables
46 TmfTrace<LttngEvent> tmptrace = null;
47 LttngEvent tmpevent = null;
48 TmfContext tmpContext = null;
49 Long nbEvent = 0L;
50
51 try {
52 // ** Use TextTrace (slow!) if it was asked
53 if ( USE_TEXT_TRACE ) {
54 tmptrace = new LTTngTextTrace(TRACE_PATH, true);
55 } else {
56 tmptrace = new LTTngTrace(TRACE_PATH, true, true);
57 }
58
59 LttngTimestamp tmpTime = new LttngTimestamp(0L);
60 tmpContext = new TmfContext(new LttngLocation(0L), 0);
61
62 for ( int nb=0; nb<NB_OF_PASS; nb++) {
63
64 // Seek to the beginning of the trace
65 tmpContext = tmptrace.seekEvent( tmpTime );
66 tmpevent = (LttngEvent)tmptrace.getNextEvent(tmpContext);
67
68 while ( tmpevent != null ) {
69 tmpevent = (LttngEvent)tmptrace.getNextEvent(tmpContext);
70
71 // Parse the events if it was asked
72 if ( (tmpevent != null) && (PARSE_EVENTS) ) {
73 tmpevent.getContent().getFields();
74
75 // *** Uncomment the following to print the parsed content
76 // Warning : this is VERY intensive
77 //
78 //System.out.println(testEvent.toString());
79 //System.out.println(testEvent.getContent().toString());
80 }
81
82 nbEvent++;
83 }
84 }
85
86 System.out.println("NB events : " + nbEvent);
87
88 }
89 catch (Exception e) {
90 e.printStackTrace();
91 }
92
93 }
94
95}
This page took 0.028855 seconds and 5 git commands to generate.