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