Commit | Line | Data |
---|---|---|
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 | ||
13 | import org.eclipse.linuxtools.lttng.event.LttngEvent; | |
14 | import org.eclipse.linuxtools.lttng.event.LttngTimestamp; | |
15 | import org.eclipse.linuxtools.lttng.trace.LTTngTrace; | |
16 | import org.eclipse.linuxtools.tmf.event.TmfEvent; | |
17 | import org.eclipse.linuxtools.tmf.event.TmfTimeRange; | |
18 | import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; | |
19 | import org.eclipse.linuxtools.tmf.request.TmfEventRequest; | |
20 | import org.eclipse.linuxtools.tmf.trace.ITmfTrace; | |
21 | ||
3b38ea61 | 22 | @SuppressWarnings("nls") |
9cb4892d WB |
23 | public class TmfTraceTest extends TmfEventRequest<LttngEvent> { |
24 | ||
25 | @SuppressWarnings("unchecked") | |
26 | public TmfTraceTest(Class<? extends TmfEvent> dataType, TmfTimeRange range, int nbRequested) { | |
27 | super((Class<LttngEvent>)dataType, range, nbRequested, 1); | |
28 | } | |
29 | ||
30 | ||
31 | // Path of the trace | |
32 | public static final String TRACE_PATH = "/home/william/trace-614601events-nolost-newformat"; | |
33 | ||
34 | // *** Change this to run several time over the same trace | |
35 | public static final int NB_OF_PASS = 1; | |
36 | ||
37 | // *** Change this to true to parse all the events in the trace | |
38 | // Otherwise, events are just read | |
39 | public final boolean PARSE_EVENTS = true; | |
40 | ||
41 | ||
42 | // Work variables | |
43 | public static int nbEvent = 0; | |
44 | public static int nbPassDone = 0; | |
45 | public static TmfExperiment<LttngEvent> fExperiment = null; | |
46 | ||
47 | ||
48 | public static void main(String[] args) { | |
49 | ||
50 | try { | |
51 | // OUr experiment will contains ONE trace | |
52 | ITmfTrace[] traces = new ITmfTrace[1]; | |
53 | traces[0] = new LTTngTrace(TRACE_PATH); | |
54 | // Create our new experiment | |
55 | fExperiment = new TmfExperiment<LttngEvent>(LttngEvent.class, "Headless", traces); | |
56 | ||
57 | ||
58 | // Create a new time range from -infinity to +infinity | |
59 | // That way, we will get "everything" in the trace | |
60 | LttngTimestamp ts1 = new LttngTimestamp(Long.MIN_VALUE); | |
61 | LttngTimestamp ts2 = new LttngTimestamp(Long.MAX_VALUE); | |
62 | TmfTimeRange tmpRange = new TmfTimeRange(ts1, ts2); | |
63 | ||
64 | ||
65 | // We will issue a request for each "pass". | |
66 | // TMF will then process them synchonously | |
67 | TmfTraceTest request = null; | |
68 | for ( int x=0; x<NB_OF_PASS; x++ ) { | |
69 | request = new TmfTraceTest(LttngEvent.class, tmpRange, Integer.MAX_VALUE ); | |
70 | fExperiment.sendRequest(request); | |
71 | nbPassDone++; | |
72 | } | |
73 | } | |
74 | catch (NullPointerException e) { | |
75 | // Silently dismiss Null pointer exception | |
76 | // The only way to "finish" the threads in TMF is by crashing them with null | |
77 | } | |
78 | catch (Exception e) { | |
79 | e.printStackTrace(); | |
80 | } | |
81 | ||
82 | } | |
83 | ||
9cb4892d | 84 | @Override |
f9673903 FC |
85 | public void handleData(LttngEvent event) { |
86 | super.handleData(event); | |
87 | if ( (event != null) && (PARSE_EVENTS) ) { | |
88 | ((LttngEvent) event).getContent().getFields(); | |
9cb4892d WB |
89 | |
90 | // *** Uncomment the following to print the parsed content | |
91 | // Warning : this is VERY intensive | |
92 | // | |
93 | //System.out.println((LttngEvent)evt[0]); | |
94 | //System.out.println(((LttngEvent)evt[0]).getContent()); | |
95 | ||
96 | nbEvent++; | |
97 | } | |
98 | } | |
99 | ||
100 | @Override | |
101 | public void handleCompleted() { | |
102 | if ( nbPassDone >= NB_OF_PASS ) { | |
103 | try { | |
104 | System.out.println("Nb events : " + nbEvent); | |
105 | ||
106 | fExperiment.sendRequest(null); | |
107 | } | |
108 | catch (Exception e) {} | |
109 | } | |
110 | } | |
111 | ||
112 | @Override | |
113 | public void handleSuccess() { | |
114 | } | |
115 | ||
116 | @Override | |
117 | public void handleFailure() { | |
118 | } | |
119 | ||
120 | @Override | |
121 | public void handleCancel() { | |
122 | } | |
123 | ||
124 | } |