2010-06-05 fchouinard@gmail.com Contributions for bugs 292965, 292963, 293102,...
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.headless / src / LttngTraceTest.java
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 org.eclipse.linuxtools.lttng.event.LttngEvent;
14 import org.eclipse.linuxtools.lttng.event.LttngLocation;
15 import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
16 import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace;
17 import org.eclipse.linuxtools.lttng.trace.LTTngTrace;
18 import org.eclipse.linuxtools.tmf.trace.TmfContext;
19 import org.eclipse.linuxtools.tmf.trace.TmfTrace;
20
21
22 public 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/francois/Desktop/Workspaces/LTTngTraces/trace_2GB";
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
63 long startTime = System.nanoTime();
64 System.out.println("Start: " + startTime);
65 for ( int nb=0; nb<NB_OF_PASS; nb++) {
66
67 // Seek to the beginning of the trace
68 tmpContext = tmptrace.seekEvent( tmpTime );
69 tmpevent = (LttngEvent)tmptrace.getNextEvent(tmpContext);
70
71 while ( tmpevent != null ) {
72 tmpevent = (LttngEvent)tmptrace.getNextEvent(tmpContext);
73
74 // Parse the events if it was asked
75 if ( (tmpevent != null) && (PARSE_EVENTS) ) {
76 tmpevent.getContent().getFields();
77
78 // *** Uncomment the following to print the parsed content
79 // Warning : this is VERY intensive
80 //
81 // System.out.println(tmpevent.toString());
82 //System.out.println(testEvent.getContent().toString());
83 }
84
85 nbEvent++;
86 }
87 }
88
89 System.out.println("NB events : " + nbEvent);
90
91 long endTime = System.nanoTime();
92 long elapsed = endTime - startTime;
93 System.out.println("End: " + endTime);
94 System.out.println("Elapsed: " + elapsed + ", Average: " + (elapsed/nbEvent) + "ns/evt");
95
96 }
97 catch (Exception e) {
98 e.printStackTrace();
99 }
100
101 }
102
103 }
This page took 0.032945 seconds and 5 git commands to generate.