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