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