summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMatthew Khouzam2012-03-16 17:43:56 (EDT)
committer Francois Chouinard2012-04-16 14:19:50 (EDT)
commit117c2cdb3591bc8797cdfa73e4d938d90f1bc55b (patch)
treee05c4bd85004b342a82658c52432a1daa675083d
parentb87e4977d430529b7d9fcd5401b1d06c0feb8a42 (diff)
downloadorg.eclipse.linuxtools-117c2cdb3591bc8797cdfa73e4d938d90f1bc55b.zip
org.eclipse.linuxtools-117c2cdb3591bc8797cdfa73e4d938d90f1bc55b.tar.gz
org.eclipse.linuxtools-117c2cdb3591bc8797cdfa73e4d938d90f1bc55b.tar.bz2
Generalized trace test added. Can be useful for profiling.
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java79
1 files changed, 79 insertions, 0 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java
new file mode 100644
index 0000000..a6b5aff
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.tests.headless;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
+
+public class ReadTrace {
+
+ /**
+ * @param args
+ */
+ @SuppressWarnings("nls")
+ public static void main(String[] args) {
+ final String TRACE_PATH = "Tests/traces/trace20m";
+
+ // Change this to enable text output
+ final boolean USE_TEXT = false;
+
+ // Work variables
+ Long nbEvent = 0L;
+ CTFTrace trace = null;
+ try {
+ trace = new CTFTrace(TRACE_PATH);
+ } catch (CTFReaderException e) {
+
+ nbEvent = (long) -1;
+ }
+ long start, stop;
+ start = System.nanoTime();
+ if (nbEvent != -1) {
+ CTFTraceReader traceReader = new CTFTraceReader(trace);
+
+ start = System.nanoTime();
+ while (traceReader.hasMoreEvents()) {
+ EventDefinition ed = traceReader.getCurrentEventDef();
+ nbEvent++;
+ if (USE_TEXT) {
+ String output = formatDate(ed.timestamp + trace.getOffset());
+ System.out.println("Event " + nbEvent + " Time " + output
+ + " type " + ed.getDeclaration().getName()
+ + " on CPU " + ed.getCPU());
+ }
+ traceReader.advance();
+ }
+ }
+ stop = System.nanoTime();
+ System.out.println("Time taken for " + nbEvent + " " + (stop - start)
+ + "ns ");
+ System.out.println(((stop - start) / nbEvent) + "ns/event ");
+ }
+
+ /**
+ * @param timestamp the timestamp in UTC to convert to nanoseconds.
+ * @return formatted string.
+ */
+ 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$
+ String output = df.format(d) + (timestamp % 1000000000);
+ return output;
+ }
+}