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
;
19 import java
.util
.Vector
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDefinition
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
24 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTraceReader
;
25 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.Stream
;
27 @SuppressWarnings("javadoc")
28 public class ReadTrace
{
33 public static void main(String
[] args
) {
34 final String TRACE_PATH
= "traces/kernel";
36 // Change this to enable text output
37 final boolean USE_TEXT
= false;
39 final int LOOP_COUNT
= 1;
43 Vector
<Double
> benchs
= new Vector
<Double
>();
44 CTFTrace trace
= null;
46 for (int loops
= 0; loops
< LOOP_COUNT
; loops
++) {
49 trace
= new CTFTrace(TRACE_PATH
);
50 } catch (CTFReaderException e
) {
53 @SuppressWarnings("unused")
55 start
= System
.nanoTime();
57 System
.out
.println("Event, " + " Time, " + " type, " + " CPU ");
60 CTFTraceReader traceReader
= new CTFTraceReader(trace
);
62 start
= System
.nanoTime();
64 while (traceReader
.hasMoreEvents()) {
65 EventDefinition ed
= traceReader
.getCurrentEventDef();
68 String output
= formatDate(ed
.getTimestamp()
70 System
.out
.println(nbEvent
+ ", "
71 + output
+ ", " + ed
.getDeclaration().getName()
72 + ", " + ed
.getCPU() + ed
.getFields().toString()) ;
74 @SuppressWarnings("unused")
75 long endTime
= traceReader
.getEndTime();
76 @SuppressWarnings("unused")
77 long timestamp
= traceReader
.getCurrentEventDef().getTimestamp();
78 traceReader
.advance();
80 @SuppressWarnings("unused")
81 Map
<Long
, Stream
> streams
= traceReader
.getTrace().getStreams();
83 stop
= System
.nanoTime();
85 System
.out
.print('.');
86 double time
= (stop
- start
) / (double) nbEvent
;
89 System
.out
.println("");
91 for (Double val
: benchs
) {
95 System
.out
.println("Time to read " + nbEvent
+ " events = " + avg
97 for (Double val
: benchs
) {
98 System
.out
.print(val
);
99 System
.out
.print(", ");
105 * the timestamp in UTC to convert to nanoseconds.
106 * @return formatted string.
108 private static String
formatDate(long timestamp
) {
109 Date d
= new Date(timestamp
/ 1000000);
110 DateFormat df
= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.");
111 String output
= df
.format(d
) + (timestamp
% 1000000000);