1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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 * Matthew Khouzam - Update to CtfTmf trace and events
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.temp
.headless
;
16 import java
.util
.Vector
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfExperiment
;
23 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
24 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
27 * Benchmark the event request subsystem of TMF.
29 public class RequestBenchmark
extends TmfEventRequest
{
31 private RequestBenchmark(final Class
<?
extends ITmfEvent
> dataType
,
32 final TmfTimeRange range
, final int nbRequested
) {
33 super(dataType
, range
, 0, nbRequested
, ExecutionType
.FOREGROUND
);
37 private static final String TRACE_PATH
= "../org.eclipse.linuxtools.ctf.core.tests/traces/kernel";
39 // Change this to run several time over the same trace
40 private static final int NB_OF_PASS
= 100;
43 private static int nbEvent
= 0;
44 private static TmfExperiment fExperiment
= null;
45 private static Vector
<Double
> benchs
= new Vector
<>();
51 * The command-line arguments
53 public static void main(final String
[] args
) {
56 /* Our experiment will contains ONE trace */
57 final ITmfTrace
[] traces
= new ITmfTrace
[1];
58 traces
[0] = new CtfTmfTrace();
59 traces
[0].initTrace(null, TRACE_PATH
, CtfTmfEvent
.class);
60 /* Create our new experiment */
61 fExperiment
= new TmfExperiment(CtfTmfEvent
.class, "Headless", traces
,
62 TmfExperiment
.DEFAULT_INDEX_PAGE_SIZE
, null);
65 * We will issue a request for each "pass". TMF will then process
68 RequestBenchmark request
= null;
69 for (int x
= 0; x
< NB_OF_PASS
; x
++) {
70 request
= new RequestBenchmark(CtfTmfEvent
.class,
71 TmfTimeRange
.ETERNITY
, Integer
.MAX_VALUE
);
72 fExperiment
.sendRequest(request
);
74 prev
= System
.nanoTime();
75 } catch (final NullPointerException e
) {
77 * Silently dismiss Null pointer exception The only way to "finish"
78 * the threads in TMF is by crashing them with null.
80 } catch (final Exception e
) {
87 public void handleData(final ITmfEvent event
) {
88 super.handleData(event
);
96 public void handleCompleted() {
97 final long next
= System
.nanoTime();
98 double val
= next
- prev
;
99 final int nbEvent2
= nbEvent
;
105 if (benchs
.size() == NB_OF_PASS
) {
107 System
.out
.println("Nb events : " + nbEvent2
);
109 for (final double value
: benchs
) {
110 System
.out
.print(value
+ ", ");
112 fExperiment
.sendRequest(null);
114 } catch (final Exception e
) {
120 public void handleSuccess() {
124 public void handleFailure() {
128 public void handleCancel() {