Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
bcb8c2cb | 2 | * Copyright (c) 2009, 2014 Ericsson, École Polytechnique de Montréal |
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 |
e73a4ba5 GB |
12 | * Geneviève Bastien - Added timestamp transforms and timestamp |
13 | * creation functions | |
8c8bf09f ASL |
14 | *******************************************************************************/ |
15 | ||
6c13869b | 16 | package org.eclipse.linuxtools.tmf.core.trace; |
8c8bf09f | 17 | |
12c155f5 | 18 | import org.eclipse.core.resources.IProject; |
a1091415 | 19 | import org.eclipse.core.resources.IResource; |
a94410d9 | 20 | import org.eclipse.core.runtime.IStatus; |
ff3f02c8 AM |
21 | import org.eclipse.jdt.annotation.NonNull; |
22 | import org.eclipse.jdt.annotation.Nullable; | |
c068a752 | 23 | import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule; |
fd3f1eff | 24 | import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider; |
72f1e62a | 25 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
b4f71e4a | 26 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
e73a4ba5 | 27 | import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform; |
3bd46eef AM |
28 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
29 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; | |
a3db8436 AM |
30 | import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer; |
31 | import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation; | |
8c8bf09f ASL |
32 | |
33 | /** | |
f17b2f70 FC |
34 | * The event stream structure in TMF. In its basic form, a trace has: |
35 | * <ul> | |
7e6347b0 FC |
36 | * <li> an associated Eclipse resource |
37 | * <li> a path to its location on the file system | |
f17b2f70 FC |
38 | * <li> the type of the events it contains |
39 | * <li> the number of events it contains | |
40 | * <li> the time range (span) of the events it contains | |
41 | * </ul> | |
42 | * Concrete ITmfTrace classes have to provide a parameter-less constructor and | |
e73a4ba5 GB |
43 | * an initialization method (<i>initTrace</i>) if they are to be opened from the |
44 | * Project View. Also, a validation method (<i>validate</i>) has to be provided | |
45 | * to ensure that the trace is of the correct type. | |
f17b2f70 FC |
46 | * <p> |
47 | * A trace can be accessed simultaneously from multiple threads by various | |
48 | * application components. To avoid obvious multi-threading issues, the trace | |
49 | * uses an ITmfContext as a synchronization aid for its read operations. | |
50 | * <p> | |
51 | * A proper ITmfContext can be obtained by performing a seek operation on the | |
52 | * trace. Seek operations can be performed for a particular event (by rank or | |
53 | * timestamp) or for a plain trace location. | |
54 | * <p> | |
d337369a | 55 | * <b>Example 1</b>: Process a whole trace |
f17b2f70 | 56 | * <pre> |
7e6347b0 | 57 | * ITmfContext context = trace.seekEvent(0); |
c32744d6 | 58 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 | 59 | * while (event != null) { |
d337369a | 60 | * processEvent(event); |
c32744d6 | 61 | * event = trace.getNext(context); |
f17b2f70 FC |
62 | * } |
63 | * </pre> | |
64 | * <b>Example 2</b>: Process 50 events starting from the 1000th event | |
65 | * <pre> | |
66 | * int nbEventsRead = 0; | |
67 | * ITmfContext context = trace.seekEvent(1000); | |
c32744d6 | 68 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 FC |
69 | * while (event != null && nbEventsRead < 50) { |
70 | * nbEventsRead++; | |
d337369a | 71 | * processEvent(event); |
c32744d6 | 72 | * event = trace.getNext(context); |
f17b2f70 FC |
73 | * } |
74 | * </pre> | |
75 | * <b>Example 3</b>: Process the events between 2 timestamps (inclusive) | |
76 | * <pre> | |
77 | * ITmfTimestamp startTime = ...; | |
78 | * ITmfTimestamp endTime = ...; | |
79 | * ITmfContext context = trace.seekEvent(startTime); | |
c32744d6 | 80 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 | 81 | * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) { |
d337369a | 82 | * processEvent(event); |
c32744d6 | 83 | * event = trace.getNext(context); |
f17b2f70 FC |
84 | * } |
85 | * </pre> | |
e73a4ba5 | 86 | * |
d337369a | 87 | * A trace is also an event provider so it can process event requests |
7e6347b0 | 88 | * asynchronously (and coalesce compatible, concurrent requests). |
d337369a | 89 | * <p> |
e73a4ba5 GB |
90 | * |
91 | * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for | |
92 | * variants) | |
d337369a FC |
93 | * <pre> |
94 | * ITmfRequest request = new TmfEventRequest<MyEventType>(MyEventType.class) { | |
e73a4ba5 | 95 | * @Override |
d337369a FC |
96 | * public void handleData(MyEventType event) { |
97 | * super.handleData(event); | |
98 | * processEvent(event); | |
99 | * } | |
e73a4ba5 GB |
100 | * |
101 | * @Override | |
d337369a FC |
102 | * public void handleCompleted() { |
103 | * finish(); | |
104 | * super.handleCompleted(); | |
105 | * } | |
106 | * }; | |
0283f7ff | 107 | * |
d337369a FC |
108 | * fTrace.handleRequest(request); |
109 | * if (youWant) { | |
110 | * request.waitForCompletion(); | |
0283f7ff | 111 | * } |
d337369a | 112 | * </pre> |
0283f7ff | 113 | * |
5419a136 | 114 | * @version 1.0 |
f7703ed6 | 115 | * @author Francois Chouinard |
0283f7ff | 116 | * |
0316808c | 117 | * @see ITmfContext |
d337369a | 118 | * @see ITmfEvent |
0316808c FC |
119 | * @see ITmfTraceIndexer |
120 | * @see ITmfEventParser | |
8c8bf09f | 121 | */ |
fd3f1eff | 122 | public interface ITmfTrace extends ITmfEventProvider { |
12c155f5 | 123 | |
0316808c FC |
124 | // ------------------------------------------------------------------------ |
125 | // Constants | |
126 | // ------------------------------------------------------------------------ | |
127 | ||
128 | /** | |
129 | * The default trace cache size | |
130 | */ | |
131 | public static final int DEFAULT_TRACE_CACHE_SIZE = 1000; | |
132 | ||
8636b448 FC |
133 | // ------------------------------------------------------------------------ |
134 | // Initializers | |
135 | // ------------------------------------------------------------------------ | |
085d898f | 136 | |
3118edf1 FC |
137 | /** |
138 | * Initialize a newly instantiated "empty" trace object. This is used to | |
25e48683 FC |
139 | * properly parameterize an ITmfTrace instantiated with its parameterless |
140 | * constructor. | |
d337369a | 141 | * <p> |
e73a4ba5 GB |
142 | * Typically, the parameterless constructor will provide the block size and |
143 | * its associated parser and indexer. | |
0283f7ff | 144 | * |
e73a4ba5 GB |
145 | * @param resource |
146 | * the trace resource | |
147 | * @param path | |
148 | * the trace path | |
149 | * @param type | |
150 | * the trace event type | |
151 | * @throws TmfTraceException | |
152 | * If we couldn't open the trace | |
3118edf1 | 153 | */ |
57a2a5ca | 154 | void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException; |
12c155f5 | 155 | |
3118edf1 | 156 | /** |
bcb8c2cb PT |
157 | * Validate that the trace is of the correct type. The implementation should |
158 | * return a TraceValidationStatus to indicate success with a certain level | |
159 | * of confidence. | |
0283f7ff | 160 | * |
e73a4ba5 GB |
161 | * @param project |
162 | * the eclipse project | |
163 | * @param path | |
164 | * the trace path | |
bcb8c2cb | 165 | * |
e73a4ba5 GB |
166 | * @return an IStatus object with validation result. Use severity OK to |
167 | * indicate success. | |
bcb8c2cb | 168 | * @see {@link TraceValidationStatus} |
a94410d9 | 169 | * @since 2.0 |
3118edf1 | 170 | */ |
57a2a5ca | 171 | IStatus validate(IProject project, String path); |
12c155f5 | 172 | |
8636b448 | 173 | // ------------------------------------------------------------------------ |
3118edf1 | 174 | // Basic getters |
8636b448 | 175 | // ------------------------------------------------------------------------ |
b0a282fb | 176 | |
abfad0aa | 177 | /** |
25e48683 | 178 | * @return the trace event type |
12c155f5 | 179 | */ |
57a2a5ca | 180 | Class<? extends ITmfEvent> getEventType(); |
12c155f5 FC |
181 | |
182 | /** | |
25e48683 | 183 | * @return the associated trace resource |
12c155f5 | 184 | */ |
57a2a5ca | 185 | IResource getResource(); |
12c155f5 | 186 | |
25e48683 FC |
187 | /** |
188 | * @return the trace path | |
189 | */ | |
57a2a5ca | 190 | String getPath(); |
25e48683 | 191 | |
20658947 FC |
192 | /** |
193 | * @return the trace cache size | |
194 | */ | |
57a2a5ca | 195 | int getCacheSize(); |
20658947 | 196 | |
51e75066 AM |
197 | /** |
198 | * Index the trace. Depending on the trace type, this could be done at the | |
199 | * constructor or initTrace phase too, so this could be implemented as a | |
200 | * no-op. | |
201 | * | |
202 | * @param waitForCompletion | |
203 | * Should we block the caller until indexing is finished, or not. | |
204 | * @since 2.0 | |
205 | */ | |
57a2a5ca | 206 | void indexTrace(boolean waitForCompletion); |
51e75066 | 207 | |
ff3f02c8 AM |
208 | // ------------------------------------------------------------------------ |
209 | // Analysis getters | |
210 | // ------------------------------------------------------------------------ | |
211 | ||
c068a752 | 212 | /** |
ff3f02c8 | 213 | * Returns an analysis module with the given ID. |
c068a752 | 214 | * |
ff3f02c8 AM |
215 | * @param id |
216 | * The analysis module ID | |
217 | * @return The {@link IAnalysisModule} object, or null if an analysis with | |
218 | * the given ID does no exist. | |
c4767854 | 219 | * @since 3.0 |
c068a752 | 220 | */ |
ff3f02c8 AM |
221 | @Nullable |
222 | IAnalysisModule getAnalysisModule(String id); | |
c068a752 GB |
223 | |
224 | /** | |
ff3f02c8 | 225 | * Get a list of all analysis modules currently available for this trace. |
c068a752 | 226 | * |
ff3f02c8 | 227 | * @return An iterable view of the analysis modules |
c4767854 | 228 | * @since 3.0 |
c068a752 | 229 | */ |
ff3f02c8 AM |
230 | @NonNull |
231 | Iterable<IAnalysisModule> getAnalysisModules(); | |
c068a752 GB |
232 | |
233 | /** | |
ff3f02c8 AM |
234 | * Get an analysis module belonging to this trace, with the specified ID and |
235 | * class. | |
c068a752 | 236 | * |
ff3f02c8 AM |
237 | * @param moduleClass |
238 | * Returned modules must extend this class | |
239 | * @param id | |
240 | * The ID of the analysis module | |
241 | * @return The analysis module with specified class and ID, or null if no | |
242 | * such module exists. | |
243 | * @since 3.0 | |
244 | */ | |
245 | @Nullable | |
246 | <T extends IAnalysisModule> T getAnalysisModuleOfClass(Class<T> moduleClass, String id); | |
247 | ||
248 | /** | |
249 | * Return the analysis modules that are of a given class. Module are already | |
250 | * casted to the requested class. | |
c068a752 | 251 | * |
ff3f02c8 AM |
252 | * @param moduleClass |
253 | * Returned modules must extend this class | |
254 | * @return List of modules of class moduleClass | |
c4767854 | 255 | * @since 3.0 |
c068a752 | 256 | */ |
ff3f02c8 AM |
257 | @NonNull |
258 | <T> Iterable<T> getAnalysisModulesOfClass(Class<T> moduleClass); | |
c068a752 | 259 | |
25e48683 FC |
260 | // ------------------------------------------------------------------------ |
261 | // Trace characteristics getters | |
262 | // ------------------------------------------------------------------------ | |
263 | ||
12c155f5 FC |
264 | /** |
265 | * @return the number of events in the trace | |
266 | */ | |
57a2a5ca | 267 | long getNbEvents(); |
12c155f5 FC |
268 | |
269 | /** | |
3118edf1 | 270 | * @return the trace time range |
3bd46eef | 271 | * @since 2.0 |
12c155f5 | 272 | */ |
57a2a5ca | 273 | TmfTimeRange getTimeRange(); |
12c155f5 | 274 | |
3118edf1 FC |
275 | /** |
276 | * @return the timestamp of the first trace event | |
3bd46eef | 277 | * @since 2.0 |
3118edf1 | 278 | */ |
57a2a5ca | 279 | ITmfTimestamp getStartTime(); |
12c155f5 | 280 | |
3118edf1 FC |
281 | /** |
282 | * @return the timestamp of the last trace event | |
3bd46eef | 283 | * @since 2.0 |
3118edf1 | 284 | */ |
57a2a5ca | 285 | ITmfTimestamp getEndTime(); |
62d1696a | 286 | |
13cb5f43 FC |
287 | /** |
288 | * @return the streaming interval in ms (0 if not a streaming trace) | |
289 | */ | |
57a2a5ca | 290 | long getStreamingInterval(); |
13cb5f43 | 291 | |
25e48683 FC |
292 | // ------------------------------------------------------------------------ |
293 | // Trace positioning getters | |
294 | // ------------------------------------------------------------------------ | |
1b70b6dc | 295 | |
3118edf1 | 296 | /** |
25e48683 | 297 | * @return the current trace location |
a3db8436 | 298 | * @since 3.0 |
3118edf1 | 299 | */ |
57a2a5ca | 300 | ITmfLocation getCurrentLocation(); |
3791b5df FC |
301 | |
302 | /** | |
25e48683 | 303 | * Returns the ratio (proportion) corresponding to the specified location. |
0283f7ff | 304 | * |
e73a4ba5 GB |
305 | * @param location |
306 | * a trace specific location | |
25e48683 | 307 | * @return a floating-point number between 0.0 (beginning) and 1.0 (end) |
a3db8436 | 308 | * @since 3.0 |
3791b5df | 309 | */ |
57a2a5ca | 310 | double getLocationRatio(ITmfLocation location); |
3791b5df | 311 | |
8636b448 | 312 | // ------------------------------------------------------------------------ |
7e6347b0 | 313 | // SeekEvent operations (returning a trace context) |
8636b448 FC |
314 | // ------------------------------------------------------------------------ |
315 | ||
12c155f5 | 316 | /** |
7e6347b0 FC |
317 | * Position the trace at the specified (trace specific) location. |
318 | * <p> | |
319 | * A null location is interpreted as seeking for the first event of the | |
320 | * trace. | |
25e48683 | 321 | * <p> |
7e6347b0 FC |
322 | * If not null, the location requested must be valid otherwise the returned |
323 | * context is undefined (up to the implementation to recover if possible). | |
25e48683 | 324 | * <p> |
e73a4ba5 GB |
325 | * |
326 | * @param location | |
327 | * the trace specific location | |
3118edf1 | 328 | * @return a context which can later be used to read the corresponding event |
a3db8436 | 329 | * @since 3.0 |
8c8bf09f | 330 | */ |
57a2a5ca | 331 | ITmfContext seekEvent(ITmfLocation location); |
12c155f5 | 332 | |
c76c54bb | 333 | /** |
7e6347b0 | 334 | * Position the trace at the 'rank'th event in the trace. |
09e86496 | 335 | * <p> |
e73a4ba5 | 336 | * A rank <= 0 is interpreted as seeking for the first event of the trace. |
7e6347b0 FC |
337 | * <p> |
338 | * If the requested rank is beyond the last trace event, the context | |
339 | * returned will yield a null event if used in a subsequent read. | |
0283f7ff | 340 | * |
e73a4ba5 GB |
341 | * @param rank |
342 | * the event rank | |
3118edf1 | 343 | * @return a context which can later be used to read the corresponding event |
c76c54bb | 344 | */ |
57a2a5ca | 345 | ITmfContext seekEvent(long rank); |
12c155f5 | 346 | |
3118edf1 FC |
347 | /** |
348 | * Position the trace at the first event with the specified timestamp. If | |
e73a4ba5 GB |
349 | * there is no event with the requested timestamp, a context pointing to the |
350 | * next chronological event is returned. | |
09e86496 FC |
351 | * <p> |
352 | * A null timestamp is interpreted as seeking for the first event of the | |
353 | * trace. | |
354 | * <p> | |
355 | * If the requested timestamp is beyond the last trace event, the context | |
356 | * returned will yield a null event if used in a subsequent read. | |
0283f7ff | 357 | * |
e73a4ba5 GB |
358 | * @param timestamp |
359 | * the timestamp of desired event | |
3118edf1 | 360 | * @return a context which can later be used to read the corresponding event |
3bd46eef | 361 | * @since 2.0 |
3118edf1 | 362 | */ |
57a2a5ca | 363 | ITmfContext seekEvent(ITmfTimestamp timestamp); |
3118edf1 FC |
364 | |
365 | /** | |
7e6347b0 FC |
366 | * Position the trace at the event located at the specified ratio in the |
367 | * trace file. | |
09e86496 | 368 | * <p> |
7e6347b0 FC |
369 | * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left |
370 | * voluntarily vague. Typically, it would refer to the event proportional | |
371 | * rank (arguably more intuitive) or timestamp in the trace file. | |
0283f7ff | 372 | * |
e73a4ba5 GB |
373 | * @param ratio |
374 | * the proportional 'rank' in the trace | |
3118edf1 FC |
375 | * @return a context which can later be used to read the corresponding event |
376 | */ | |
57a2a5ca | 377 | ITmfContext seekEvent(double ratio); |
3118edf1 | 378 | |
66262ad8 BH |
379 | /** |
380 | * Returns the initial range offset | |
381 | * | |
382 | * @return the initial range offset | |
383 | * @since 2.0 | |
384 | */ | |
57a2a5ca | 385 | ITmfTimestamp getInitialRangeOffset(); |
bb52f9bc GB |
386 | |
387 | /** | |
388 | * Returns the ID of the host this trace is from. The host ID is not | |
389 | * necessarily the hostname, but should be a unique identifier for the | |
390 | * machine on which the trace was taken. It can be used to determine if two | |
391 | * traces were taken on the exact same machine (timestamp are already | |
392 | * synchronized, resources with same id are the same if taken at the same | |
393 | * time, etc). | |
394 | * | |
395 | * @return The host id of this trace | |
396 | * @since 3.0 | |
397 | */ | |
e73a4ba5 GB |
398 | String getHostId(); |
399 | ||
400 | // ------------------------------------------------------------------------ | |
401 | // Timestamp transformation functions | |
402 | // ------------------------------------------------------------------------ | |
403 | ||
404 | /** | |
405 | * Returns the timestamp transformation for this trace | |
406 | * | |
407 | * @return the timestamp transform | |
408 | * @since 3.0 | |
409 | */ | |
410 | ITmfTimestampTransform getTimestampTransform(); | |
411 | ||
412 | /** | |
413 | * Sets the trace's timestamp transform | |
414 | * | |
415 | * @param tt | |
416 | * The timestamp transform for all timestamps of this trace | |
417 | * @since 3.0 | |
418 | */ | |
419 | void setTimestampTransform(final ITmfTimestampTransform tt); | |
420 | ||
421 | /** | |
422 | * Creates a timestamp for this trace, using the transformation formula | |
423 | * | |
424 | * @param ts | |
425 | * The time in long with which to create the timestamp | |
426 | * @return The new timestamp | |
427 | * @since 3.0 | |
428 | */ | |
429 | ITmfTimestamp createTimestamp(long ts); | |
bb52f9bc | 430 | |
8c8bf09f | 431 | } |