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