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
.tracecompass
.tmf
.core
.trace
;
19 import org
.eclipse
.core
.resources
.IFile
;
20 import org
.eclipse
.core
.resources
.IProject
;
21 import org
.eclipse
.core
.resources
.IResource
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.jdt
.annotation
.NonNull
;
24 import org
.eclipse
.jdt
.annotation
.Nullable
;
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
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
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
;
38 * The event stream structure in TMF. In its basic form, a trace has:
40 * <li> an associated Eclipse resource
41 * <li> a path to its location on the file system
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
46 * Concrete ITmfTrace classes have to provide a parameter-less constructor and
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.
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.
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.
59 * <b>Example 1</b>: Process a whole trace
61 * ITmfContext context = trace.seekEvent(0);
62 * ITmfEvent event = trace.getNext(context);
63 * while (event != null) {
64 * processEvent(event);
65 * event = trace.getNext(context);
68 * <b>Example 2</b>: Process 50 events starting from the 1000th event
70 * int nbEventsRead = 0;
71 * ITmfContext context = trace.seekEvent(1000);
72 * ITmfEvent event = trace.getNext(context);
73 * while (event != null && nbEventsRead < 50) {
75 * processEvent(event);
76 * event = trace.getNext(context);
79 * <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
81 * ITmfTimestamp startTime = ...;
82 * ITmfTimestamp endTime = ...;
83 * ITmfContext context = trace.seekEvent(startTime);
84 * ITmfEvent event = trace.getNext(context);
85 * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
86 * processEvent(event);
87 * event = trace.getNext(context);
91 * A trace is also an event provider so it can process event requests
92 * asynchronously (and coalesce compatible, concurrent requests).
95 * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for
98 * ITmfRequest request = new TmfEventRequest<MyEventType>(MyEventType.class) {
100 * public void handleData(MyEventType event) {
101 * super.handleData(event);
102 * processEvent(event);
106 * public void handleCompleted() {
108 * super.handleCompleted();
112 * fTrace.handleRequest(request);
114 * request.waitForCompletion();
119 * @author Francois Chouinard
123 * @see ITmfTraceIndexer
124 * @see ITmfEventParser
126 public interface ITmfTrace
extends ITmfEventProvider
{
128 // ------------------------------------------------------------------------
130 // ------------------------------------------------------------------------
133 * The default trace cache size
135 public static final int DEFAULT_TRACE_CACHE_SIZE
= 1000;
137 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
142 * Initialize a newly instantiated "empty" trace object. This is used to
143 * properly parameterize an ITmfTrace instantiated with its parameterless
146 * Typically, the parameterless constructor will provide the block size and
147 * its associated parser and indexer.
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.
156 * the trace event type
157 * @throws TmfTraceException
158 * If we couldn't open the trace
160 void initTrace(IResource resource
, String path
, Class
<?
extends ITmfEvent
> type
) throws TmfTraceException
;
163 * Initialize a newly instantiated "empty" trace object. This is used to
164 * properly parameterize an ITmfTrace instantiated with its parameterless
167 * Typically, the parameterless constructor will provide the block size and
168 * its associated parser and indexer.
175 * the trace event type
180 * @throws TmfTraceException
181 * If we couldn't open the trace
183 void initTrace(IResource resource
, String path
, Class
<?
extends ITmfEvent
> type
, String name
, String traceTypeId
) throws TmfTraceException
;
186 * Validate that the trace is of the correct type. The implementation should
187 * return a TraceValidationStatus to indicate success with a certain level
191 * the eclipse project
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.
197 * @return an IStatus object with validation result. Use severity OK to
199 * @see TraceValidationStatus
201 IStatus
validate(IProject project
, String path
);
203 // ------------------------------------------------------------------------
205 // ------------------------------------------------------------------------
208 * @return the associated trace resource
210 IResource
getResource();
213 * Get the trace type id
215 * @return the trace type id
217 @Nullable String
getTraceTypeId();
220 * @return the trace path
225 * @return the trace cache size
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
234 * @param waitForCompletion
235 * Should we block the caller until indexing is finished, or not.
237 void indexTrace(boolean waitForCompletion
);
239 // ------------------------------------------------------------------------
241 // ------------------------------------------------------------------------
244 * Returns an analysis module with the given 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.
251 @Nullable IAnalysisModule
getAnalysisModule(String id
);
254 * Get a list of all analysis modules currently available for this trace.
256 * @return An iterable view of the analysis modules
258 @NonNull Iterable
<@NonNull IAnalysisModule
> getAnalysisModules();
260 // ------------------------------------------------------------------------
262 // ------------------------------------------------------------------------
265 * Return the pre-defined set of event aspects exposed by this trace.
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}.
270 * @return The event aspects for this trace
272 @NonNull Iterable
<@NonNull ITmfEventAspect
> getEventAspects();
274 // ------------------------------------------------------------------------
275 // Trace characteristics getters
276 // ------------------------------------------------------------------------
279 * @return the number of events in the trace
284 * @return the trace time range
286 @NonNull TmfTimeRange
getTimeRange();
289 * @return the timestamp of the first trace event
291 @NonNull ITmfTimestamp
getStartTime();
294 * @return the timestamp of the last trace event
296 @NonNull ITmfTimestamp
getEndTime();
299 * @return the streaming interval in ms (0 if not a streaming trace)
301 long getStreamingInterval();
303 // ------------------------------------------------------------------------
304 // Trace positioning getters
305 // ------------------------------------------------------------------------
308 * @return the current trace location
310 ITmfLocation
getCurrentLocation();
313 * Returns the ratio (proportion) corresponding to the specified location.
316 * a trace specific location
317 * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
319 double getLocationRatio(ITmfLocation location
);
321 // ------------------------------------------------------------------------
322 // SeekEvent operations (returning a trace context)
323 // ------------------------------------------------------------------------
326 * Position the trace at the specified (trace specific) location.
328 * A null location is interpreted as seeking for the first event of the
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).
336 * the trace specific location
337 * @return a context which can later be used to read the corresponding event
339 ITmfContext
seekEvent(ITmfLocation location
);
342 * Position the trace at the 'rank'th event in the trace.
344 * A rank <= 0 is interpreted as seeking for the first event of the trace.
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.
351 * @return a context which can later be used to read the corresponding event
353 ITmfContext
seekEvent(long rank
);
356 * Position the trace at the first event with the specified timestamp. If
357 * there is no event with the requested timestamp, a context pointing to the
358 * next chronological event is returned.
360 * A null timestamp is interpreted as seeking for the first event of the
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.
367 * the timestamp of desired event
368 * @return a context which can later be used to read the corresponding event
370 ITmfContext
seekEvent(ITmfTimestamp timestamp
);
373 * Position the trace at the event located at the specified ratio in the
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.
381 * the proportional 'rank' in the trace
382 * @return a context which can later be used to read the corresponding event
384 ITmfContext
seekEvent(double ratio
);
387 * Returns the initial range offset
389 * @return the initial range offset
391 ITmfTimestamp
getInitialRangeOffset();
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
401 * @return The host id of this trace
403 @NonNull String
getHostId();
405 // ------------------------------------------------------------------------
406 // Timestamp transformation functions
407 // ------------------------------------------------------------------------
410 * Returns the timestamp transformation for this trace
412 * @return the timestamp transform
414 ITmfTimestampTransform
getTimestampTransform();
417 * Sets the trace's timestamp transform
420 * The timestamp transform for all timestamps of this trace
422 void setTimestampTransform(final ITmfTimestampTransform tt
);
425 * Creates a timestamp for this trace, using the transformation formula
428 * The time in nanoseconds with which to create the timestamp
429 * @return The new timestamp
431 @NonNull ITmfTimestamp
createTimestamp(long ts
);
434 * Build a new trace context.
437 * The selected time range
439 * The visible window's time range
441 * The file representing the selected editor
443 * The currently applied filter. 'null' for none.
444 * @return The newly created context
447 default TmfTraceContext
createTraceContext(@NonNull TmfTimeRange selection
, @NonNull TmfTimeRange windowRange
, @Nullable IFile editorFile
, @Nullable ITmfFilter filter
) {
448 return new TmfTraceContext(selection
, windowRange
, editorFile
, filter
);