2010-06-05 fchouinard@gmail.com Contributions for bugs 292965, 292963, 293102,...
[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() {
cb866e08 86 LttngEvent[] result = getData();
9cb4892d 87
cb866e08 88 LttngEvent evt = (result.length > 0) ? result[0] : null;
9cb4892d 89
cb866e08
FC
90 if ( (evt != null) && (PARSE_EVENTS) ) {
91 ((LttngEvent) evt).getContent().getFields();
9cb4892d
WB
92
93 // *** Uncomment the following to print the parsed content
94 // Warning : this is VERY intensive
95 //
96 //System.out.println((LttngEvent)evt[0]);
97 //System.out.println(((LttngEvent)evt[0]).getContent());
98
99 nbEvent++;
100 }
101 }
102
103 @Override
104 public void handleCompleted() {
105 if ( nbPassDone >= NB_OF_PASS ) {
106 try {
107 System.out.println("Nb events : " + nbEvent);
108
109 fExperiment.sendRequest(null);
110 }
111 catch (Exception e) {}
112 }
113 }
114
115 @Override
116 public void handleSuccess() {
117 }
118
119 @Override
120 public void handleFailure() {
121 }
122
123 @Override
124 public void handleCancel() {
125 }
126
127}
This page took 0.028125 seconds and 5 git commands to generate.