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