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