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: | |
95bf10e7 AM |
10 | * William Bourque <wbourque@gmail.com> - Initial API and implementation |
11 | * Matthew Khouzam - Update to CtfTmf trace and events | |
ce2388e0 | 12 | *******************************************************************************/ |
95bf10e7 | 13 | |
ce2388e0 FC |
14 | package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.headless; |
15 | ||
16 | import java.util.Vector; | |
17 | ||
18 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; | |
ce2388e0 FC |
19 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; |
20 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; | |
ce2388e0 | 21 | import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; |
3bd46eef | 22 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; |
ce2388e0 | 23 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
9e0640dc | 24 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; |
ce2388e0 | 25 | |
95bf10e7 AM |
26 | /** |
27 | * Benchmark the event request subsystem of TMF. | |
28 | */ | |
6256d8ad | 29 | public class RequestBenchmark extends TmfEventRequest { |
ce2388e0 | 30 | |
95bf10e7 | 31 | private RequestBenchmark(final Class<? extends ITmfEvent> dataType, |
25e48683 | 32 | final TmfTimeRange range, final int nbRequested) { |
6256d8ad | 33 | super(dataType, range, nbRequested, 1); |
ce2388e0 FC |
34 | } |
35 | ||
36 | // Path of the trace | |
95bf10e7 | 37 | private static final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel"; //$NON-NLS-1$ |
ce2388e0 | 38 | |
95bf10e7 AM |
39 | // Change this to run several time over the same trace |
40 | private static final int NB_OF_PASS = 100; | |
ce2388e0 FC |
41 | |
42 | // Work variables | |
95bf10e7 | 43 | private static int nbEvent = 0; |
6256d8ad | 44 | private static TmfExperiment fExperiment = null; |
95bf10e7 AM |
45 | private static Vector<Double> benchs = new Vector<Double>(); |
46 | ||
47 | /** | |
48 | * Run the benchmark | |
49 | * | |
50 | * @param args | |
51 | * The command-line arguments | |
52 | */ | |
25e48683 | 53 | public static void main(final String[] args) { |
ce2388e0 FC |
54 | |
55 | try { | |
95bf10e7 | 56 | /* Our experiment will contains ONE trace */ |
6256d8ad | 57 | final ITmfTrace[] traces = new ITmfTrace[1]; |
ce2388e0 | 58 | traces[0] = new CtfTmfTrace(); |
25e48683 | 59 | traces[0].initTrace(null, TRACE_PATH, CtfTmfEvent.class); |
95bf10e7 | 60 | /* Create our new experiment */ |
6256d8ad | 61 | fExperiment = new TmfExperiment(CtfTmfEvent.class, "Headless", traces); //$NON-NLS-1$ |
ce2388e0 | 62 | |
95bf10e7 AM |
63 | /* |
64 | * We will issue a request for each "pass". TMF will then process | |
65 | * them synchronously. | |
66 | */ | |
ce2388e0 FC |
67 | RequestBenchmark request = null; |
68 | for (int x = 0; x < NB_OF_PASS; x++) { | |
95bf10e7 AM |
69 | request = new RequestBenchmark(CtfTmfEvent.class, |
70 | TmfTimeRange.ETERNITY, Integer.MAX_VALUE); | |
ce2388e0 | 71 | fExperiment.sendRequest(request); |
ce2388e0 FC |
72 | } |
73 | prev = System.nanoTime(); | |
25e48683 | 74 | } catch (final NullPointerException e) { |
95bf10e7 AM |
75 | /* |
76 | * Silently dismiss Null pointer exception The only way to "finish" | |
77 | * the threads in TMF is by crashing them with null. | |
78 | */ | |
25e48683 | 79 | } catch (final Exception e) { |
ce2388e0 FC |
80 | e.printStackTrace(); |
81 | } | |
82 | ||
83 | } | |
84 | ||
85 | @Override | |
5419a136 AM |
86 | public void handleData(final ITmfEvent event) { |
87 | super.handleData(event); | |
ce2388e0 FC |
88 | nbEvent++; |
89 | ||
90 | } | |
91 | ||
92 | static long prev; | |
93 | static long done = 0; | |
94 | @Override | |
5419a136 | 95 | public void handleCompleted() { |
25e48683 | 96 | final long next = System.nanoTime(); |
ce2388e0 | 97 | double val = next - prev; |
25e48683 | 98 | final int nbEvent2 = nbEvent; |
ce2388e0 FC |
99 | val /= nbEvent2; |
100 | ||
101 | nbEvent = 0; | |
102 | prev = next; | |
103 | benchs.add(val); | |
b0f9e44d | 104 | if (benchs.size() == NB_OF_PASS) { |
ce2388e0 | 105 | try { |
95bf10e7 | 106 | System.out.println("Nb events : " + nbEvent2); //$NON-NLS-1$ |
ce2388e0 | 107 | |
b0f9e44d | 108 | for (final double value : benchs) { |
95bf10e7 | 109 | System.out.print(value + ", "); //$NON-NLS-1$ |
b0f9e44d | 110 | } |
ce2388e0 FC |
111 | fExperiment.sendRequest(null); |
112 | ||
25e48683 | 113 | } catch (final Exception e) { |
ce2388e0 | 114 | } |
b0f9e44d | 115 | } |
ce2388e0 FC |
116 | } |
117 | ||
118 | @Override | |
119 | public void handleSuccess() { | |
120 | } | |
121 | ||
122 | @Override | |
123 | public void handleFailure() { | |
124 | } | |
125 | ||
126 | @Override | |
127 | public void handleCancel() { | |
128 | } | |
129 | ||
130 | } |