Commit | Line | Data |
---|---|---|
ce2388e0 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 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 | package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.headless; | |
13 | ||
ce2388e0 FC |
14 | import java.util.Vector; |
15 | ||
16 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator; | |
17 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; | |
18 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; | |
b4f71e4a | 19 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
ce2388e0 FC |
20 | |
21 | public class Benchmark { | |
22 | ||
23 | /** | |
24 | * @param args | |
25 | */ | |
26 | @SuppressWarnings("nls") | |
25e48683 | 27 | public static void main(final String[] args) { |
aa572e22 | 28 | final String TRACE_PATH = "testfiles/kernel"; |
ce2388e0 FC |
29 | final int NUM_LOOPS = 100; |
30 | ||
31 | // Change this to enable text output | |
aa572e22 | 32 | final boolean USE_TEXT = true; |
ce2388e0 | 33 | |
aa572e22 MK |
34 | // try { |
35 | // System.in.read(); | |
36 | // } catch (final IOException e1) { | |
37 | // e1.printStackTrace(); | |
38 | // } | |
ce2388e0 FC |
39 | // Work variables |
40 | Long nbEvent = 0L; | |
25e48683 | 41 | final Vector<Double> benchs = new Vector<Double>(); |
ce2388e0 FC |
42 | CtfTmfTrace trace = null; |
43 | long start, stop; | |
44 | for (int loops = 0; loops < NUM_LOOPS; loops++) { | |
45 | nbEvent = 0L; | |
46 | trace = new CtfTmfTrace(); | |
47 | try { | |
25e48683 | 48 | trace.initTrace(null, TRACE_PATH, CtfTmfEvent.class); |
b4f71e4a | 49 | } catch (final TmfTraceException e) { |
ce2388e0 FC |
50 | loops = NUM_LOOPS +1; |
51 | break; | |
52 | } | |
53 | ||
54 | start = System.nanoTime(); | |
55 | if (nbEvent != -1) { | |
25e48683 | 56 | final CtfIterator traceReader = (CtfIterator) trace.seekEvent(0); |
ce2388e0 FC |
57 | |
58 | start = System.nanoTime(); | |
59 | CtfTmfEvent current = traceReader.getCurrentEvent(); | |
60 | while (current != null) { | |
61 | nbEvent++; | |
62 | if (USE_TEXT) { | |
aa572e22 | 63 | |
ce2388e0 | 64 | System.out.println("Event " + traceReader.getRank() + " Time " |
aa572e22 MK |
65 | + current.getTimestamp().toString() + " type " + current.getEventName() |
66 | + " on CPU " + current.getSource() + " " + current.getContent().toString()) ; | |
ce2388e0 FC |
67 | } |
68 | traceReader.advance(); | |
69 | current = traceReader.getCurrentEvent(); | |
70 | } | |
71 | } | |
72 | stop = System.nanoTime(); | |
73 | System.out.print('.'); | |
25e48683 | 74 | final double time = (stop - start) / (double) nbEvent; |
ce2388e0 FC |
75 | benchs.add(time); |
76 | } | |
77 | System.out.println(""); | |
78 | double avg = 0; | |
aa572e22 | 79 | for (final Double val : benchs) { |
ce2388e0 | 80 | avg += val; |
aa572e22 | 81 | } |
ce2388e0 FC |
82 | avg /= benchs.size(); |
83 | System.out.println("Time to read = " + avg + " events/ns"); | |
25e48683 | 84 | for (final Double val : benchs) { |
ce2388e0 FC |
85 | System.out.print(val); |
86 | System.out.print(", "); | |
87 | } | |
88 | ||
89 | } | |
90 | ||
8fd82db5 FC |
91 | // /** |
92 | // * @param timestamp | |
93 | // * the timestamp in UTC to convert to nanoseconds. | |
94 | // * @return formatted string. | |
95 | // */ | |
96 | // private static String formatDate(final long timestamp) { | |
97 | // final Date d = new Date(timestamp / 1000000); | |
98 | // final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$ | |
99 | // final String output = df.format(d) + (timestamp % 1000000000); | |
100 | // return output; | |
101 | // } | |
ce2388e0 FC |
102 | |
103 | } |