First set of standalone LTTng "applications". Useful for debug
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.headless / src / TmfTraceTest.java
CommitLineData
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
13import org.eclipse.linuxtools.lttng.event.LttngEvent;
14import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
15import org.eclipse.linuxtools.lttng.trace.LTTngTrace;
16import org.eclipse.linuxtools.tmf.event.TmfEvent;
17import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
18import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
19import org.eclipse.linuxtools.tmf.request.TmfEventRequest;
20import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
21
22public 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
83
84 @Override
85 public void handleData() {
86 TmfEvent[] result = getData();
87 TmfEvent[] evt = new TmfEvent[1];
88
89 evt[0] = (result.length > 0) ? result[0] : null;
90
91 if ( (evt[0] != null) && (PARSE_EVENTS) ) {
92 ((LttngEvent)evt[0]).getContent().getFields();
93
94 // *** Uncomment the following to print the parsed content
95 // Warning : this is VERY intensive
96 //
97 //System.out.println((LttngEvent)evt[0]);
98 //System.out.println(((LttngEvent)evt[0]).getContent());
99
100 nbEvent++;
101 }
102 }
103
104 @Override
105 public void handleCompleted() {
106 if ( nbPassDone >= NB_OF_PASS ) {
107 try {
108 System.out.println("Nb events : " + nbEvent);
109
110 fExperiment.sendRequest(null);
111 }
112 catch (Exception e) {}
113 }
114 }
115
116 @Override
117 public void handleSuccess() {
118 }
119
120 @Override
121 public void handleFailure() {
122 }
123
124 @Override
125 public void handleCancel() {
126 }
127
128}
This page took 0.027751 seconds and 5 git commands to generate.