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