Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
e73a4ba5 | 2 | * Copyright (c) 2009, 2013 Ericsson, École Polytechnique de Montréal |
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 |
e73a4ba5 GB |
12 | * Geneviève Bastien - Added timestamp transforms and timestamp |
13 | * creation functions | |
8c8bf09f ASL |
14 | *******************************************************************************/ |
15 | ||
6c13869b | 16 | package org.eclipse.linuxtools.tmf.core.trace; |
8c8bf09f | 17 | |
35c160d9 AM |
18 | import java.util.Collections; |
19 | import java.util.Map; | |
a51b2b9f | 20 | |
12c155f5 | 21 | import org.eclipse.core.resources.IProject; |
a1091415 | 22 | import org.eclipse.core.resources.IResource; |
a94410d9 | 23 | import org.eclipse.core.runtime.IStatus; |
c068a752 | 24 | import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule; |
fd3f1eff | 25 | import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider; |
72f1e62a | 26 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
b4f71e4a | 27 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
7898bb21 | 28 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
5237a931 | 29 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems; |
200789b3 | 30 | import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; |
e73a4ba5 | 31 | import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform; |
3bd46eef AM |
32 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
33 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; | |
a3db8436 AM |
34 | import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer; |
35 | import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation; | |
8c8bf09f ASL |
36 | |
37 | /** | |
f17b2f70 FC |
38 | * The event stream structure in TMF. In its basic form, a trace has: |
39 | * <ul> | |
7e6347b0 FC |
40 | * <li> an associated Eclipse resource |
41 | * <li> a path to its location on the file system | |
f17b2f70 FC |
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 | |
e73a4ba5 GB |
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. | |
f17b2f70 FC |
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> | |
d337369a | 59 | * <b>Example 1</b>: Process a whole trace |
f17b2f70 | 60 | * <pre> |
7e6347b0 | 61 | * ITmfContext context = trace.seekEvent(0); |
c32744d6 | 62 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 | 63 | * while (event != null) { |
d337369a | 64 | * processEvent(event); |
c32744d6 | 65 | * event = trace.getNext(context); |
f17b2f70 FC |
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); | |
c32744d6 | 72 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 FC |
73 | * while (event != null && nbEventsRead < 50) { |
74 | * nbEventsRead++; | |
d337369a | 75 | * processEvent(event); |
c32744d6 | 76 | * event = trace.getNext(context); |
f17b2f70 FC |
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); | |
c32744d6 | 84 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 | 85 | * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) { |
d337369a | 86 | * processEvent(event); |
c32744d6 | 87 | * event = trace.getNext(context); |
f17b2f70 FC |
88 | * } |
89 | * </pre> | |
e73a4ba5 | 90 | * |
d337369a | 91 | * A trace is also an event provider so it can process event requests |
7e6347b0 | 92 | * asynchronously (and coalesce compatible, concurrent requests). |
d337369a | 93 | * <p> |
e73a4ba5 GB |
94 | * |
95 | * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for | |
96 | * variants) | |
d337369a FC |
97 | * <pre> |
98 | * ITmfRequest request = new TmfEventRequest<MyEventType>(MyEventType.class) { | |
e73a4ba5 | 99 | * @Override |
d337369a FC |
100 | * public void handleData(MyEventType event) { |
101 | * super.handleData(event); | |
102 | * processEvent(event); | |
103 | * } | |
e73a4ba5 GB |
104 | * |
105 | * @Override | |
d337369a FC |
106 | * public void handleCompleted() { |
107 | * finish(); | |
108 | * super.handleCompleted(); | |
109 | * } | |
110 | * }; | |
0283f7ff | 111 | * |
d337369a FC |
112 | * fTrace.handleRequest(request); |
113 | * if (youWant) { | |
114 | * request.waitForCompletion(); | |
0283f7ff | 115 | * } |
d337369a | 116 | * </pre> |
0283f7ff | 117 | * |
5419a136 | 118 | * @version 1.0 |
f7703ed6 | 119 | * @author Francois Chouinard |
0283f7ff | 120 | * |
0316808c | 121 | * @see ITmfContext |
d337369a | 122 | * @see ITmfEvent |
0316808c FC |
123 | * @see ITmfTraceIndexer |
124 | * @see ITmfEventParser | |
8c8bf09f | 125 | */ |
fd3f1eff | 126 | public interface ITmfTrace extends ITmfEventProvider { |
12c155f5 | 127 | |
0316808c FC |
128 | // ------------------------------------------------------------------------ |
129 | // Constants | |
130 | // ------------------------------------------------------------------------ | |
131 | ||
132 | /** | |
133 | * The default trace cache size | |
134 | */ | |
135 | public static final int DEFAULT_TRACE_CACHE_SIZE = 1000; | |
136 | ||
8636b448 FC |
137 | // ------------------------------------------------------------------------ |
138 | // Initializers | |
139 | // ------------------------------------------------------------------------ | |
085d898f | 140 | |
3118edf1 FC |
141 | /** |
142 | * Initialize a newly instantiated "empty" trace object. This is used to | |
25e48683 FC |
143 | * properly parameterize an ITmfTrace instantiated with its parameterless |
144 | * constructor. | |
d337369a | 145 | * <p> |
e73a4ba5 GB |
146 | * Typically, the parameterless constructor will provide the block size and |
147 | * its associated parser and indexer. | |
0283f7ff | 148 | * |
e73a4ba5 GB |
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 | |
3118edf1 | 157 | */ |
57a2a5ca | 158 | void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException; |
12c155f5 | 159 | |
3118edf1 FC |
160 | /** |
161 | * Validate that the trace is of the correct type. | |
0283f7ff | 162 | * |
e73a4ba5 GB |
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. | |
a94410d9 | 169 | * @since 2.0 |
3118edf1 | 170 | */ |
57a2a5ca | 171 | IStatus validate(IProject project, String path); |
12c155f5 | 172 | |
8636b448 | 173 | // ------------------------------------------------------------------------ |
3118edf1 | 174 | // Basic getters |
8636b448 | 175 | // ------------------------------------------------------------------------ |
b0a282fb | 176 | |
abfad0aa | 177 | /** |
25e48683 | 178 | * @return the trace event type |
12c155f5 | 179 | */ |
57a2a5ca | 180 | Class<? extends ITmfEvent> getEventType(); |
12c155f5 FC |
181 | |
182 | /** | |
25e48683 | 183 | * @return the associated trace resource |
12c155f5 | 184 | */ |
57a2a5ca | 185 | IResource getResource(); |
12c155f5 | 186 | |
25e48683 FC |
187 | /** |
188 | * @return the trace path | |
189 | */ | |
57a2a5ca | 190 | String getPath(); |
25e48683 | 191 | |
20658947 FC |
192 | /** |
193 | * @return the trace cache size | |
194 | */ | |
57a2a5ca | 195 | int getCacheSize(); |
20658947 | 196 | |
200789b3 AM |
197 | /** |
198 | * @return The statistics provider for this trace | |
199 | * @since 2.0 | |
200 | */ | |
57a2a5ca | 201 | ITmfStatistics getStatistics(); |
200789b3 | 202 | |
7898bb21 | 203 | /** |
35c160d9 | 204 | * Return the map of state systems associated with this trace. |
a51b2b9f | 205 | * |
35c160d9 AM |
206 | * This view should be read-only (implementations should use |
207 | * {@link Collections#unmodifiableMap}). | |
a51b2b9f | 208 | * |
35c160d9 | 209 | * @return The map of state systems |
7898bb21 | 210 | * @since 2.0 |
8a6ff07f | 211 | * @deprecated State systems now should be provided by analysis and use |
5237a931 | 212 | * {@link ITmfAnalysisModuleWithStateSystems} and retrieve the modules |
8a6ff07f GB |
213 | * with {@link TmfTrace#getAnalysisModules(Class)} with Class |
214 | * being TmfStateSystemAnalysisModule.class | |
7898bb21 | 215 | */ |
8a6ff07f | 216 | @Deprecated |
57a2a5ca | 217 | Map<String, ITmfStateSystem> getStateSystems(); |
7898bb21 | 218 | |
6c5e0863 AM |
219 | /** |
220 | * If a state system is not build by the trace itself, it's possible to | |
221 | * register it if it comes from another source. It will then be accessible | |
222 | * with {@link #getStateSystems} normally. | |
223 | * | |
224 | * @param id | |
225 | * The unique ID to assign to this state system. In case of | |
226 | * conflicting ID's, the new one will overwrite the previous one | |
227 | * (default Map behavior). | |
228 | * @param ss | |
229 | * The already-built state system | |
230 | * @since 2.0 | |
8a6ff07f | 231 | * @deprecated State systems now should be provided by analysis and use |
5237a931 | 232 | * {@link ITmfAnalysisModuleWithStateSystems} |
6c5e0863 | 233 | */ |
8a6ff07f | 234 | @Deprecated |
57a2a5ca | 235 | void registerStateSystem(String id, ITmfStateSystem ss); |
6c5e0863 | 236 | |
51e75066 AM |
237 | /** |
238 | * Index the trace. Depending on the trace type, this could be done at the | |
239 | * constructor or initTrace phase too, so this could be implemented as a | |
240 | * no-op. | |
241 | * | |
242 | * @param waitForCompletion | |
243 | * Should we block the caller until indexing is finished, or not. | |
244 | * @since 2.0 | |
245 | */ | |
57a2a5ca | 246 | void indexTrace(boolean waitForCompletion); |
51e75066 | 247 | |
c068a752 GB |
248 | /** |
249 | * Returns an analysis module with the given id | |
250 | * | |
251 | * @param analysisId | |
252 | * The analysis module id | |
253 | * @return The {@link IAnalysisModule} object | |
c4767854 | 254 | * @since 3.0 |
c068a752 GB |
255 | */ |
256 | IAnalysisModule getAnalysisModule(String analysisId); | |
257 | ||
258 | /** | |
8a6ff07f GB |
259 | * Return a map of analysis modules that are of a given class. Module are |
260 | * already casted to the requested class | |
c068a752 GB |
261 | * |
262 | * @param moduleclass | |
263 | * Class returned module must extend | |
8a6ff07f | 264 | * @return List of modules of class moduleclass |
c4767854 | 265 | * @since 3.0 |
c068a752 | 266 | */ |
8a6ff07f | 267 | <T> Map<String, T> getAnalysisModules(Class<T> moduleclass); |
c068a752 GB |
268 | |
269 | /** | |
270 | * Returns a map of analysis modules applicable to this trace. The key is | |
271 | * the analysis id. | |
272 | * | |
273 | * This view should be read-only (implementations should use | |
274 | * {@link Collections#unmodifiableMap}). | |
275 | * | |
276 | * @return The map of analysis modules | |
c4767854 | 277 | * @since 3.0 |
c068a752 GB |
278 | */ |
279 | Map<String, IAnalysisModule> getAnalysisModules(); | |
280 | ||
25e48683 FC |
281 | // ------------------------------------------------------------------------ |
282 | // Trace characteristics getters | |
283 | // ------------------------------------------------------------------------ | |
284 | ||
12c155f5 FC |
285 | /** |
286 | * @return the number of events in the trace | |
287 | */ | |
57a2a5ca | 288 | long getNbEvents(); |
12c155f5 FC |
289 | |
290 | /** | |
3118edf1 | 291 | * @return the trace time range |
3bd46eef | 292 | * @since 2.0 |
12c155f5 | 293 | */ |
57a2a5ca | 294 | TmfTimeRange getTimeRange(); |
12c155f5 | 295 | |
3118edf1 FC |
296 | /** |
297 | * @return the timestamp of the first trace event | |
3bd46eef | 298 | * @since 2.0 |
3118edf1 | 299 | */ |
57a2a5ca | 300 | ITmfTimestamp getStartTime(); |
12c155f5 | 301 | |
3118edf1 FC |
302 | /** |
303 | * @return the timestamp of the last trace event | |
3bd46eef | 304 | * @since 2.0 |
3118edf1 | 305 | */ |
57a2a5ca | 306 | ITmfTimestamp getEndTime(); |
62d1696a | 307 | |
13cb5f43 FC |
308 | /** |
309 | * @return the streaming interval in ms (0 if not a streaming trace) | |
310 | */ | |
57a2a5ca | 311 | long getStreamingInterval(); |
13cb5f43 | 312 | |
25e48683 FC |
313 | // ------------------------------------------------------------------------ |
314 | // Trace positioning getters | |
315 | // ------------------------------------------------------------------------ | |
1b70b6dc | 316 | |
3118edf1 | 317 | /** |
25e48683 | 318 | * @return the current trace location |
a3db8436 | 319 | * @since 3.0 |
3118edf1 | 320 | */ |
57a2a5ca | 321 | ITmfLocation getCurrentLocation(); |
3791b5df FC |
322 | |
323 | /** | |
25e48683 | 324 | * Returns the ratio (proportion) corresponding to the specified location. |
0283f7ff | 325 | * |
e73a4ba5 GB |
326 | * @param location |
327 | * a trace specific location | |
25e48683 | 328 | * @return a floating-point number between 0.0 (beginning) and 1.0 (end) |
a3db8436 | 329 | * @since 3.0 |
3791b5df | 330 | */ |
57a2a5ca | 331 | double getLocationRatio(ITmfLocation location); |
3791b5df | 332 | |
8636b448 | 333 | // ------------------------------------------------------------------------ |
7e6347b0 | 334 | // SeekEvent operations (returning a trace context) |
8636b448 FC |
335 | // ------------------------------------------------------------------------ |
336 | ||
12c155f5 | 337 | /** |
7e6347b0 FC |
338 | * Position the trace at the specified (trace specific) location. |
339 | * <p> | |
340 | * A null location is interpreted as seeking for the first event of the | |
341 | * trace. | |
25e48683 | 342 | * <p> |
7e6347b0 FC |
343 | * If not null, the location requested must be valid otherwise the returned |
344 | * context is undefined (up to the implementation to recover if possible). | |
25e48683 | 345 | * <p> |
e73a4ba5 GB |
346 | * |
347 | * @param location | |
348 | * the trace specific location | |
3118edf1 | 349 | * @return a context which can later be used to read the corresponding event |
a3db8436 | 350 | * @since 3.0 |
8c8bf09f | 351 | */ |
57a2a5ca | 352 | ITmfContext seekEvent(ITmfLocation location); |
12c155f5 | 353 | |
c76c54bb | 354 | /** |
7e6347b0 | 355 | * Position the trace at the 'rank'th event in the trace. |
09e86496 | 356 | * <p> |
e73a4ba5 | 357 | * A rank <= 0 is interpreted as seeking for the first event of the trace. |
7e6347b0 FC |
358 | * <p> |
359 | * If the requested rank is beyond the last trace event, the context | |
360 | * returned will yield a null event if used in a subsequent read. | |
0283f7ff | 361 | * |
e73a4ba5 GB |
362 | * @param rank |
363 | * the event rank | |
3118edf1 | 364 | * @return a context which can later be used to read the corresponding event |
c76c54bb | 365 | */ |
57a2a5ca | 366 | ITmfContext seekEvent(long rank); |
12c155f5 | 367 | |
3118edf1 FC |
368 | /** |
369 | * Position the trace at the first event with the specified timestamp. If | |
e73a4ba5 GB |
370 | * there is no event with the requested timestamp, a context pointing to the |
371 | * next chronological event is returned. | |
09e86496 FC |
372 | * <p> |
373 | * A null timestamp is interpreted as seeking for the first event of the | |
374 | * trace. | |
375 | * <p> | |
376 | * If the requested timestamp is beyond the last trace event, the context | |
377 | * returned will yield a null event if used in a subsequent read. | |
0283f7ff | 378 | * |
e73a4ba5 GB |
379 | * @param timestamp |
380 | * the timestamp of desired event | |
3118edf1 | 381 | * @return a context which can later be used to read the corresponding event |
3bd46eef | 382 | * @since 2.0 |
3118edf1 | 383 | */ |
57a2a5ca | 384 | ITmfContext seekEvent(ITmfTimestamp timestamp); |
3118edf1 FC |
385 | |
386 | /** | |
7e6347b0 FC |
387 | * Position the trace at the event located at the specified ratio in the |
388 | * trace file. | |
09e86496 | 389 | * <p> |
7e6347b0 FC |
390 | * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left |
391 | * voluntarily vague. Typically, it would refer to the event proportional | |
392 | * rank (arguably more intuitive) or timestamp in the trace file. | |
0283f7ff | 393 | * |
e73a4ba5 GB |
394 | * @param ratio |
395 | * the proportional 'rank' in the trace | |
3118edf1 FC |
396 | * @return a context which can later be used to read the corresponding event |
397 | */ | |
57a2a5ca | 398 | ITmfContext seekEvent(double ratio); |
3118edf1 | 399 | |
66262ad8 BH |
400 | /** |
401 | * Returns the initial range offset | |
402 | * | |
403 | * @return the initial range offset | |
404 | * @since 2.0 | |
405 | */ | |
57a2a5ca | 406 | ITmfTimestamp getInitialRangeOffset(); |
bb52f9bc GB |
407 | |
408 | /** | |
409 | * Returns the ID of the host this trace is from. The host ID is not | |
410 | * necessarily the hostname, but should be a unique identifier for the | |
411 | * machine on which the trace was taken. It can be used to determine if two | |
412 | * traces were taken on the exact same machine (timestamp are already | |
413 | * synchronized, resources with same id are the same if taken at the same | |
414 | * time, etc). | |
415 | * | |
416 | * @return The host id of this trace | |
417 | * @since 3.0 | |
418 | */ | |
e73a4ba5 GB |
419 | String getHostId(); |
420 | ||
421 | // ------------------------------------------------------------------------ | |
422 | // Timestamp transformation functions | |
423 | // ------------------------------------------------------------------------ | |
424 | ||
425 | /** | |
426 | * Returns the timestamp transformation for this trace | |
427 | * | |
428 | * @return the timestamp transform | |
429 | * @since 3.0 | |
430 | */ | |
431 | ITmfTimestampTransform getTimestampTransform(); | |
432 | ||
433 | /** | |
434 | * Sets the trace's timestamp transform | |
435 | * | |
436 | * @param tt | |
437 | * The timestamp transform for all timestamps of this trace | |
438 | * @since 3.0 | |
439 | */ | |
440 | void setTimestampTransform(final ITmfTimestampTransform tt); | |
441 | ||
442 | /** | |
443 | * Creates a timestamp for this trace, using the transformation formula | |
444 | * | |
445 | * @param ts | |
446 | * The time in long with which to create the timestamp | |
447 | * @return The new timestamp | |
448 | * @since 3.0 | |
449 | */ | |
450 | ITmfTimestamp createTimestamp(long ts); | |
bb52f9bc | 451 | |
8c8bf09f | 452 | } |