1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * William Bourque (wbourque@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.ctfadaptor
.headless
;
14 import java
.util
.Vector
;
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
;
25 @SuppressWarnings("nls")
26 public class RequestBenchmark
extends TmfEventRequest
<CtfTmfEvent
> {
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);
35 public static final String TRACE_PATH
= "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel";
37 // *** Change this to run several time over the same trace
38 public static final int NB_OF_PASS
= 100;
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;
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
>();
50 public static void main(final String
[] args
) {
53 // OUr experiment will contains ONE trace
54 @SuppressWarnings("unchecked")
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
);
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
);
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
,
74 fExperiment
.sendRequest(request
);
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
82 } catch (final Exception e
) {
89 public void handleData(final CtfTmfEvent event
) {
90 super.handleData(event
);
98 public void handleCompleted() {
99 final long next
= System
.nanoTime();
100 double val
= next
- prev
;
101 final int nbEvent2
= nbEvent
;
107 if (benchs
.size() == NB_OF_PASS
) {
109 System
.out
.println("Nb events : " + nbEvent2
);
111 for (final double value
: benchs
) {
112 System
.out
.print(value
+ ", ");
114 fExperiment
.sendRequest(null);
116 } catch (final Exception e
) {
122 public void handleSuccess() {
126 public void handleFailure() {
130 public void handleCancel() {
This page took 0.032601 seconds and 5 git commands to generate.