Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
8636b448 | 2 | * Copyright (c) 2009, 2011, 2012 Ericsson |
0283f7ff | 3 | * |
8c8bf09f ASL |
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 | |
0283f7ff | 8 | * |
8c8bf09f ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
8636b448 | 11 | * Francois Chouinard - Updated as per TMF Trace Model 1.0 |
8c8bf09f ASL |
12 | *******************************************************************************/ |
13 | ||
6c13869b | 14 | package org.eclipse.linuxtools.tmf.core.trace; |
8c8bf09f | 15 | |
a51b2b9f AM |
16 | import java.util.Collection; |
17 | ||
12c155f5 | 18 | import org.eclipse.core.resources.IProject; |
a1091415 | 19 | import org.eclipse.core.resources.IResource; |
f17b2f70 | 20 | import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider; |
72f1e62a | 21 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
4df4581d | 22 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b | 23 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; |
b4f71e4a | 24 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
7898bb21 | 25 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
200789b3 | 26 | import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; |
8c8bf09f ASL |
27 | |
28 | /** | |
f17b2f70 FC |
29 | * The event stream structure in TMF. In its basic form, a trace has: |
30 | * <ul> | |
7e6347b0 FC |
31 | * <li> an associated Eclipse resource |
32 | * <li> a path to its location on the file system | |
f17b2f70 FC |
33 | * <li> the type of the events it contains |
34 | * <li> the number of events it contains | |
35 | * <li> the time range (span) of the events it contains | |
36 | * </ul> | |
37 | * Concrete ITmfTrace classes have to provide a parameter-less constructor and | |
7e6347b0 | 38 | * an initialization method (<i>initTrace</i>) if they are to be opened from |
0283f7ff | 39 | * the Project View. Also, a validation method (<i>validate</i>) has to be |
7e6347b0 | 40 | * provided to ensure that the trace is of the correct type. |
f17b2f70 FC |
41 | * <p> |
42 | * A trace can be accessed simultaneously from multiple threads by various | |
43 | * application components. To avoid obvious multi-threading issues, the trace | |
44 | * uses an ITmfContext as a synchronization aid for its read operations. | |
45 | * <p> | |
46 | * A proper ITmfContext can be obtained by performing a seek operation on the | |
47 | * trace. Seek operations can be performed for a particular event (by rank or | |
48 | * timestamp) or for a plain trace location. | |
49 | * <p> | |
d337369a | 50 | * <b>Example 1</b>: Process a whole trace |
f17b2f70 | 51 | * <pre> |
7e6347b0 | 52 | * ITmfContext context = trace.seekEvent(0); |
c32744d6 | 53 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 | 54 | * while (event != null) { |
d337369a | 55 | * processEvent(event); |
c32744d6 | 56 | * event = trace.getNext(context); |
f17b2f70 FC |
57 | * } |
58 | * </pre> | |
59 | * <b>Example 2</b>: Process 50 events starting from the 1000th event | |
60 | * <pre> | |
61 | * int nbEventsRead = 0; | |
62 | * ITmfContext context = trace.seekEvent(1000); | |
c32744d6 | 63 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 FC |
64 | * while (event != null && nbEventsRead < 50) { |
65 | * nbEventsRead++; | |
d337369a | 66 | * processEvent(event); |
c32744d6 | 67 | * event = trace.getNext(context); |
f17b2f70 FC |
68 | * } |
69 | * </pre> | |
70 | * <b>Example 3</b>: Process the events between 2 timestamps (inclusive) | |
71 | * <pre> | |
72 | * ITmfTimestamp startTime = ...; | |
73 | * ITmfTimestamp endTime = ...; | |
74 | * ITmfContext context = trace.seekEvent(startTime); | |
c32744d6 | 75 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 | 76 | * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) { |
d337369a | 77 | * processEvent(event); |
c32744d6 | 78 | * event = trace.getNext(context); |
f17b2f70 FC |
79 | * } |
80 | * </pre> | |
d337369a | 81 | * A trace is also an event provider so it can process event requests |
7e6347b0 | 82 | * asynchronously (and coalesce compatible, concurrent requests). |
d337369a FC |
83 | * <p> |
84 | * </pre> | |
7e6347b0 | 85 | * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for variants) |
d337369a FC |
86 | * <pre> |
87 | * ITmfRequest request = new TmfEventRequest<MyEventType>(MyEventType.class) { | |
88 | * @Override | |
89 | * public void handleData(MyEventType event) { | |
90 | * super.handleData(event); | |
91 | * processEvent(event); | |
92 | * } | |
93 | * @Override | |
94 | * public void handleCompleted() { | |
95 | * finish(); | |
96 | * super.handleCompleted(); | |
97 | * } | |
98 | * }; | |
0283f7ff | 99 | * |
d337369a FC |
100 | * fTrace.handleRequest(request); |
101 | * if (youWant) { | |
102 | * request.waitForCompletion(); | |
0283f7ff | 103 | * } |
d337369a | 104 | * </pre> |
0283f7ff | 105 | * |
f7703ed6 FC |
106 | * @version 1.0 |
107 | * @author Francois Chouinard | |
0283f7ff | 108 | * |
0316808c | 109 | * @see ITmfContext |
d337369a | 110 | * @see ITmfEvent |
0316808c FC |
111 | * @see ITmfTraceIndexer |
112 | * @see ITmfEventParser | |
8c8bf09f | 113 | */ |
6256d8ad | 114 | public interface ITmfTrace extends ITmfDataProvider { |
12c155f5 | 115 | |
0316808c FC |
116 | // ------------------------------------------------------------------------ |
117 | // Constants | |
118 | // ------------------------------------------------------------------------ | |
119 | ||
120 | /** | |
121 | * The default trace cache size | |
122 | */ | |
123 | public static final int DEFAULT_TRACE_CACHE_SIZE = 1000; | |
124 | ||
8636b448 FC |
125 | // ------------------------------------------------------------------------ |
126 | // Initializers | |
127 | // ------------------------------------------------------------------------ | |
085d898f | 128 | |
3118edf1 FC |
129 | /** |
130 | * Initialize a newly instantiated "empty" trace object. This is used to | |
25e48683 FC |
131 | * properly parameterize an ITmfTrace instantiated with its parameterless |
132 | * constructor. | |
d337369a | 133 | * <p> |
25e48683 FC |
134 | * Typically, the parameterless constructor will provide the block size |
135 | * and its associated parser and indexer. | |
0283f7ff | 136 | * |
25e48683 | 137 | * @param resource the trace resource |
3118edf1 | 138 | * @param path the trace path |
3791b5df | 139 | * @param type the trace event type |
063f0d27 | 140 | * @throws TmfTraceException If we couldn't open the trace |
3118edf1 | 141 | */ |
6256d8ad | 142 | public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException; |
12c155f5 | 143 | |
3118edf1 FC |
144 | /** |
145 | * Validate that the trace is of the correct type. | |
0283f7ff | 146 | * |
3118edf1 FC |
147 | * @param project the eclipse project |
148 | * @param path the trace path | |
0283f7ff | 149 | * |
3118edf1 FC |
150 | * @return true if trace is valid |
151 | */ | |
152 | public boolean validate(IProject project, String path); | |
12c155f5 | 153 | |
8636b448 | 154 | // ------------------------------------------------------------------------ |
3118edf1 | 155 | // Basic getters |
8636b448 | 156 | // ------------------------------------------------------------------------ |
b0a282fb | 157 | |
abfad0aa | 158 | /** |
25e48683 | 159 | * @return the trace event type |
12c155f5 | 160 | */ |
6256d8ad | 161 | public Class<? extends ITmfEvent> getEventType(); |
12c155f5 FC |
162 | |
163 | /** | |
25e48683 | 164 | * @return the associated trace resource |
12c155f5 | 165 | */ |
3791b5df | 166 | public IResource getResource(); |
12c155f5 | 167 | |
25e48683 FC |
168 | /** |
169 | * @return the trace path | |
170 | */ | |
171 | public String getPath(); | |
172 | ||
20658947 FC |
173 | /** |
174 | * @return the trace cache size | |
175 | */ | |
176 | public int getCacheSize(); | |
177 | ||
200789b3 AM |
178 | /** |
179 | * @return The statistics provider for this trace | |
180 | * @since 2.0 | |
181 | */ | |
182 | public ITmfStatistics getStatistics(); | |
183 | ||
7898bb21 | 184 | /** |
a51b2b9f AM |
185 | * Retrieve a state system that belongs to this trace |
186 | * | |
187 | * @param id | |
188 | * The ID of the state system to retrieve. | |
189 | * @return The state system that is associated with this trace and ID, or | |
190 | * 'null' if such a match doesn't exist. | |
191 | * @since 2.0 | |
192 | */ | |
193 | public ITmfStateSystem getStateSystem(String id); | |
194 | ||
195 | /** | |
196 | * Return the list of existing state systems registered with this trace. | |
197 | * | |
198 | * @return A Collection view of the available state systems. The collection | |
199 | * could be empty, but should not be null. | |
7898bb21 AM |
200 | * @since 2.0 |
201 | */ | |
a51b2b9f | 202 | public Collection<String> listStateSystems(); |
7898bb21 | 203 | |
25e48683 FC |
204 | // ------------------------------------------------------------------------ |
205 | // Trace characteristics getters | |
206 | // ------------------------------------------------------------------------ | |
207 | ||
12c155f5 FC |
208 | /** |
209 | * @return the number of events in the trace | |
210 | */ | |
211 | public long getNbEvents(); | |
212 | ||
213 | /** | |
3118edf1 | 214 | * @return the trace time range |
12c155f5 FC |
215 | */ |
216 | public TmfTimeRange getTimeRange(); | |
217 | ||
3118edf1 FC |
218 | /** |
219 | * @return the timestamp of the first trace event | |
220 | */ | |
4df4581d | 221 | public ITmfTimestamp getStartTime(); |
12c155f5 | 222 | |
3118edf1 FC |
223 | /** |
224 | * @return the timestamp of the last trace event | |
225 | */ | |
4df4581d | 226 | public ITmfTimestamp getEndTime(); |
62d1696a | 227 | |
13cb5f43 FC |
228 | /** |
229 | * @return the streaming interval in ms (0 if not a streaming trace) | |
230 | */ | |
231 | public long getStreamingInterval(); | |
232 | ||
25e48683 FC |
233 | // ------------------------------------------------------------------------ |
234 | // Trace positioning getters | |
235 | // ------------------------------------------------------------------------ | |
1b70b6dc | 236 | |
3118edf1 | 237 | /** |
25e48683 | 238 | * @return the current trace location |
3118edf1 | 239 | */ |
1e1bef82 | 240 | public ITmfLocation getCurrentLocation(); |
3791b5df FC |
241 | |
242 | /** | |
25e48683 | 243 | * Returns the ratio (proportion) corresponding to the specified location. |
0283f7ff | 244 | * |
25e48683 FC |
245 | * @param location a trace specific location |
246 | * @return a floating-point number between 0.0 (beginning) and 1.0 (end) | |
3791b5df | 247 | */ |
1e1bef82 | 248 | public double getLocationRatio(ITmfLocation location); |
3791b5df | 249 | |
8636b448 | 250 | // ------------------------------------------------------------------------ |
7e6347b0 | 251 | // SeekEvent operations (returning a trace context) |
8636b448 FC |
252 | // ------------------------------------------------------------------------ |
253 | ||
12c155f5 | 254 | /** |
7e6347b0 FC |
255 | * Position the trace at the specified (trace specific) location. |
256 | * <p> | |
257 | * A null location is interpreted as seeking for the first event of the | |
258 | * trace. | |
25e48683 | 259 | * <p> |
7e6347b0 FC |
260 | * If not null, the location requested must be valid otherwise the returned |
261 | * context is undefined (up to the implementation to recover if possible). | |
25e48683 | 262 | * <p> |
7e6347b0 | 263 | * @param location the trace specific location |
3118edf1 | 264 | * @return a context which can later be used to read the corresponding event |
8c8bf09f | 265 | */ |
1e1bef82 | 266 | public ITmfContext seekEvent(ITmfLocation location); |
12c155f5 | 267 | |
c76c54bb | 268 | /** |
7e6347b0 | 269 | * Position the trace at the 'rank'th event in the trace. |
09e86496 | 270 | * <p> |
7e6347b0 FC |
271 | * A rank <= 0 is interpreted as seeking for the first event of the |
272 | * trace. | |
273 | * <p> | |
274 | * If the requested rank is beyond the last trace event, the context | |
275 | * returned will yield a null event if used in a subsequent read. | |
0283f7ff | 276 | * |
7e6347b0 | 277 | * @param rank the event rank |
3118edf1 | 278 | * @return a context which can later be used to read the corresponding event |
c76c54bb | 279 | */ |
7e6347b0 | 280 | public ITmfContext seekEvent(long rank); |
12c155f5 | 281 | |
3118edf1 FC |
282 | /** |
283 | * Position the trace at the first event with the specified timestamp. If | |
284 | * there is no event with the requested timestamp, a context pointing to | |
09e86496 FC |
285 | * the next chronological event is returned. |
286 | * <p> | |
287 | * A null timestamp is interpreted as seeking for the first event of the | |
288 | * trace. | |
289 | * <p> | |
290 | * If the requested timestamp is beyond the last trace event, the context | |
291 | * returned will yield a null event if used in a subsequent read. | |
0283f7ff | 292 | * |
3118edf1 FC |
293 | * @param timestamp the timestamp of desired event |
294 | * @return a context which can later be used to read the corresponding event | |
295 | */ | |
296 | public ITmfContext seekEvent(ITmfTimestamp timestamp); | |
297 | ||
298 | /** | |
7e6347b0 FC |
299 | * Position the trace at the event located at the specified ratio in the |
300 | * trace file. | |
09e86496 | 301 | * <p> |
7e6347b0 FC |
302 | * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left |
303 | * voluntarily vague. Typically, it would refer to the event proportional | |
304 | * rank (arguably more intuitive) or timestamp in the trace file. | |
0283f7ff | 305 | * |
7e6347b0 | 306 | * @param ratio the proportional 'rank' in the trace |
3118edf1 FC |
307 | * @return a context which can later be used to read the corresponding event |
308 | */ | |
7e6347b0 | 309 | public ITmfContext seekEvent(double ratio); |
3118edf1 | 310 | |
66262ad8 BH |
311 | /** |
312 | * Returns the initial range offset | |
313 | * | |
314 | * @return the initial range offset | |
315 | * @since 2.0 | |
316 | */ | |
317 | public ITmfTimestamp getInitialRangeOffset(); | |
318 | ||
d7ee91bb PT |
319 | /** |
320 | * Return the current selected time. | |
321 | * | |
322 | * @return the current time stamp | |
323 | * @since 2.0 | |
324 | */ | |
325 | public ITmfTimestamp getCurrentTime(); | |
326 | ||
327 | /** | |
328 | * Return the current selected range. | |
329 | * | |
330 | * @return the current time range | |
331 | * @since 2.0 | |
332 | */ | |
333 | public TmfTimeRange getCurrentRange(); | |
8c8bf09f | 334 | } |