/*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2014 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
package org.eclipse.linuxtools.ctf.core.tests.headless;
+import java.io.FileNotFoundException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
+@SuppressWarnings("javadoc")
public class ReadTrace {
/**
* @param args
+ * @throws FileNotFoundException
*/
- @SuppressWarnings("nls")
- public static void main(String[] args) {
- final String TRACE_PATH = "Tests/traces/trace20m1";
+ public static void main(String[] args) throws FileNotFoundException {
+ final String TRACE_PATH = "traces/kernel";
// Change this to enable text output
final boolean USE_TEXT = false;
+ final int LOOP_COUNT = 10;
+
// Work variables
- Long nbEvent = 0L;
- Vector<Double> benchs = new Vector<Double>();
+ long nbEvent = 0L;
+ Vector<Double> benchs = new Vector<>();
CTFTrace trace = null;
long start, stop;
- for (int loops = 0; loops < 100; loops++) {
+ for (int loops = 0; loops < LOOP_COUNT; loops++) {
try {
nbEvent = 0L;
trace = new CTFTrace(TRACE_PATH);
} catch (CTFReaderException e) {
- nbEvent = (long) -1;
+ throw new FileNotFoundException(TRACE_PATH);
}
-
start = System.nanoTime();
- if (nbEvent != -1) {
- CTFTraceReader traceReader = new CTFTraceReader(trace);
-
+ if (USE_TEXT) {
+ System.out.println("Event, " + " Time, " + " type, " + " CPU ");
+ }
+ try (CTFTraceReader traceReader = new CTFTraceReader(trace);) {
start = System.nanoTime();
+
while (traceReader.hasMoreEvents()) {
EventDefinition ed = traceReader.getCurrentEventDef();
nbEvent++;
if (USE_TEXT) {
- String output = formatDate(ed.timestamp
+ String output = formatDate(ed.getTimestamp()
+ trace.getOffset());
- System.out.println("Event " + nbEvent + " Time "
- + output + " type "
- + ed.getDeclaration().getName() + " on CPU "
- + ed.getCPU());
+ System.out.println(nbEvent + ", "
+ + output + ", " + ed.getDeclaration().getName()
+ + ", " + ed.getCPU() + ed.getFields().toString());
}
+
traceReader.advance();
}
+
+ stop = System.nanoTime();
+
+ System.out.print('.');
+ double time = (stop - start) / (double) nbEvent;
+ benchs.add(time);
+ } catch (CTFReaderException e) {
+ System.out.println("error");
}
- stop = System.nanoTime();
- System.out.print('.');
- double time = (stop - start) / (double) nbEvent;
- benchs.add(time);
}
System.out.println("");
double avg = 0;
avg += val;
}
avg /= benchs.size();
- System.out.println("Time to read = " + avg + " events/ns");
- for(Double val:benchs){
- System.out.print(val );System.out.print( ", ");
+ System.out.println("Time to read " + nbEvent + " events = " + avg
+ + " ns/event");
+ for (Double val : benchs) {
+ System.out.print(val);
+ System.out.print(", ");
}
-
}
/**
*/
private static String formatDate(long timestamp) {
Date d = new Date(timestamp / 1000000);
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.");
String output = df.format(d) + (timestamp % 1000000000);
return output;
}