1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 Ericsson, École Polytechnique de Montréal
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
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 * Geneviève Bastien - Added timestamp transforms and timestamp
14 * Patrick Tasse - Add support for folder elements
15 *******************************************************************************/
17 package org
.eclipse
.linuxtools
.tmf
.core
.trace
;
19 import org
.eclipse
.core
.resources
.IProject
;
20 import org
.eclipse
.core
.resources
.IResource
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.jdt
.annotation
.NonNull
;
23 import org
.eclipse
.jdt
.annotation
.Nullable
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModule
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfEventProvider
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.ITmfTimestampTransform
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.indexer
.ITmfTraceIndexer
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.ITmfLocation
;
35 * The event stream structure in TMF. In its basic form, a trace has:
37 * <li> an associated Eclipse resource
38 * <li> a path to its location on the file system
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
43 * Concrete ITmfTrace classes have to provide a parameter-less constructor and
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.
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.
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.
56 * <b>Example 1</b>: Process a whole trace
58 * ITmfContext context = trace.seekEvent(0);
59 * ITmfEvent event = trace.getNext(context);
60 * while (event != null) {
61 * processEvent(event);
62 * event = trace.getNext(context);
65 * <b>Example 2</b>: Process 50 events starting from the 1000th event
67 * int nbEventsRead = 0;
68 * ITmfContext context = trace.seekEvent(1000);
69 * ITmfEvent event = trace.getNext(context);
70 * while (event != null && nbEventsRead < 50) {
72 * processEvent(event);
73 * event = trace.getNext(context);
76 * <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
78 * ITmfTimestamp startTime = ...;
79 * ITmfTimestamp endTime = ...;
80 * ITmfContext context = trace.seekEvent(startTime);
81 * ITmfEvent event = trace.getNext(context);
82 * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
83 * processEvent(event);
84 * event = trace.getNext(context);
88 * A trace is also an event provider so it can process event requests
89 * asynchronously (and coalesce compatible, concurrent requests).
92 * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for
95 * ITmfRequest request = new TmfEventRequest<MyEventType>(MyEventType.class) {
97 * public void handleData(MyEventType event) {
98 * super.handleData(event);
99 * processEvent(event);
103 * public void handleCompleted() {
105 * super.handleCompleted();
109 * fTrace.handleRequest(request);
111 * request.waitForCompletion();
116 * @author Francois Chouinard
120 * @see ITmfTraceIndexer
121 * @see ITmfEventParser
123 public interface ITmfTrace
extends ITmfEventProvider
{
125 // ------------------------------------------------------------------------
127 // ------------------------------------------------------------------------
130 * The default trace cache size
132 public static final int DEFAULT_TRACE_CACHE_SIZE
= 1000;
134 // ------------------------------------------------------------------------
136 // ------------------------------------------------------------------------
139 * Initialize a newly instantiated "empty" trace object. This is used to
140 * properly parameterize an ITmfTrace instantiated with its parameterless
143 * Typically, the parameterless constructor will provide the block size and
144 * its associated parser and indexer.
151 * the trace event type
152 * @throws TmfTraceException
153 * If we couldn't open the trace
155 void initTrace(IResource resource
, String path
, Class
<?
extends ITmfEvent
> type
) throws TmfTraceException
;
158 * Initialize a newly instantiated "empty" trace object. This is used to
159 * properly parameterize an ITmfTrace instantiated with its parameterless
162 * Typically, the parameterless constructor will provide the block size and
163 * its associated parser and indexer.
170 * the trace event type
173 * @throws TmfTraceException
174 * If we couldn't open the trace
176 void initTrace(IResource resource
, String path
, Class
<?
extends ITmfEvent
> type
, String name
) throws TmfTraceException
;
179 * Validate that the trace is of the correct type. The implementation should
180 * return a TraceValidationStatus to indicate success with a certain level
184 * the eclipse project
188 * @return an IStatus object with validation result. Use severity OK to
190 * @see {@link TraceValidationStatus}
193 IStatus
validate(IProject project
, String path
);
195 // ------------------------------------------------------------------------
197 // ------------------------------------------------------------------------
200 * @return the trace event type
202 Class
<?
extends ITmfEvent
> getEventType();
205 * @return the associated trace resource
207 IResource
getResource();
210 * @return the trace path
215 * @return the trace cache size
220 * Index the trace. Depending on the trace type, this could be done at the
221 * constructor or initTrace phase too, so this could be implemented as a
224 * @param waitForCompletion
225 * Should we block the caller until indexing is finished, or not.
228 void indexTrace(boolean waitForCompletion
);
230 // ------------------------------------------------------------------------
232 // ------------------------------------------------------------------------
235 * Returns an analysis module with the given ID.
238 * The analysis module ID
239 * @return The {@link IAnalysisModule} object, or null if an analysis with
240 * the given ID does no exist.
244 IAnalysisModule
getAnalysisModule(String id
);
247 * Get a list of all analysis modules currently available for this trace.
249 * @return An iterable view of the analysis modules
253 Iterable
<IAnalysisModule
> getAnalysisModules();
256 * Get an analysis module belonging to this trace, with the specified ID and
260 * Returned modules must extend this class
262 * The ID of the analysis module
263 * @return The analysis module with specified class and ID, or null if no
264 * such module exists.
268 <T
extends IAnalysisModule
> T
getAnalysisModuleOfClass(Class
<T
> moduleClass
, String id
);
271 * Return the analysis modules that are of a given class. Module are already
272 * casted to the requested class.
275 * Returned modules must extend this class
276 * @return List of modules of class moduleClass
280 <T
> Iterable
<T
> getAnalysisModulesOfClass(Class
<T
> moduleClass
);
282 // ------------------------------------------------------------------------
283 // Trace characteristics getters
284 // ------------------------------------------------------------------------
287 * @return the number of events in the trace
292 * @return the trace time range
295 TmfTimeRange
getTimeRange();
298 * @return the timestamp of the first trace event
301 ITmfTimestamp
getStartTime();
304 * @return the timestamp of the last trace event
307 ITmfTimestamp
getEndTime();
310 * @return the streaming interval in ms (0 if not a streaming trace)
312 long getStreamingInterval();
314 // ------------------------------------------------------------------------
315 // Trace positioning getters
316 // ------------------------------------------------------------------------
319 * @return the current trace location
322 ITmfLocation
getCurrentLocation();
325 * Returns the ratio (proportion) corresponding to the specified location.
328 * a trace specific location
329 * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
332 double getLocationRatio(ITmfLocation location
);
334 // ------------------------------------------------------------------------
335 // SeekEvent operations (returning a trace context)
336 // ------------------------------------------------------------------------
339 * Position the trace at the specified (trace specific) location.
341 * A null location is interpreted as seeking for the first event of the
344 * If not null, the location requested must be valid otherwise the returned
345 * context is undefined (up to the implementation to recover if possible).
349 * the trace specific location
350 * @return a context which can later be used to read the corresponding event
353 ITmfContext
seekEvent(ITmfLocation location
);
356 * Position the trace at the 'rank'th event in the trace.
358 * A rank <= 0 is interpreted as seeking for the first event of the trace.
360 * If the requested rank is beyond the last trace event, the context
361 * returned will yield a null event if used in a subsequent read.
365 * @return a context which can later be used to read the corresponding event
367 ITmfContext
seekEvent(long rank
);
370 * Position the trace at the first event with the specified timestamp. If
371 * there is no event with the requested timestamp, a context pointing to the
372 * next chronological event is returned.
374 * A null timestamp is interpreted as seeking for the first event of the
377 * If the requested timestamp is beyond the last trace event, the context
378 * returned will yield a null event if used in a subsequent read.
381 * the timestamp of desired event
382 * @return a context which can later be used to read the corresponding event
385 ITmfContext
seekEvent(ITmfTimestamp timestamp
);
388 * Position the trace at the event located at the specified ratio in the
391 * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left
392 * voluntarily vague. Typically, it would refer to the event proportional
393 * rank (arguably more intuitive) or timestamp in the trace file.
396 * the proportional 'rank' in the trace
397 * @return a context which can later be used to read the corresponding event
399 ITmfContext
seekEvent(double ratio
);
402 * Returns the initial range offset
404 * @return the initial range offset
407 ITmfTimestamp
getInitialRangeOffset();
410 * Returns the ID of the host this trace is from. The host ID is not
411 * necessarily the hostname, but should be a unique identifier for the
412 * machine on which the trace was taken. It can be used to determine if two
413 * traces were taken on the exact same machine (timestamp are already
414 * synchronized, resources with same id are the same if taken at the same
417 * @return The host id of this trace
422 // ------------------------------------------------------------------------
423 // Timestamp transformation functions
424 // ------------------------------------------------------------------------
427 * Returns the timestamp transformation for this trace
429 * @return the timestamp transform
432 ITmfTimestampTransform
getTimestampTransform();
435 * Sets the trace's timestamp transform
438 * The timestamp transform for all timestamps of this trace
441 void setTimestampTransform(final ITmfTimestampTransform tt
);
444 * Creates a timestamp for this trace, using the transformation formula
447 * The time in nanoseconds with which to create the timestamp
448 * @return The new timestamp
451 ITmfTimestamp
createTimestamp(long ts
);