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