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