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 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.trace
;
16 import java
.io
.FileNotFoundException
;
18 import org
.eclipse
.core
.resources
.IProject
;
19 import org
.eclipse
.core
.resources
.IResource
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.component
.ITmfDataProvider
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
;
27 * <b><u>ITmfTrace</u></b>
29 * The event stream structure in TMF. In its basic form, a trace has:
31 * <li> an associated Eclipse resource
32 * <li> a path to its location on the file system
33 * <li> the type of the events it contains
34 * <li> the number of events it contains
35 * <li> the time range (span) of the events it contains
37 * Concrete ITmfTrace classes have to provide a parameter-less constructor and
38 * an initialization method (<i>initTrace</i>) if they are to be opened from
39 * the Project View. Also, a validation method (<i>validate</i>) has to be
40 * provided to ensure that the trace is of the correct type.
42 * A trace can be accessed simultaneously from multiple threads by various
43 * application components. To avoid obvious multi-threading issues, the trace
44 * uses an ITmfContext as a synchronization aid for its read operations.
46 * A proper ITmfContext can be obtained by performing a seek operation on the
47 * trace. Seek operations can be performed for a particular event (by rank or
48 * timestamp) or for a plain trace location.
50 * <b>Example 1</b>: Process a whole trace
52 * ITmfContext context = trace.seekEvent(0);
53 * ITmfEvent event = trace.getEvent(context);
54 * while (event != null) {
55 * processEvent(event);
56 * event = trace.getEvent(context);
59 * <b>Example 2</b>: Process 50 events starting from the 1000th event
61 * int nbEventsRead = 0;
62 * ITmfContext context = trace.seekEvent(1000);
63 * ITmfEvent event = trace.getEvent(context);
64 * while (event != null && nbEventsRead < 50) {
66 * processEvent(event);
67 * event = trace.getEvent(context);
70 * <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
72 * ITmfTimestamp startTime = ...;
73 * ITmfTimestamp endTime = ...;
74 * ITmfContext context = trace.seekEvent(startTime);
75 * ITmfEvent event = trace.getEvent(context);
76 * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
77 * processEvent(event);
78 * event = trace.getEvent(context);
81 * A trace is also an event provider so it can process event requests
82 * asynchronously (and coalesce compatible, concurrent requests).
85 * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for variants)
87 * ITmfRequest request = new TmfEventRequest<MyEventType>(MyEventType.class) {
89 * public void handleData(MyEventType event) {
90 * super.handleData(event);
91 * processEvent(event);
94 * public void handleCompleted() {
96 * super.handleCompleted();
100 * fTrace.handleRequest(request);
102 * request.waitForCompletion();
106 * @see ITmfEventProvider
107 * @see ITmfEventRequest
109 public interface ITmfTrace
<T
extends ITmfEvent
> extends ITmfDataProvider
<T
> {
111 // ------------------------------------------------------------------------
113 // ------------------------------------------------------------------------
116 * Initialize a newly instantiated "empty" trace object. This is used to
117 * properly parameterize an ITmfTrace instantiated with its parameterless
120 * Typically, the parameterless constructor will provide the block size
121 * and its associated parser and indexer.
123 * @param resource the trace resource
124 * @param path the trace path
125 * @param type the trace event type
126 * @throws FileNotFoundException
128 public void initTrace(IResource resource
, String path
, Class
<T
> type
) throws FileNotFoundException
;
131 * Validate that the trace is of the correct type.
133 * @param project the eclipse project
134 * @param path the trace path
136 * @return true if trace is valid
138 public boolean validate(IProject project
, String path
);
140 // ------------------------------------------------------------------------
142 // ------------------------------------------------------------------------
145 * @return the trace event type
147 public Class
<T
> getEventType();
150 * @return the associated trace resource
152 public IResource
getResource();
155 * @return the trace path
157 public String
getPath();
160 * @return the trace cache size
162 public int getCacheSize();
164 // ------------------------------------------------------------------------
165 // Trace characteristics getters
166 // ------------------------------------------------------------------------
169 * @return the number of events in the trace
171 public long getNbEvents();
174 * @return the trace time range
176 public TmfTimeRange
getTimeRange();
179 * @return the timestamp of the first trace event
181 public ITmfTimestamp
getStartTime();
184 * @return the timestamp of the last trace event
186 public ITmfTimestamp
getEndTime();
189 * @return the streaming interval in ms (0 if not a streaming trace)
191 public long getStreamingInterval();
193 // ------------------------------------------------------------------------
194 // Trace positioning getters
195 // ------------------------------------------------------------------------
198 * @return the current trace location
200 public ITmfLocation
<?
> getCurrentLocation();
203 * Returns the ratio (proportion) corresponding to the specified location.
205 * @param location a trace specific location
206 * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
208 public double getLocationRatio(ITmfLocation
<?
> location
);
210 // ------------------------------------------------------------------------
211 // SeekEvent operations (returning a trace context)
212 // ------------------------------------------------------------------------
215 * Position the trace at the specified (trace specific) location.
217 * A null location is interpreted as seeking for the first event of the
220 * If not null, the location requested must be valid otherwise the returned
221 * context is undefined (up to the implementation to recover if possible).
223 * @param location the trace specific location
224 * @return a context which can later be used to read the corresponding event
226 public ITmfContext
seekEvent(ITmfLocation
<?
> location
);
229 * Position the trace at the 'rank'th event in the trace.
231 * A rank <= 0 is interpreted as seeking for the first event of the
234 * If the requested rank is beyond the last trace event, the context
235 * returned will yield a null event if used in a subsequent read.
237 * @param rank the event rank
238 * @return a context which can later be used to read the corresponding event
240 public ITmfContext
seekEvent(long rank
);
243 * Position the trace at the first event with the specified timestamp. If
244 * there is no event with the requested timestamp, a context pointing to
245 * the next chronological event is returned.
247 * A null timestamp is interpreted as seeking for the first event of the
250 * If the requested timestamp is beyond the last trace event, the context
251 * returned will yield a null event if used in a subsequent read.
253 * @param timestamp the timestamp of desired event
254 * @return a context which can later be used to read the corresponding event
256 public ITmfContext
seekEvent(ITmfTimestamp timestamp
);
259 * Position the trace at the event located at the specified ratio in the
262 * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left
263 * voluntarily vague. Typically, it would refer to the event proportional
264 * rank (arguably more intuitive) or timestamp in the trace file.
266 * @param ratio the proportional 'rank' in the trace
267 * @return a context which can later be used to read the corresponding event
269 public ITmfContext
seekEvent(double ratio
);
271 // ------------------------------------------------------------------------
272 // Read operations (returning an actual event)
273 // ------------------------------------------------------------------------
276 * Return the event pointed by the supplied context (or null if no event
277 * left) and updates the context to point the next event.
279 * @param context the read context (will be updated)
280 * @return the event pointed to by the context
282 public ITmfEvent
readEvent(ITmfContext context
);
This page took 0.03711 seconds and 5 git commands to generate.