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 *******************************************************************************/
16 package org
.eclipse
.linuxtools
.tmf
.core
.trace
;
18 import org
.eclipse
.core
.resources
.IProject
;
19 import org
.eclipse
.core
.resources
.IResource
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
22 import org
.eclipse
.jdt
.annotation
.Nullable
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModule
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfEventProvider
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.ITmfTimestampTransform
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.indexer
.ITmfTraceIndexer
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.location
.ITmfLocation
;
34 * The event stream structure in TMF. In its basic form, a trace has:
36 * <li> an associated Eclipse resource
37 * <li> a path to its location on the file system
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
42 * Concrete ITmfTrace classes have to provide a parameter-less constructor and
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.
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.
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.
55 * <b>Example 1</b>: Process a whole trace
57 * ITmfContext context = trace.seekEvent(0);
58 * ITmfEvent event = trace.getNext(context);
59 * while (event != null) {
60 * processEvent(event);
61 * event = trace.getNext(context);
64 * <b>Example 2</b>: Process 50 events starting from the 1000th event
66 * int nbEventsRead = 0;
67 * ITmfContext context = trace.seekEvent(1000);
68 * ITmfEvent event = trace.getNext(context);
69 * while (event != null && nbEventsRead < 50) {
71 * processEvent(event);
72 * event = trace.getNext(context);
75 * <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
77 * ITmfTimestamp startTime = ...;
78 * ITmfTimestamp endTime = ...;
79 * ITmfContext context = trace.seekEvent(startTime);
80 * ITmfEvent event = trace.getNext(context);
81 * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
82 * processEvent(event);
83 * event = trace.getNext(context);
87 * A trace is also an event provider so it can process event requests
88 * asynchronously (and coalesce compatible, concurrent requests).
91 * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for
94 * ITmfRequest request = new TmfEventRequest<MyEventType>(MyEventType.class) {
96 * public void handleData(MyEventType event) {
97 * super.handleData(event);
98 * processEvent(event);
102 * public void handleCompleted() {
104 * super.handleCompleted();
108 * fTrace.handleRequest(request);
110 * request.waitForCompletion();
115 * @author Francois Chouinard
119 * @see ITmfTraceIndexer
120 * @see ITmfEventParser
122 public interface ITmfTrace
extends ITmfEventProvider
{
124 // ------------------------------------------------------------------------
126 // ------------------------------------------------------------------------
129 * The default trace cache size
131 public static final int DEFAULT_TRACE_CACHE_SIZE
= 1000;
133 // ------------------------------------------------------------------------
135 // ------------------------------------------------------------------------
138 * Initialize a newly instantiated "empty" trace object. This is used to
139 * properly parameterize an ITmfTrace instantiated with its parameterless
142 * Typically, the parameterless constructor will provide the block size and
143 * its associated parser and indexer.
150 * the trace event type
151 * @throws TmfTraceException
152 * If we couldn't open the trace
154 void initTrace(IResource resource
, String path
, Class
<?
extends ITmfEvent
> type
) throws TmfTraceException
;
157 * Validate that the trace is of the correct type. The implementation should
158 * return a TraceValidationStatus to indicate success with a certain level
162 * the eclipse project
166 * @return an IStatus object with validation result. Use severity OK to
168 * @see {@link TraceValidationStatus}
171 IStatus
validate(IProject project
, String path
);
173 // ------------------------------------------------------------------------
175 // ------------------------------------------------------------------------
178 * @return the trace event type
180 Class
<?
extends ITmfEvent
> getEventType();
183 * @return the associated trace resource
185 IResource
getResource();
188 * @return the trace path
193 * @return the trace cache size
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
202 * @param waitForCompletion
203 * Should we block the caller until indexing is finished, or not.
206 void indexTrace(boolean waitForCompletion
);
208 // ------------------------------------------------------------------------
210 // ------------------------------------------------------------------------
213 * Returns an analysis module with the given 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.
222 IAnalysisModule
getAnalysisModule(String id
);
225 * Get a list of all analysis modules currently available for this trace.
227 * @return An iterable view of the analysis modules
231 Iterable
<IAnalysisModule
> getAnalysisModules();
234 * Get an analysis module belonging to this trace, with the specified ID and
238 * Returned modules must extend this class
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.
246 <T
extends IAnalysisModule
> T
getAnalysisModuleOfClass(Class
<T
> moduleClass
, String id
);
249 * Return the analysis modules that are of a given class. Module are already
250 * casted to the requested class.
253 * Returned modules must extend this class
254 * @return List of modules of class moduleClass
258 <T
> Iterable
<T
> getAnalysisModulesOfClass(Class
<T
> moduleClass
);
260 // ------------------------------------------------------------------------
261 // Trace characteristics getters
262 // ------------------------------------------------------------------------
265 * @return the number of events in the trace
270 * @return the trace time range
273 TmfTimeRange
getTimeRange();
276 * @return the timestamp of the first trace event
279 ITmfTimestamp
getStartTime();
282 * @return the timestamp of the last trace event
285 ITmfTimestamp
getEndTime();
288 * @return the streaming interval in ms (0 if not a streaming trace)
290 long getStreamingInterval();
292 // ------------------------------------------------------------------------
293 // Trace positioning getters
294 // ------------------------------------------------------------------------
297 * @return the current trace location
300 ITmfLocation
getCurrentLocation();
303 * Returns the ratio (proportion) corresponding to the specified location.
306 * a trace specific location
307 * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
310 double getLocationRatio(ITmfLocation location
);
312 // ------------------------------------------------------------------------
313 // SeekEvent operations (returning a trace context)
314 // ------------------------------------------------------------------------
317 * Position the trace at the specified (trace specific) location.
319 * A null location is interpreted as seeking for the first event of the
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).
327 * the trace specific location
328 * @return a context which can later be used to read the corresponding event
331 ITmfContext
seekEvent(ITmfLocation location
);
334 * Position the trace at the 'rank'th event in the trace.
336 * A rank <= 0 is interpreted as seeking for the first event of the trace.
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.
343 * @return a context which can later be used to read the corresponding event
345 ITmfContext
seekEvent(long rank
);
348 * Position the trace at the first event with the specified timestamp. If
349 * there is no event with the requested timestamp, a context pointing to the
350 * next chronological event is returned.
352 * A null timestamp is interpreted as seeking for the first event of the
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.
359 * the timestamp of desired event
360 * @return a context which can later be used to read the corresponding event
363 ITmfContext
seekEvent(ITmfTimestamp timestamp
);
366 * Position the trace at the event located at the specified ratio in the
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.
374 * the proportional 'rank' in the trace
375 * @return a context which can later be used to read the corresponding event
377 ITmfContext
seekEvent(double ratio
);
380 * Returns the initial range offset
382 * @return the initial range offset
385 ITmfTimestamp
getInitialRangeOffset();
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
395 * @return The host id of this trace
400 // ------------------------------------------------------------------------
401 // Timestamp transformation functions
402 // ------------------------------------------------------------------------
405 * Returns the timestamp transformation for this trace
407 * @return the timestamp transform
410 ITmfTimestampTransform
getTimestampTransform();
413 * Sets the trace's timestamp transform
416 * The timestamp transform for all timestamps of this trace
419 void setTimestampTransform(final ITmfTimestampTransform tt
);
422 * Creates a timestamp for this trace, using the transformation formula
425 * The time in long with which to create the timestamp
426 * @return The new timestamp
429 ITmfTimestamp
createTimestamp(long ts
);