1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.tests
.headless
;
15 import java
.text
.DateFormat
;
16 import java
.text
.SimpleDateFormat
;
17 import java
.util
.Date
;
18 import java
.util
.Vector
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDefinition
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTraceReader
;
25 @SuppressWarnings("javadoc")
26 public class ReadTrace
{
31 public static void main(String
[] args
) {
32 final String TRACE_PATH
= "traces/kernel";
34 // Change this to enable text output
35 final boolean USE_TEXT
= false;
37 final int LOOP_COUNT
= 1;
41 Vector
<Double
> benchs
= new Vector
<Double
>();
42 CTFTrace trace
= null;
44 for (int loops
= 0; loops
< LOOP_COUNT
; loops
++) {
47 trace
= new CTFTrace(TRACE_PATH
);
48 } catch (CTFReaderException e
) {
51 start
= System
.nanoTime();
53 System
.out
.println("Event, " + " Time, " + " type, " + " CPU ");
57 CTFTraceReader traceReader
= new CTFTraceReader(trace
);
59 start
= System
.nanoTime();
61 while (traceReader
.hasMoreEvents()) {
62 EventDefinition ed
= traceReader
.getCurrentEventDef();
65 String output
= formatDate(ed
.getTimestamp()
67 System
.out
.println(nbEvent
+ ", "
68 + output
+ ", " + ed
.getDeclaration().getName()
69 + ", " + ed
.getCPU() + ed
.getFields().toString());
71 // long endTime = traceReader.getEndTime();
73 // traceReader.getCurrentEventDef().getTimestamp();
74 traceReader
.advance();
76 // Map<Long, Stream> streams =
77 // traceReader.getTrace().getStreams();
79 stop
= System
.nanoTime();
81 System
.out
.print('.');
82 double time
= (stop
- start
) / (double) nbEvent
;
84 } catch (CTFReaderException e
) {
85 System
.out
.println("error");
88 System
.out
.println("");
90 for (Double val
: benchs
) {
94 System
.out
.println("Time to read " + nbEvent
+ " events = " + avg
96 for (Double val
: benchs
) {
97 System
.out
.print(val
);
98 System
.out
.print(", ");
104 * the timestamp in UTC to convert to nanoseconds.
105 * @return formatted string.
107 private static String
formatDate(long timestamp
) {
108 Date d
= new Date(timestamp
/ 1000000);
109 DateFormat df
= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.");
110 String output
= df
.format(d
) + (timestamp
% 1000000000);