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