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