1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.temp
.headless
;
15 import java
.util
.Vector
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
18 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.context
.CtfTmfContext
;
19 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
20 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
23 * Test and benchmark reading a CTF LTTng kernel trace.
25 * @author Matthew Khouzam
27 public class Benchmark
{
32 * @param args The command-line arguments
34 public static void main(final String
[] args
) {
35 final String TRACE_PATH
= "testfiles/kernel";
36 final int NUM_LOOPS
= 100;
38 // Change this to enable text output
39 final boolean USE_TEXT
= true;
43 final Vector
<Double
> benchs
= new Vector
<>();
45 for (int loops
= 0; loops
< NUM_LOOPS
; loops
++) {
47 try (CtfTmfTrace trace
= new CtfTmfTrace();) {
49 trace
.initTrace(null, TRACE_PATH
, CtfTmfEvent
.class);
50 } catch (final TmfTraceException e
) {
51 loops
= NUM_LOOPS
+ 1;
55 start
= System
.nanoTime();
57 final CtfTmfContext traceReader
= (CtfTmfContext
) trace
.seekEvent(0);
59 start
= System
.nanoTime();
60 CtfTmfEvent current
= traceReader
.getCurrentEvent();
61 while (current
!= null) {
65 System
.out
.println("Event " + nbEvent
+ " Time "
66 + current
.getTimestamp().toString() + " type " + current
.getType().getName()
67 + " on CPU " + current
.getCPU() + " " + current
.getContent().toString());
69 // advance the trace to the next event.
70 boolean hasMore
= traceReader
.advance();
72 // you can know the trace has more events.
74 current
= traceReader
.getCurrentEvent();
77 stop
= System
.nanoTime();
78 System
.out
.print('.');
79 final double time
= (stop
- start
) / (double) nbEvent
;
83 System
.out
.println("");
85 for (final double val
: benchs
) {
89 System
.out
.println("Time to read = " + avg
+ " events/ns");
90 for (final Double val
: benchs
) {
91 System
.out
.print(val
);
92 System
.out
.print(", ");