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