588f97d676c8c65dc6331cc78060b7743f22bd6e
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / temp / headless / RequestBenchmark.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2015 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.tracecompass.tmf.ctf.core.tests.temp.headless;
15
16 import java.util.Vector;
17
18 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
19 import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
20 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
21 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
22 import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
23 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
24 import org.eclipse.tracecompass.tmf.ctf.core.trace.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.tracecompass.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 TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null);
63
64 /*
65 * We will issue a request for each "pass". TMF will then process
66 * them synchronously.
67 */
68 RequestBenchmark request = null;
69 for (int x = 0; x < NB_OF_PASS; x++) {
70 request = new RequestBenchmark(CtfTmfEvent.class,
71 TmfTimeRange.ETERNITY, Integer.MAX_VALUE);
72 fExperiment.sendRequest(request);
73 }
74 prev = System.nanoTime();
75 } catch (final NullPointerException e) {
76 /*
77 * Silently dismiss Null pointer exception The only way to "finish"
78 * the threads in TMF is by crashing them with null.
79 */
80 } catch (final Exception e) {
81 e.printStackTrace();
82 }
83
84 }
85
86 @Override
87 public void handleData(final ITmfEvent event) {
88 super.handleData(event);
89 nbEvent++;
90
91 }
92
93 static long prev;
94 static long done = 0;
95 @Override
96 public void handleCompleted() {
97 final long next = System.nanoTime();
98 double val = next - prev;
99 final int nbEvent2 = nbEvent;
100 val /= nbEvent2;
101
102 nbEvent = 0;
103 prev = next;
104 benchs.add(val);
105 if (benchs.size() == NB_OF_PASS) {
106 try {
107 System.out.println("Nb events : " + nbEvent2);
108
109 for (final double value : benchs) {
110 System.out.print(value + ", ");
111 }
112 fExperiment.sendRequest(null);
113
114 } catch (final Exception e) {
115 }
116 }
117 }
118
119 @Override
120 public void handleSuccess() {
121 }
122
123 @Override
124 public void handleFailure() {
125 }
126
127 @Override
128 public void handleCancel() {
129 }
130
131 }
This page took 0.051191 seconds and 4 git commands to generate.