Commit | Line | Data |
---|---|---|
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 | |
91e7f946 | 13 | package org.eclipse.linuxtools.tmf.ctf.core.tests.headless; |
ce2388e0 | 14 | |
ce2388e0 FC |
15 | import java.util.Vector; |
16 | ||
b4f71e4a | 17 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
91e7f946 AM |
18 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfContext; |
19 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent; | |
20 | import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace; | |
ce2388e0 | 21 | |
95bf10e7 AM |
22 | /** |
23 | * Test and benchmark reading a CTF LTTng kernel trace. | |
24 | * | |
25 | * @author Matthew Khouzam | |
26 | */ | |
ce2388e0 FC |
27 | public 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 | CtfTmfTrace trace = null; |
45 | long start, stop; | |
46 | for (int loops = 0; loops < NUM_LOOPS; loops++) { | |
47 | nbEvent = 0L; | |
48 | trace = new CtfTmfTrace(); | |
49 | try { | |
25e48683 | 50 | trace.initTrace(null, TRACE_PATH, CtfTmfEvent.class); |
b4f71e4a | 51 | } catch (final TmfTraceException e) { |
ce2388e0 FC |
52 | loops = NUM_LOOPS +1; |
53 | break; | |
54 | } | |
55 | ||
56 | start = System.nanoTime(); | |
57 | if (nbEvent != -1) { | |
81a2d02e | 58 | final CtfTmfContext traceReader = (CtfTmfContext) trace.seekEvent(0); |
ce2388e0 FC |
59 | |
60 | start = System.nanoTime(); | |
61 | CtfTmfEvent current = traceReader.getCurrentEvent(); | |
62 | while (current != null) { | |
63 | nbEvent++; | |
64 | if (USE_TEXT) { | |
aa572e22 | 65 | |
cad06250 | 66 | System.out.println("Event " + nbEvent + " Time " |
33803b9b | 67 | + current.getTimestamp().toString() + " type " + current.getType().getName() |
cad06250 | 68 | + " on CPU " + current.getSource() + " " + current.getContent().toString()); |
ce2388e0 | 69 | } |
156a3e3a MK |
70 | // advance the trace to the next event. |
71 | boolean hasMore = traceReader.advance(); | |
72 | if( hasMore ){ | |
73 | // you can know the trace has more events. | |
74 | } | |
ce2388e0 FC |
75 | current = traceReader.getCurrentEvent(); |
76 | } | |
77 | } | |
78 | stop = System.nanoTime(); | |
79 | System.out.print('.'); | |
25e48683 | 80 | final double time = (stop - start) / (double) nbEvent; |
ce2388e0 FC |
81 | benchs.add(time); |
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 | } |