rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ctf.core.tests / src / org / eclipse / tracecompass / tmf / ctf / core / tests / temp / headless / Benchmark.java
CommitLineData
ce2388e0 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2012, 2014 Ericsson
ce2388e0
FC
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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
95bf10e7 12
9722e5d7 13package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.headless;
ce2388e0 14
ce2388e0
FC
15import java.util.Vector;
16
2bdf0193 17import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
9722e5d7
AM
18import org.eclipse.tracecompass.tmf.ctf.core.context.CtfTmfContext;
19import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
20import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
ce2388e0 21
95bf10e7
AM
22/**
23 * Test and benchmark reading a CTF LTTng kernel trace.
24 *
25 * @author Matthew Khouzam
26 */
ce2388e0
FC
27public class Benchmark {
28
29 /**
95bf10e7
AM
30 * Run the benchmark.
31 *
32 * @param args The command-line arguments
ce2388e0 33 */
25e48683 34 public static void main(final String[] args) {
cad06250 35 final String TRACE_PATH = "testfiles/kernel";
ce2388e0
FC
36 final int NUM_LOOPS = 100;
37
38 // Change this to enable text output
aa572e22 39 final boolean USE_TEXT = true;
ce2388e0 40
ce2388e0 41 // Work variables
0126a8ca 42 long nbEvent = 0L;
ccf2bbb4 43 final Vector<Double> benchs = new Vector<>();
ce2388e0
FC
44 long start, stop;
45 for (int loops = 0; loops < NUM_LOOPS; loops++) {
46 nbEvent = 0L;
090c006e
AM
47 try (CtfTmfTrace trace = new CtfTmfTrace();) {
48 try {
49 trace.initTrace(null, TRACE_PATH, CtfTmfEvent.class);
50 } catch (final TmfTraceException e) {
51 loops = NUM_LOOPS + 1;
52 break;
53 }
ce2388e0
FC
54
55 start = System.nanoTime();
090c006e
AM
56 if (nbEvent != -1) {
57 final CtfTmfContext traceReader = (CtfTmfContext) trace.seekEvent(0);
aa572e22 58
090c006e
AM
59 start = System.nanoTime();
60 CtfTmfEvent current = traceReader.getCurrentEvent();
61 while (current != null) {
62 nbEvent++;
63 if (USE_TEXT) {
64
65 System.out.println("Event " + nbEvent + " Time "
66 + current.getTimestamp().toString() + " type " + current.getType().getName()
f9ff7d40 67 + " on CPU " + current.getCPU() + " " + current.getContent().toString());
090c006e
AM
68 }
69 // advance the trace to the next event.
70 boolean hasMore = traceReader.advance();
71 if (hasMore) {
72 // you can know the trace has more events.
73 }
74 current = traceReader.getCurrentEvent();
156a3e3a 75 }
ce2388e0 76 }
090c006e
AM
77 stop = System.nanoTime();
78 System.out.print('.');
79 final double time = (stop - start) / (double) nbEvent;
80 benchs.add(time);
81 } // trace.close()
ce2388e0 82 }
cad06250 83 System.out.println("");
ce2388e0 84 double avg = 0;
0126a8ca 85 for (final double val : benchs) {
ce2388e0 86 avg += val;
aa572e22 87 }
ce2388e0 88 avg /= benchs.size();
cad06250 89 System.out.println("Time to read = " + avg + " events/ns");
25e48683 90 for (final Double val : benchs) {
ce2388e0 91 System.out.print(val);
cad06250 92 System.out.print(", ");
ce2388e0
FC
93 }
94
95 }
96
ce2388e0 97}
This page took 0.073333 seconds and 5 git commands to generate.