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
1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.headless;
14
15 import java.util.Vector;
16
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;
21
22 /**
23 * Test and benchmark reading a CTF LTTng kernel trace.
24 *
25 * @author Matthew Khouzam
26 */
27 public class Benchmark {
28
29 /**
30 * Run the benchmark.
31 *
32 * @param args The command-line arguments
33 */
34 public static void main(final String[] args) {
35 final String TRACE_PATH = "testfiles/kernel";
36 final int NUM_LOOPS = 100;
37
38 // Change this to enable text output
39 final boolean USE_TEXT = true;
40
41 // Work variables
42 long nbEvent = 0L;
43 final Vector<Double> benchs = new Vector<>();
44 long start, stop;
45 for (int loops = 0; loops < NUM_LOOPS; loops++) {
46 nbEvent = 0L;
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 }
54
55 start = System.nanoTime();
56 if (nbEvent != -1) {
57 final CtfTmfContext traceReader = (CtfTmfContext) trace.seekEvent(0);
58
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()
67 + " on CPU " + current.getCPU() + " " + current.getContent().toString());
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();
75 }
76 }
77 stop = System.nanoTime();
78 System.out.print('.');
79 final double time = (stop - start) / (double) nbEvent;
80 benchs.add(time);
81 } // trace.close()
82 }
83 System.out.println("");
84 double avg = 0;
85 for (final double val : benchs) {
86 avg += val;
87 }
88 avg /= benchs.size();
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(", ");
93 }
94
95 }
96
97 }
This page took 0.03301 seconds and 5 git commands to generate.