1 /*******************************************************************************
2 * Copyright (c) 2009, 2011, 2012 Ericsson
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 * Alexandre Montplaisir - Added State Systems support
13 * Patrick Tasse - Added coincidental cohesion APIs
14 * Francois Chouinard - Added Iterator support
15 *******************************************************************************/
17 package org
.eclipse
.linuxtools
.tmf
.core
.trace
;
19 import java
.util
.Collection
;
20 import java
.util
.Iterator
;
22 import org
.eclipse
.core
.resources
.IProject
;
23 import org
.eclipse
.core
.resources
.IResource
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfDataProvider
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.statistics
.ITmfStatistics
;
33 * The event stream structure in TMF. In its basic form, a trace has:
35 * <li> an associated Eclipse resource
36 * <li> a path to its location on the file system
37 * <li> the type of the events it contains
38 * <li> the number of events it contains
39 * <li> the time range (span) of the events it contains
41 * Concrete ITmfTrace classes have to provide a parameter-less constructor and
42 * an initialization method (<i>initTrace</i>) if they are to be opened from
43 * the Project View. Also, a validation method (<i>validate</i>) has to be
44 * provided to ensure that the trace is of the correct type.
46 * A trace can be accessed simultaneously from multiple threads by various
47 * application components. To avoid obvious multi-threading issues, the trace
48 * uses an ITmfContext as a synchronization aid for its read operations.
50 * A proper ITmfContext can be obtained by performing a seek operation on the
51 * trace. Seek operations can be performed for a particular event (by rank or
52 * timestamp) or for a plain trace location.
54 * <b>Example 1</b>: Process a whole trace
56 * ITmfContext context = trace.seekEvent(0);
57 * ITmfEvent event = trace.getNext(context);
58 * while (event != null) {
59 * processEvent(event);
60 * event = trace.getNext(context);
63 * <b>Example 1b</b>: Process a whole trace using an iterator
65 * Iterator<ITmfEvent> it = trace.iterator();
66 * while (it.hasNext()) {
67 * processEvent(it.next());
70 * <b>Example 2</b>: Process 50 events starting from the 1000th event
72 * int nbEventsRead = 0;
73 * ITmfContext context = trace.seekEvent(1000);
74 * ITmfEvent event = trace.getNext(context);
75 * while (event != null && nbEventsRead < 50) {
77 * processEvent(event);
78 * event = trace.getNext(context);
81 * <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
83 * ITmfTimestamp startTime = ...;
84 * ITmfTimestamp endTime = ...;
85 * ITmfContext context = trace.seekEvent(startTime);
86 * ITmfEvent event = trace.getNext(context);
87 * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
88 * processEvent(event);
89 * event = trace.getNext(context);
92 * A trace is also an event provider so it can process event requests
93 * asynchronously (and coalesce compatible, concurrent requests).
96 * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for variants)
98 * ITmfRequest request = new TmfEventRequest<MyEventType>(MyEventType.class) {
100 * public void handleData(MyEventType event) {
101 * super.handleData(event);
102 * processEvent(event);
105 * public void handleCompleted() {
107 * super.handleCompleted();
111 * fTrace.handleRequest(request);
113 * request.waitForCompletion();
117 * @author Francois Chouinard
122 * @see ITmfTraceIndexer
123 * @see ITmfEventParser
125 public interface ITmfTrace
extends ITmfDataProvider
{
127 // ------------------------------------------------------------------------
129 // ------------------------------------------------------------------------
132 * The default trace cache size
134 public static final int DEFAULT_TRACE_CACHE_SIZE
= 1000;
136 // ------------------------------------------------------------------------
138 // ------------------------------------------------------------------------
141 * Initialize a newly instantiated "empty" trace object. This is used to
142 * properly parameterize an ITmfTrace instantiated with its parameterless
145 * Typically, the parameterless constructor will provide the block size
146 * and its associated parser and indexer.
148 * @param resource the trace resource
149 * @param path the trace path
150 * @param type the trace event type
151 * @throws TmfTraceException If we couldn't open the trace
153 public void initTrace(IResource resource
, String path
, Class
<?
extends ITmfEvent
> type
) throws TmfTraceException
;
156 * Validate that the trace is of the correct type.
158 * @param project the eclipse project
159 * @param path the trace path
161 * @return true if trace is valid
163 public boolean validate(IProject project
, String path
);
165 // ------------------------------------------------------------------------
167 // ------------------------------------------------------------------------
170 * @return the trace event type
172 public Class
<?
extends ITmfEvent
> getEventType();
175 * @return the associated trace resource
177 public IResource
getResource();
180 * @return the trace path
182 public String
getPath();
185 * @return the trace cache size
187 public int getCacheSize();
190 * @return The statistics provider for this trace
193 public ITmfStatistics
getStatistics();
196 * Retrieve a state system that belongs to this trace
199 * The ID of the state system to retrieve.
200 * @return The state system that is associated with this trace and ID, or
201 * 'null' if such a match doesn't exist.
204 public ITmfStateSystem
getStateSystem(String id
);
207 * Return the list of existing state systems registered with this trace.
209 * @return A Collection view of the available state systems. The collection
210 * could be empty, but should not be null.
213 public Collection
<String
> listStateSystems();
215 // ------------------------------------------------------------------------
216 // Trace characteristics getters
217 // ------------------------------------------------------------------------
220 * @return the number of events in the trace
222 public long getNbEvents();
225 * @return the trace time range
227 public TmfTimeRange
getTimeRange();
230 * @return the timestamp of the first trace event
232 public ITmfTimestamp
getStartTime();
235 * @return the timestamp of the last trace event
237 public ITmfTimestamp
getEndTime();
240 * @return the streaming interval in ms (0 if not a streaming trace)
242 public long getStreamingInterval();
244 // ------------------------------------------------------------------------
245 // Trace positioning getters
246 // ------------------------------------------------------------------------
249 * @return the current trace location
251 public ITmfLocation
getCurrentLocation();
254 * Returns the ratio (proportion) corresponding to the specified location.
256 * @param location a trace specific location
257 * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
259 public double getLocationRatio(ITmfLocation location
);
261 // ------------------------------------------------------------------------
262 // SeekEvent operations (returning a trace context)
263 // ------------------------------------------------------------------------
266 * Position the trace at the specified (trace specific) location.
268 * A null location is interpreted as seeking for the first event of the
271 * If not null, the location requested must be valid otherwise the returned
272 * context is undefined (up to the implementation to recover if possible).
274 * @param location the trace specific location
275 * @return a context which can later be used to read the corresponding event
277 public ITmfContext
seekEvent(ITmfLocation location
);
280 * Position the trace at the 'rank'th event in the trace.
282 * A rank <= 0 is interpreted as seeking for the first event of the
285 * If the requested rank is beyond the last trace event, the context
286 * returned will yield a null event if used in a subsequent read.
288 * @param rank the event rank
289 * @return a context which can later be used to read the corresponding event
291 public ITmfContext
seekEvent(long rank
);
294 * Position the trace at the first event with the specified timestamp. If
295 * there is no event with the requested timestamp, a context pointing to
296 * the next chronological event is returned.
298 * A null timestamp is interpreted as seeking for the first event of the
301 * If the requested timestamp is beyond the last trace event, the context
302 * returned will yield a null event if used in a subsequent read.
304 * @param timestamp the timestamp of desired event
305 * @return a context which can later be used to read the corresponding event
307 public ITmfContext
seekEvent(ITmfTimestamp timestamp
);
310 * Position the trace at the event located at the specified ratio in the
313 * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left
314 * voluntarily vague. Typically, it would refer to the event proportional
315 * rank (arguably more intuitive) or timestamp in the trace file.
317 * @param ratio the proportional 'rank' in the trace
318 * @return a context which can later be used to read the corresponding event
320 public ITmfContext
seekEvent(double ratio
);
322 // ------------------------------------------------------------------------
324 // ------------------------------------------------------------------------
327 * Returns an iterator suitable to read a trace from the start
329 * @return a trace iterator
331 public Iterator
<ITmfEvent
> iterator();
334 * Returns an iterator suitable to read a trace from the requested location
336 * @param location the first event location in the trace
337 * @return a trace iterator
339 public Iterator
<ITmfEvent
> iterator(ITmfLocation location
);
342 * Returns an iterator suitable to read a trace from the requested rank
344 * @param rank the first event rank
345 * @return a trace iterator
347 public Iterator
<ITmfEvent
> iterator(long rank
);
350 * Returns an iterator suitable to read a trace from the requested timestamp
352 * @param timestamp the first event timestamp
353 * @return a trace iterator
355 public Iterator
<ITmfEvent
> iterator(ITmfTimestamp timestamp
);
358 * Returns an iterator suitable to read a trace from the requested 'ratio'
360 * @param ratio the first event 'ratio' (see seekEvent(double))
361 * @return a trace iterator
363 public Iterator
<ITmfEvent
> iterator(double ratio
);
365 // ------------------------------------------------------------------------
366 // Coincidental cohesion APIs: current time and range are TMF UI concepts
367 // and have nothing to do with this core API. It can probably be argued
368 // that this is also pathological coupling.
369 // TODO: Stop hacking, start designing.
370 // ------------------------------------------------------------------------
373 * Returns the initial range offset
375 * @return the initial range offset
378 public ITmfTimestamp
getInitialRangeOffset();
381 * Return the current selected time.
383 * @return the current time stamp
386 public ITmfTimestamp
getCurrentTime();
389 * Return the current selected range.
391 * @return the current time range
394 public TmfTimeRange
getCurrentRange();
This page took 0.040973 seconds and 5 git commands to generate.