Improve CTF timestamp output, will now output in y/m/d, h:m:s.ns or ns or s (double)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / src / org / eclipse / linuxtools / tmf / core / tests / ctfadaptor / headless / RequestBenchmark.java
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:
10 * William Bourque (wbourque@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.headless;
13
14 import java.util.Vector;
15
16 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
17 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp;
18 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
19 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
20 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
21 import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment;
22 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
23 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
24
25 @SuppressWarnings("nls")
26 public class RequestBenchmark extends TmfEventRequest<CtfTmfEvent> {
27
28 @SuppressWarnings("unchecked")
29 public RequestBenchmark(final Class<? extends ITmfEvent> dataType,
30 final TmfTimeRange range, final int nbRequested) {
31 super((Class<CtfTmfEvent>) dataType, range, nbRequested, 1);
32 }
33
34 // Path of the trace
35 public static final String TRACE_PATH = "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel";
36
37 // *** Change this to run several time over the same trace
38 public static final int NB_OF_PASS = 100;
39
40 // *** Change this to true to parse all the events in the trace
41 // Otherwise, events are just read
42 public final boolean PARSE_EVENTS = true;
43
44 // Work variables
45 public static int nbEvent = 0;
46 public static int nbPassDone = 0;
47 public static TmfExperiment<CtfTmfEvent> fExperiment = null;
48 public static Vector<Double> benchs = new Vector<Double>();
49
50 public static void main(final String[] args) {
51
52 try {
53 // OUr experiment will contains ONE trace
54 @SuppressWarnings("unchecked")
55 final
56 ITmfTrace<CtfTmfEvent>[] traces = new ITmfTrace[1];
57 traces[0] = new CtfTmfTrace();
58 traces[0].initTrace(null, TRACE_PATH, CtfTmfEvent.class);
59 // Create our new experiment
60 fExperiment = new TmfExperiment<CtfTmfEvent>(CtfTmfEvent.class, "Headless", traces);
61
62 // Create a new time range from -infinity to +infinity
63 // That way, we will get "everything" in the trace
64 final CtfTmfTimestamp ts1 = new CtfTmfTimestamp(Long.MIN_VALUE);
65 final CtfTmfTimestamp ts2 = new CtfTmfTimestamp(Long.MAX_VALUE);
66 final TmfTimeRange tmpRange = new TmfTimeRange(ts1, ts2);
67
68 // We will issue a request for each "pass".
69 // TMF will then process them synchonously
70 RequestBenchmark request = null;
71 for (int x = 0; x < NB_OF_PASS; x++) {
72 request = new RequestBenchmark(CtfTmfEvent.class, tmpRange,
73 Integer.MAX_VALUE);
74 fExperiment.sendRequest(request);
75 nbPassDone++;
76 }
77 prev = System.nanoTime();
78 } catch (final NullPointerException e) {
79 // Silently dismiss Null pointer exception
80 // The only way to "finish" the threads in TMF is by crashing them
81 // with null
82 } catch (final Exception e) {
83 e.printStackTrace();
84 }
85
86 }
87
88 @Override
89 public void handleData(final CtfTmfEvent event) {
90 super.handleData(event);
91 nbEvent++;
92
93 }
94
95 static long prev;
96 static long done = 0;
97 @Override
98 public void handleCompleted() {
99 final long next = System.nanoTime();
100 double val = next - prev;
101 final int nbEvent2 = nbEvent;
102 val /= nbEvent2;
103
104 nbEvent = 0;
105 prev = next;
106 benchs.add(val);
107 if (benchs.size() == NB_OF_PASS) {
108 try {
109 System.out.println("Nb events : " + nbEvent2);
110
111 for (final double value : benchs) {
112 System.out.print(value + ", ");
113 }
114 fExperiment.sendRequest(null);
115
116 } catch (final Exception e) {
117 }
118 }
119 }
120
121 @Override
122 public void handleSuccess() {
123 }
124
125 @Override
126 public void handleFailure() {
127 }
128
129 @Override
130 public void handleCancel() {
131 }
132
133 }
This page took 0.032601 seconds and 5 git commands to generate.