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