lttng: Update kernel provider tests to the new trace location
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core.tests / src / org / eclipse / linuxtools / ctf / core / tests / headless / ReadTrace.java
CommitLineData
ce2388e0
FC
1/*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.ctf.core.tests.headless;
14
15import java.text.DateFormat;
16import java.text.SimpleDateFormat;
17import java.util.Date;
18import java.util.Vector;
19
20import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
21import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
22import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
23import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
24
25public class ReadTrace {
26
27 /**
28 * @param args
29 */
30 @SuppressWarnings("nls")
31 public static void main(String[] args) {
32 final String TRACE_PATH = "Tests/traces/trace20m1";
33
34 // Change this to enable text output
35 final boolean USE_TEXT = false;
36
37 final int LOOP_COUNT = 1;
38
39 // Work variables
40 Long nbEvent = 0L;
41 Vector<Double> benchs = new Vector<Double>();
42 CTFTrace trace = null;
43 long start, stop;
44 for (int loops = 0; loops < LOOP_COUNT; loops++) {
45 try {
46 nbEvent = 0L;
47 trace = new CTFTrace(TRACE_PATH);
48 } catch (CTFReaderException e) {
49 // do nothing
50 }
51 long prev = -1;
52 start = System.nanoTime();
53 if (USE_TEXT) {
54 System.out.println("Event, " + " Time, " + " type, " + " CPU ");
55 }
56 if (trace != null) {
57 CTFTraceReader traceReader = new CTFTraceReader(trace);
58
59 start = System.nanoTime();
60
61 while (traceReader.hasMoreEvents()) {
62 EventDefinition ed = traceReader.getCurrentEventDef();
63 nbEvent++;
64 if (prev == traceReader.getIndex()) {
65 System.out.println("Error on events " + prev);
66 }
67 prev = traceReader.getIndex();
68 if (USE_TEXT) {
69 String output = formatDate(ed.timestamp
70 + trace.getOffset());
71 System.out.println(traceReader.getIndex() + ", "
72 + output + ", " + ed.getDeclaration().getName()
73 + ", " + ed.getCPU());
74 }
75
76 traceReader.advance();
77 }
78 }
79 stop = System.nanoTime();
80 System.out.print('.');
81 double time = (stop - start) / (double) nbEvent;
82 benchs.add(time);
83 }
84 System.out.println("");
85 double avg = 0;
86 for (Double val : benchs) {
87 avg += val;
88 }
89 avg /= benchs.size();
90 System.out.println("Time to read " + nbEvent + " events = " + avg
91 + " events/ns");
92 for (Double val : benchs) {
93 System.out.print(val);
94 System.out.print(", ");
95 }
96 try {
97 testSeekIndex(trace);
98 } catch (CTFReaderException e) {
99 // TODO Auto-generated catch block
100 e.printStackTrace();
101 }
102
103 try {
104 testSeekIndex(trace);
105 } catch (CTFReaderException e) {
106 // TODO Auto-generated catch block
107 e.printStackTrace();
108 }
109
110 }
111
112 /**
113 * @return
114 */
115 private static long getTimestamp(CTFTraceReader fixture) {
116 if (fixture.getCurrentEventDef() != null) {
117 return fixture.getCurrentEventDef().timestamp;
118 }
119 return Long.MIN_VALUE;
120 }
121
122 public static void testSeekIndex(CTFTrace trace) throws CTFReaderException {
123 CTFTraceReader fixture = new CTFTraceReader(trace);
124 long rank = 300000L;
125 long timeRank = 4281275394331L;
126 long nearEnd = 4287422858132L;
127 long seekTime_0;
128 long seekIndex_0 = 0;
129 long seekNext_300000 = 0;
130 long seekIndex_300000 = 0;
131 long seekTime_300000 = 0;
132 String cr = "\n"; //$NON-NLS-1$
133 fixture.seek(0);
134 for (int i = 0; i < 100; i++) {
135 fixture.advance();
136 }
137
138 fixture.seek(nearEnd);
139 /*
140 * we need to read the trace before seeking
141 */
142 fixture.seek(0);
143 seekTime_0 = getTimestamp(fixture);
144 for (int i = 0; i < rank; i++) {
145 fixture.advance();
146 }
147 seekNext_300000 = getTimestamp(fixture);
148 fixture.seek(timeRank);
149 seekTime_300000 = getTimestamp(fixture);
150 fixture.seekIndex(0);
151 seekIndex_0 = getTimestamp(fixture);
152
153 fixture.seekIndex(rank);
154 seekIndex_300000 = getTimestamp(fixture);
155 System.out.print(cr);
156 System.out.println("seek(0) " + seekTime_0 + cr + //$NON-NLS-1$
157 "seekIndex(0) " + seekIndex_0 + cr + //$NON-NLS-1$
158 "Next(300000) " + seekNext_300000 + cr + //$NON-NLS-1$
159 "seek(time(300000)) " + seekTime_300000 + cr + //$NON-NLS-1$
160 "seekIndex(300000) " + seekIndex_300000 //$NON-NLS-1$
161 );
162 }
163
164 /**
165 * @param timestamp
166 * the timestamp in UTC to convert to nanoseconds.
167 * @return formatted string.
168 */
169 private static String formatDate(long timestamp) {
170 Date d = new Date(timestamp / 1000000);
171 DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$
172 String output = df.format(d) + (timestamp % 1000000000);
173 return output;
174 }
175}
This page took 0.041268 seconds and 5 git commands to generate.