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