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