Commit | Line | Data |
---|---|---|
ce2388e0 FC |
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 | package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.headless; | |
13 | ||
14 | import java.util.Vector; | |
15 | ||
16 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; | |
17 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp; | |
18 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; | |
19 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; | |
20 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; | |
21 | import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment; | |
22 | import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; | |
23 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
24 | ||
25 | @SuppressWarnings("nls") | |
26 | public class RequestBenchmark extends TmfEventRequest<CtfTmfEvent> { | |
27 | ||
28 | @SuppressWarnings("unchecked") | |
29 | public RequestBenchmark(Class<? extends ITmfEvent> dataType, | |
30 | TmfTimeRange range, int nbRequested) { | |
31 | super((Class<CtfTmfEvent>) dataType, range, nbRequested, 1); | |
32 | } | |
33 | ||
34 | // Path of the trace | |
35 | public static final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/Tests/traces/trace20m1"; | |
36 | ||
37 | // *** Change this to run several time over the same trace | |
38 | public static final int NB_OF_PASS = 100; | |
39 | ||
40 | // *** Change this to true to parse all the events in the trace | |
41 | // Otherwise, events are just read | |
42 | public final boolean PARSE_EVENTS = true; | |
43 | ||
44 | // Work variables | |
45 | public static int nbEvent = 0; | |
46 | public static int nbPassDone = 0; | |
47 | public static TmfExperiment<CtfTmfEvent> fExperiment = null; | |
48 | public static Vector<Double> benchs = new Vector<Double>(); | |
49 | ||
50 | public static void main(String[] args) { | |
51 | ||
52 | try { | |
53 | // OUr experiment will contains ONE trace | |
54 | @SuppressWarnings("unchecked") | |
55 | ITmfTrace<CtfTmfEvent>[] traces = new ITmfTrace[1]; | |
56 | traces[0] = new CtfTmfTrace(); | |
57 | traces[0].initTrace("CtfTrace", TRACE_PATH, CtfTmfEvent.class); | |
58 | // Create our new experiment | |
59 | fExperiment = new TmfExperiment<CtfTmfEvent>(CtfTmfEvent.class, | |
60 | "Headless", traces); | |
61 | ||
62 | // Create a new time range from -infinity to +infinity | |
63 | // That way, we will get "everything" in the trace | |
64 | CtfTmfTimestamp ts1 = new CtfTmfTimestamp(Long.MIN_VALUE, | |
65 | (CtfTmfTrace) traces[0]); | |
66 | CtfTmfTimestamp ts2 = new CtfTmfTimestamp(Long.MAX_VALUE, | |
67 | (CtfTmfTrace) traces[0]); | |
68 | TmfTimeRange tmpRange = new TmfTimeRange(ts1, ts2); | |
69 | ||
70 | // We will issue a request for each "pass". | |
71 | // TMF will then process them synchonously | |
72 | RequestBenchmark request = null; | |
73 | for (int x = 0; x < NB_OF_PASS; x++) { | |
74 | request = new RequestBenchmark(CtfTmfEvent.class, tmpRange, | |
75 | Integer.MAX_VALUE); | |
76 | fExperiment.sendRequest(request); | |
77 | nbPassDone++; | |
78 | } | |
79 | prev = System.nanoTime(); | |
80 | } catch (NullPointerException e) { | |
81 | // Silently dismiss Null pointer exception | |
82 | // The only way to "finish" the threads in TMF is by crashing them | |
83 | // with null | |
84 | } catch (Exception e) { | |
85 | e.printStackTrace(); | |
86 | } | |
87 | ||
88 | } | |
89 | ||
90 | @Override | |
91 | public void handleData(CtfTmfEvent event) { | |
92 | super.handleData(event); | |
93 | nbEvent++; | |
94 | ||
95 | } | |
96 | ||
97 | static long prev; | |
98 | static long done = 0; | |
99 | @Override | |
100 | public void handleCompleted() { | |
101 | long next = System.nanoTime(); | |
102 | double val = next - prev; | |
103 | int nbEvent2 = nbEvent; | |
104 | val /= nbEvent2; | |
105 | ||
106 | nbEvent = 0; | |
107 | prev = next; | |
108 | benchs.add(val); | |
109 | if (benchs.size() == NB_OF_PASS) { | |
110 | try { | |
111 | System.out.println("Nb events : " + nbEvent2); | |
112 | ||
113 | for (double value : benchs) { | |
114 | System.out.print(value + ", "); | |
115 | } | |
116 | fExperiment.sendRequest(null); | |
117 | ||
118 | } catch (Exception e) { | |
119 | } | |
120 | } | |
121 | } | |
122 | ||
123 | @Override | |
124 | public void handleSuccess() { | |
125 | } | |
126 | ||
127 | @Override | |
128 | public void handleFailure() { | |
129 | } | |
130 | ||
131 | @Override | |
132 | public void handleCancel() { | |
133 | } | |
134 | ||
135 | } |