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