[CTF] fix support for traces with per-event contexts
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / ITmfTrace.java
CommitLineData
8c8bf09f 1/*******************************************************************************
8636b448 2 * Copyright (c) 2009, 2011, 2012 Ericsson
0283f7ff 3 *
8c8bf09f
ASL
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
0283f7ff 8 *
8c8bf09f
ASL
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
8636b448 11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
b6cfa2bb
FC
12 * Alexandre Montplaisir - Added State Systems support
13 * Patrick Tasse - Added coincidental cohesion APIs
14 * Francois Chouinard - Added Iterator support
8c8bf09f
ASL
15 *******************************************************************************/
16
6c13869b 17package org.eclipse.linuxtools.tmf.core.trace;
8c8bf09f 18
a51b2b9f 19import java.util.Collection;
b6cfa2bb 20import java.util.Iterator;
a51b2b9f 21
12c155f5 22import org.eclipse.core.resources.IProject;
a1091415 23import org.eclipse.core.resources.IResource;
f17b2f70 24import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;
72f1e62a 25import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
4df4581d 26import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
6c13869b 27import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
b4f71e4a 28import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
7898bb21 29import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
200789b3 30import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
8c8bf09f
ASL
31
32/**
f17b2f70
FC
33 * The event stream structure in TMF. In its basic form, a trace has:
34 * <ul>
7e6347b0
FC
35 * <li> an associated Eclipse resource
36 * <li> a path to its location on the file system
f17b2f70
FC
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
40 * </ul>
41 * Concrete ITmfTrace classes have to provide a parameter-less constructor and
7e6347b0 42 * an initialization method (<i>initTrace</i>) if they are to be opened from
0283f7ff 43 * the Project View. Also, a validation method (<i>validate</i>) has to be
7e6347b0 44 * provided to ensure that the trace is of the correct type.
f17b2f70
FC
45 * <p>
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.
49 * <p>
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.
53 * <p>
d337369a 54 * <b>Example 1</b>: Process a whole trace
f17b2f70 55 * <pre>
7e6347b0 56 * ITmfContext context = trace.seekEvent(0);
c32744d6 57 * ITmfEvent event = trace.getNext(context);
f17b2f70 58 * while (event != null) {
d337369a 59 * processEvent(event);
c32744d6 60 * event = trace.getNext(context);
f17b2f70
FC
61 * }
62 * </pre>
b6cfa2bb
FC
63 * <b>Example 1b</b>: Process a whole trace using an iterator
64 * <pre>
65 * Iterator&lt;ITmfEvent&gt; it = trace.iterator();
66 * while (it.hasNext()) {
67 * processEvent(it.next());
68 * }
69 * </pre>
f17b2f70
FC
70 * <b>Example 2</b>: Process 50 events starting from the 1000th event
71 * <pre>
72 * int nbEventsRead = 0;
73 * ITmfContext context = trace.seekEvent(1000);
c32744d6 74 * ITmfEvent event = trace.getNext(context);
f17b2f70
FC
75 * while (event != null && nbEventsRead < 50) {
76 * nbEventsRead++;
d337369a 77 * processEvent(event);
c32744d6 78 * event = trace.getNext(context);
f17b2f70
FC
79 * }
80 * </pre>
81 * <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
82 * <pre>
83 * ITmfTimestamp startTime = ...;
84 * ITmfTimestamp endTime = ...;
85 * ITmfContext context = trace.seekEvent(startTime);
c32744d6 86 * ITmfEvent event = trace.getNext(context);
f17b2f70 87 * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
d337369a 88 * processEvent(event);
c32744d6 89 * event = trace.getNext(context);
f17b2f70
FC
90 * }
91 * </pre>
d337369a 92 * A trace is also an event provider so it can process event requests
7e6347b0 93 * asynchronously (and coalesce compatible, concurrent requests).
d337369a
FC
94 * <p>
95 * </pre>
7e6347b0 96 * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for variants)
d337369a
FC
97 * <pre>
98 * ITmfRequest request = new TmfEventRequest&lt;MyEventType&gt;(MyEventType.class) {
99 * &#64;Override
100 * public void handleData(MyEventType event) {
101 * super.handleData(event);
102 * processEvent(event);
103 * }
104 * &#64;Override
105 * public void handleCompleted() {
106 * finish();
107 * super.handleCompleted();
108 * }
109 * };
0283f7ff 110 *
d337369a
FC
111 * fTrace.handleRequest(request);
112 * if (youWant) {
113 * request.waitForCompletion();
0283f7ff 114 * }
d337369a 115 * </pre>
0283f7ff 116 *
f7703ed6 117 * @author Francois Chouinard
b6cfa2bb 118 * @version 2.0
0283f7ff 119 *
0316808c 120 * @see ITmfContext
d337369a 121 * @see ITmfEvent
0316808c
FC
122 * @see ITmfTraceIndexer
123 * @see ITmfEventParser
8c8bf09f 124 */
6256d8ad 125public interface ITmfTrace extends ITmfDataProvider {
12c155f5 126
0316808c
FC
127 // ------------------------------------------------------------------------
128 // Constants
129 // ------------------------------------------------------------------------
130
131 /**
132 * The default trace cache size
133 */
134 public static final int DEFAULT_TRACE_CACHE_SIZE = 1000;
135
8636b448
FC
136 // ------------------------------------------------------------------------
137 // Initializers
138 // ------------------------------------------------------------------------
085d898f 139
3118edf1
FC
140 /**
141 * Initialize a newly instantiated "empty" trace object. This is used to
25e48683
FC
142 * properly parameterize an ITmfTrace instantiated with its parameterless
143 * constructor.
d337369a 144 * <p>
25e48683
FC
145 * Typically, the parameterless constructor will provide the block size
146 * and its associated parser and indexer.
0283f7ff 147 *
25e48683 148 * @param resource the trace resource
3118edf1 149 * @param path the trace path
3791b5df 150 * @param type the trace event type
063f0d27 151 * @throws TmfTraceException If we couldn't open the trace
3118edf1 152 */
6256d8ad 153 public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException;
12c155f5 154
3118edf1
FC
155 /**
156 * Validate that the trace is of the correct type.
0283f7ff 157 *
3118edf1
FC
158 * @param project the eclipse project
159 * @param path the trace path
0283f7ff 160 *
3118edf1
FC
161 * @return true if trace is valid
162 */
163 public boolean validate(IProject project, String path);
12c155f5 164
8636b448 165 // ------------------------------------------------------------------------
3118edf1 166 // Basic getters
8636b448 167 // ------------------------------------------------------------------------
b0a282fb 168
abfad0aa 169 /**
25e48683 170 * @return the trace event type
12c155f5 171 */
6256d8ad 172 public Class<? extends ITmfEvent> getEventType();
12c155f5
FC
173
174 /**
25e48683 175 * @return the associated trace resource
12c155f5 176 */
3791b5df 177 public IResource getResource();
12c155f5 178
25e48683
FC
179 /**
180 * @return the trace path
181 */
182 public String getPath();
183
20658947
FC
184 /**
185 * @return the trace cache size
186 */
187 public int getCacheSize();
188
200789b3
AM
189 /**
190 * @return The statistics provider for this trace
191 * @since 2.0
192 */
193 public ITmfStatistics getStatistics();
194
7898bb21 195 /**
a51b2b9f
AM
196 * Retrieve a state system that belongs to this trace
197 *
198 * @param id
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.
202 * @since 2.0
203 */
204 public ITmfStateSystem getStateSystem(String id);
205
206 /**
207 * Return the list of existing state systems registered with this trace.
208 *
209 * @return A Collection view of the available state systems. The collection
210 * could be empty, but should not be null.
7898bb21
AM
211 * @since 2.0
212 */
a51b2b9f 213 public Collection<String> listStateSystems();
7898bb21 214
25e48683
FC
215 // ------------------------------------------------------------------------
216 // Trace characteristics getters
217 // ------------------------------------------------------------------------
218
12c155f5
FC
219 /**
220 * @return the number of events in the trace
221 */
222 public long getNbEvents();
223
224 /**
3118edf1 225 * @return the trace time range
12c155f5
FC
226 */
227 public TmfTimeRange getTimeRange();
228
3118edf1
FC
229 /**
230 * @return the timestamp of the first trace event
231 */
4df4581d 232 public ITmfTimestamp getStartTime();
12c155f5 233
3118edf1
FC
234 /**
235 * @return the timestamp of the last trace event
236 */
4df4581d 237 public ITmfTimestamp getEndTime();
62d1696a 238
13cb5f43
FC
239 /**
240 * @return the streaming interval in ms (0 if not a streaming trace)
241 */
242 public long getStreamingInterval();
243
25e48683
FC
244 // ------------------------------------------------------------------------
245 // Trace positioning getters
246 // ------------------------------------------------------------------------
1b70b6dc 247
3118edf1 248 /**
25e48683 249 * @return the current trace location
3118edf1 250 */
1e1bef82 251 public ITmfLocation getCurrentLocation();
3791b5df
FC
252
253 /**
25e48683 254 * Returns the ratio (proportion) corresponding to the specified location.
0283f7ff 255 *
25e48683
FC
256 * @param location a trace specific location
257 * @return a floating-point number between 0.0 (beginning) and 1.0 (end)
3791b5df 258 */
1e1bef82 259 public double getLocationRatio(ITmfLocation location);
3791b5df 260
8636b448 261 // ------------------------------------------------------------------------
7e6347b0 262 // SeekEvent operations (returning a trace context)
8636b448
FC
263 // ------------------------------------------------------------------------
264
12c155f5 265 /**
7e6347b0
FC
266 * Position the trace at the specified (trace specific) location.
267 * <p>
268 * A null location is interpreted as seeking for the first event of the
269 * trace.
25e48683 270 * <p>
7e6347b0
FC
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).
25e48683 273 * <p>
7e6347b0 274 * @param location the trace specific location
3118edf1 275 * @return a context which can later be used to read the corresponding event
8c8bf09f 276 */
1e1bef82 277 public ITmfContext seekEvent(ITmfLocation location);
12c155f5 278
c76c54bb 279 /**
7e6347b0 280 * Position the trace at the 'rank'th event in the trace.
09e86496 281 * <p>
7e6347b0
FC
282 * A rank <= 0 is interpreted as seeking for the first event of the
283 * trace.
284 * <p>
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.
0283f7ff 287 *
7e6347b0 288 * @param rank the event rank
3118edf1 289 * @return a context which can later be used to read the corresponding event
c76c54bb 290 */
7e6347b0 291 public ITmfContext seekEvent(long rank);
12c155f5 292
3118edf1
FC
293 /**
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
09e86496
FC
296 * the next chronological event is returned.
297 * <p>
298 * A null timestamp is interpreted as seeking for the first event of the
299 * trace.
300 * <p>
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.
0283f7ff 303 *
3118edf1
FC
304 * @param timestamp the timestamp of desired event
305 * @return a context which can later be used to read the corresponding event
306 */
307 public ITmfContext seekEvent(ITmfTimestamp timestamp);
308
309 /**
7e6347b0
FC
310 * Position the trace at the event located at the specified ratio in the
311 * trace file.
09e86496 312 * <p>
7e6347b0
FC
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.
0283f7ff 316 *
7e6347b0 317 * @param ratio the proportional 'rank' in the trace
3118edf1
FC
318 * @return a context which can later be used to read the corresponding event
319 */
7e6347b0 320 public ITmfContext seekEvent(double ratio);
3118edf1 321
b6cfa2bb
FC
322 // ------------------------------------------------------------------------
323 // Iterator support
324 // ------------------------------------------------------------------------
325
326 /**
327 * Returns an iterator suitable to read a trace from the start
328 *
329 * @return a trace iterator
330 */
331 public Iterator<ITmfEvent> iterator();
332
333 /**
334 * Returns an iterator suitable to read a trace from the requested location
335 *
336 * @param location the first event location in the trace
337 * @return a trace iterator
338 */
339 public Iterator<ITmfEvent> iterator(ITmfLocation location);
340
341 /**
342 * Returns an iterator suitable to read a trace from the requested rank
343 *
344 * @param rank the first event rank
345 * @return a trace iterator
346 */
347 public Iterator<ITmfEvent> iterator(long rank);
348
349 /**
350 * Returns an iterator suitable to read a trace from the requested timestamp
351 *
352 * @param timestamp the first event timestamp
353 * @return a trace iterator
354 */
355 public Iterator<ITmfEvent> iterator(ITmfTimestamp timestamp);
356
357 /**
358 * Returns an iterator suitable to read a trace from the requested 'ratio'
359 *
360 * @param ratio the first event 'ratio' (see seekEvent(double))
361 * @return a trace iterator
362 */
363 public Iterator<ITmfEvent> iterator(double ratio);
364
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 // ------------------------------------------------------------------------
371
66262ad8
BH
372 /**
373 * Returns the initial range offset
374 *
375 * @return the initial range offset
376 * @since 2.0
377 */
378 public ITmfTimestamp getInitialRangeOffset();
379
d7ee91bb
PT
380 /**
381 * Return the current selected time.
382 *
383 * @return the current time stamp
384 * @since 2.0
385 */
386 public ITmfTimestamp getCurrentTime();
387
388 /**
389 * Return the current selected range.
390 *
391 * @return the current time range
392 * @since 2.0
393 */
394 public TmfTimeRange getCurrentRange();
8c8bf09f 395}
This page took 0.061863 seconds and 5 git commands to generate.