1
/*******************************************************************************
2
* Copyright (c) 2012 Ericsson
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
10
* Matthew Khouzam - Initial API and implementation
11
*******************************************************************************/
12
package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.headless;
14
import java.util.Vector;
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;
19
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
21
public class Benchmark {
26
@SuppressWarnings("nls")
27
public static void main(final String[] args) {
28
final String TRACE_PATH = "testfiles/kernel";
29
final int NUM_LOOPS = 100;
31
// Change this to enable text output
32
final boolean USE_TEXT = true;
36
// } catch (final IOException e1) {
37
// e1.printStackTrace();
41
final Vector<Double> benchs = new Vector<Double>();
42
CtfTmfTrace trace = null;
44
for (int loops = 0; loops < NUM_LOOPS; loops++) {
46
trace = new CtfTmfTrace();
48
trace.initTrace(null, TRACE_PATH, CtfTmfEvent.class);
49
} catch (final TmfTraceException e) {
54
start = System.nanoTime();
56
final CtfIterator traceReader = (CtfIterator) trace.seekEvent(0);
58
start = System.nanoTime();
59
CtfTmfEvent current = traceReader.getCurrentEvent();
60
while (current != null) {
64
System.out.println("Event " + traceReader.getRank() + " Time "
65
+ current.getTimestamp().toString() + " type " + current.getEventName()
66
+ " on CPU " + current.getSource() + " " + current.getContent().toString()) ;
68
traceReader.advance();
69
current = traceReader.getCurrentEvent();
72
stop = System.nanoTime();
73
System.out.print('.');
74
final double time = (stop - start) / (double) nbEvent;
77
System.out.println("");
79
for (final Double val : benchs) {
83
System.out.println("Time to read = " + avg + " events/ns");
84
for (final Double val : benchs) {
85
System.out.print(val);
86
System.out.print(", ");
93
// * the timestamp in UTC to convert to nanoseconds.
94
// * @return formatted string.
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);