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