Implement TmfTrace changes - introduce TmfTraceException
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core.tests / src / org / eclipse / linuxtools / lttng / core / tests / headless / LttngTraceTest.java
CommitLineData
6c13869b 1package 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
5945cec9
FC
14import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
15import org.eclipse.linuxtools.internal.lttng.core.event.LttngLocation;
16import org.eclipse.linuxtools.internal.lttng.core.event.LttngTimestamp;
17import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTextTrace;
18import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTrace;
3791b5df 19import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
6c13869b
FC
20import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
21import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
9cb4892d
WB
22
23
3b38ea61 24@SuppressWarnings("nls")
9cb4892d
WB
25public class LttngTraceTest {
26
25e48683
FC
27 /**
28 * @param args
29 */
30 public static void main(final String[] args) {
31
32 // Path of the trace
cb866e08 33 final String TRACE_PATH = "/home/francois/Desktop/Workspaces/LTTngTraces/trace_2GB";
9cb4892d 34 // *** Change to true to use the "fake" LttngTextTrace instead of LTTngTrace
25e48683
FC
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"
9cb4892d 37 final boolean USE_TEXT_TRACE = false;
25e48683 38
9cb4892d
WB
39 // *** Change this to run several time over the same trace
40 final int NB_OF_PASS = 1;
25e48683 41
9cb4892d
WB
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;
25e48683
FC
45
46
9cb4892d
WB
47 // Work variables
48 TmfTrace<LttngEvent> tmptrace = null;
49 LttngEvent tmpevent = null;
3791b5df 50 ITmfContext tmpContext = null;
9cb4892d 51 Long nbEvent = 0L;
25e48683
FC
52
53 try {
54 // ** Use TextTrace (slow!) if it was asked
55 if ( USE_TEXT_TRACE )
56 tmptrace = new LTTngTextTrace(null, TRACE_PATH, true);
57 else
58 tmptrace = new LTTngTrace(null, TRACE_PATH, null, true, true);
59
60 final LttngTimestamp tmpTime = new LttngTimestamp(0L);
9cb4892d 61 tmpContext = new TmfContext(new LttngLocation(0L), 0);
cb866e08 62
25e48683
FC
63
64 final long startTime = System.nanoTime();
cb866e08
FC
65 System.out.println("Start: " + startTime);
66 for ( int nb=0; nb<NB_OF_PASS; nb++) {
25e48683
FC
67
68 // Seek to the beginning of the trace
69 tmpContext = tmptrace.seekEvent( tmpTime );
b4f71e4a 70 tmpevent = (LttngEvent)tmptrace.readNextEvent(tmpContext);
25e48683
FC
71
72 while ( tmpevent != null ) {
b4f71e4a 73 tmpevent = (LttngEvent)tmptrace.readNextEvent(tmpContext);
25e48683
FC
74
75 // Parse the events if it was asked
76 if ( (tmpevent != null) && (PARSE_EVENTS) )
77 tmpevent.getContent().getFields();
78
79 nbEvent++;
80 }
81 }
82
83 System.out.println("NB events : " + nbEvent);
84
85 final long endTime = System.nanoTime();
86 final long elapsed = endTime - startTime;
87 System.out.println("End: " + endTime);
88 System.out.println("Elapsed: " + elapsed + ", Average: " + (elapsed/nbEvent) + "ns/evt");
89
90 }
91 catch (final Exception e) {
92 e.printStackTrace();
93 }
94
95 }
9cb4892d
WB
96
97}
This page took 0.033148 seconds and 5 git commands to generate.