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