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