Fix references to linuxtools in comments, examples and unused code
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / temp / headless / RequestBenchmark.java
CommitLineData
ce2388e0 1/*******************************************************************************
2c7fb5af 2 * Copyright (c) 2009, 2015 Ericsson
ce2388e0
FC
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
9722e5d7 14package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.headless;
ce2388e0
FC
15
16import java.util.Vector;
17
2bdf0193
AM
18import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
19import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
20import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
21import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
5c5fa260 22import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
9722e5d7
AM
23import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
24import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
ce2388e0 25
95bf10e7
AM
26/**
27 * Benchmark the event request subsystem of TMF.
28 */
6256d8ad 29public class RequestBenchmark extends TmfEventRequest {
ce2388e0 30
95bf10e7 31 private RequestBenchmark(final Class<? extends ITmfEvent> dataType,
25e48683 32 final TmfTimeRange range, final int nbRequested) {
672a642a 33 super(dataType, range, 0, nbRequested, ExecutionType.FOREGROUND);
ce2388e0
FC
34 }
35
36 // Path of the trace
2c7fb5af 37 private static final String TRACE_PATH = "../org.eclipse.tracecompass.ctf.core.tests/traces/kernel";
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;
ccf2bbb4 45 private static Vector<Double> benchs = new Vector<>();
95bf10e7
AM
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 */
4178260e
AM
61 fExperiment = new TmfExperiment(CtfTmfEvent.class, "Headless", traces,
62 TmfExperiment.DEFAULT_INDEX_PAGE_SIZE, null);
ce2388e0 63
95bf10e7
AM
64 /*
65 * We will issue a request for each "pass". TMF will then process
66 * them synchronously.
67 */
ce2388e0
FC
68 RequestBenchmark request = null;
69 for (int x = 0; x < NB_OF_PASS; x++) {
95bf10e7
AM
70 request = new RequestBenchmark(CtfTmfEvent.class,
71 TmfTimeRange.ETERNITY, Integer.MAX_VALUE);
ce2388e0 72 fExperiment.sendRequest(request);
ce2388e0
FC
73 }
74 prev = System.nanoTime();
25e48683 75 } catch (final NullPointerException e) {
95bf10e7
AM
76 /*
77 * Silently dismiss Null pointer exception The only way to "finish"
78 * the threads in TMF is by crashing them with null.
79 */
25e48683 80 } catch (final Exception e) {
ce2388e0
FC
81 e.printStackTrace();
82 }
83
84 }
85
86 @Override
5419a136
AM
87 public void handleData(final ITmfEvent event) {
88 super.handleData(event);
ce2388e0
FC
89 nbEvent++;
90
91 }
92
93 static long prev;
94 static long done = 0;
95 @Override
5419a136 96 public void handleCompleted() {
25e48683 97 final long next = System.nanoTime();
ce2388e0 98 double val = next - prev;
25e48683 99 final int nbEvent2 = nbEvent;
ce2388e0
FC
100 val /= nbEvent2;
101
102 nbEvent = 0;
103 prev = next;
104 benchs.add(val);
b0f9e44d 105 if (benchs.size() == NB_OF_PASS) {
ce2388e0 106 try {
cad06250 107 System.out.println("Nb events : " + nbEvent2);
ce2388e0 108
b0f9e44d 109 for (final double value : benchs) {
cad06250 110 System.out.print(value + ", ");
b0f9e44d 111 }
ce2388e0
FC
112 fExperiment.sendRequest(null);
113
25e48683 114 } catch (final Exception e) {
ce2388e0 115 }
b0f9e44d 116 }
ce2388e0
FC
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.06888 seconds and 5 git commands to generate.