ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ctf.core.tests / src / org / eclipse / linuxtools / tmf / ctf / core / tests / headless / RequestBenchmark.java
CommitLineData
ce2388e0 1/*******************************************************************************
61759503 2 * Copyright (c) 2009, 2013 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
91e7f946 14package org.eclipse.linuxtools.tmf.ctf.core.tests.headless;
ce2388e0
FC
15
16import java.util.Vector;
17
ce2388e0 18import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
ce2388e0 19import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
3bd46eef 20import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
ce2388e0 21import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
9e0640dc 22import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
91e7f946
AM
23import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent;
24import org.eclipse.linuxtools.tmf.ctf.core.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
cad06250 37 private static final String TRACE_PATH = "../org.eclipse.linuxtools.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 */
cad06250 61 fExperiment = new TmfExperiment(CtfTmfEvent.class, "Headless", traces);
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 {
cad06250 106 System.out.println("Nb events : " + nbEvent2);
ce2388e0 107
b0f9e44d 108 for (final double value : benchs) {
cad06250 109 System.out.print(value + ", ");
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}
This page took 0.062562 seconds and 5 git commands to generate.