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