Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
8636b448 | 2 | * Copyright (c) 2009, 2011, 2012 Ericsson |
8c8bf09f ASL |
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 | |
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 | |
12c155f5 | 16 | import org.eclipse.core.resources.IProject; |
a1091415 | 17 | import org.eclipse.core.resources.IResource; |
f17b2f70 | 18 | import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider; |
72f1e62a | 19 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
4df4581d | 20 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b | 21 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; |
b4f71e4a | 22 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
8c8bf09f ASL |
23 | |
24 | /** | |
f17b2f70 FC |
25 | * The event stream structure in TMF. In its basic form, a trace has: |
26 | * <ul> | |
7e6347b0 FC |
27 | * <li> an associated Eclipse resource |
28 | * <li> a path to its location on the file system | |
f17b2f70 FC |
29 | * <li> the type of the events it contains |
30 | * <li> the number of events it contains | |
31 | * <li> the time range (span) of the events it contains | |
32 | * </ul> | |
33 | * Concrete ITmfTrace classes have to provide a parameter-less constructor and | |
7e6347b0 FC |
34 | * an initialization method (<i>initTrace</i>) if they are to be opened from |
35 | * the Project View. Also, a validation method (<i>validate</i>) has to be | |
36 | * provided to ensure that the trace is of the correct type. | |
f17b2f70 FC |
37 | * <p> |
38 | * A trace can be accessed simultaneously from multiple threads by various | |
39 | * application components. To avoid obvious multi-threading issues, the trace | |
40 | * uses an ITmfContext as a synchronization aid for its read operations. | |
41 | * <p> | |
42 | * A proper ITmfContext can be obtained by performing a seek operation on the | |
43 | * trace. Seek operations can be performed for a particular event (by rank or | |
44 | * timestamp) or for a plain trace location. | |
45 | * <p> | |
d337369a | 46 | * <b>Example 1</b>: Process a whole trace |
f17b2f70 | 47 | * <pre> |
7e6347b0 | 48 | * ITmfContext context = trace.seekEvent(0); |
c32744d6 | 49 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 | 50 | * while (event != null) { |
d337369a | 51 | * processEvent(event); |
c32744d6 | 52 | * event = trace.getNext(context); |
f17b2f70 FC |
53 | * } |
54 | * </pre> | |
55 | * <b>Example 2</b>: Process 50 events starting from the 1000th event | |
56 | * <pre> | |
57 | * int nbEventsRead = 0; | |
58 | * ITmfContext context = trace.seekEvent(1000); | |
c32744d6 | 59 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 FC |
60 | * while (event != null && nbEventsRead < 50) { |
61 | * nbEventsRead++; | |
d337369a | 62 | * processEvent(event); |
c32744d6 | 63 | * event = trace.getNext(context); |
f17b2f70 FC |
64 | * } |
65 | * </pre> | |
66 | * <b>Example 3</b>: Process the events between 2 timestamps (inclusive) | |
67 | * <pre> | |
68 | * ITmfTimestamp startTime = ...; | |
69 | * ITmfTimestamp endTime = ...; | |
70 | * ITmfContext context = trace.seekEvent(startTime); | |
c32744d6 | 71 | * ITmfEvent event = trace.getNext(context); |
f17b2f70 | 72 | * while (event != null && event.getTimestamp().compareTo(endTime) <= 0) { |
d337369a | 73 | * processEvent(event); |
c32744d6 | 74 | * event = trace.getNext(context); |
f17b2f70 FC |
75 | * } |
76 | * </pre> | |
d337369a | 77 | * A trace is also an event provider so it can process event requests |
7e6347b0 | 78 | * asynchronously (and coalesce compatible, concurrent requests). |
d337369a FC |
79 | * <p> |
80 | * </pre> | |
7e6347b0 | 81 | * <b>Example 4</b>: Process a whole trace (see ITmfEventRequest for variants) |
d337369a FC |
82 | * <pre> |
83 | * ITmfRequest request = new TmfEventRequest<MyEventType>(MyEventType.class) { | |
84 | * @Override | |
85 | * public void handleData(MyEventType event) { | |
86 | * super.handleData(event); | |
87 | * processEvent(event); | |
88 | * } | |
89 | * @Override | |
90 | * public void handleCompleted() { | |
91 | * finish(); | |
92 | * super.handleCompleted(); | |
93 | * } | |
94 | * }; | |
7e6347b0 | 95 | * |
d337369a FC |
96 | * fTrace.handleRequest(request); |
97 | * if (youWant) { | |
98 | * request.waitForCompletion(); | |
99 | * } | |
100 | * </pre> | |
f7703ed6 | 101 | * |
f7703ed6 FC |
102 | * @version 1.0 |
103 | * @author Francois Chouinard | |
0316808c FC |
104 | * |
105 | * @see ITmfContext | |
d337369a | 106 | * @see ITmfEvent |
0316808c FC |
107 | * @see ITmfTraceIndexer |
108 | * @see ITmfEventParser | |
8c8bf09f | 109 | */ |
f17b2f70 | 110 | public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> { |
12c155f5 | 111 | |
0316808c FC |
112 | // ------------------------------------------------------------------------ |
113 | // Constants | |
114 | // ------------------------------------------------------------------------ | |
115 | ||
116 | /** | |
117 | * The default trace cache size | |
118 | */ | |
119 | public static final int DEFAULT_TRACE_CACHE_SIZE = 1000; | |
120 | ||
8636b448 FC |
121 | // ------------------------------------------------------------------------ |
122 | // Initializers | |
123 | // ------------------------------------------------------------------------ | |
085d898f | 124 | |
3118edf1 FC |
125 | /** |
126 | * Initialize a newly instantiated "empty" trace object. This is used to | |
25e48683 FC |
127 | * properly parameterize an ITmfTrace instantiated with its parameterless |
128 | * constructor. | |
d337369a | 129 | * <p> |
25e48683 FC |
130 | * Typically, the parameterless constructor will provide the block size |
131 | * and its associated parser and indexer. | |
132 | * | |
133 | * @param resource the trace resource | |
3118edf1 | 134 | * @param path the trace path |
3791b5df | 135 | * @param type the trace event type |
063f0d27 | 136 | * @throws TmfTraceException If we couldn't open the trace |
3118edf1 | 137 | */ |
b4f71e4a | 138 | public void initTrace(IResource resource, String path, Class<T> type) throws TmfTraceException; |
12c155f5 | 139 | |
3118edf1 FC |
140 | /** |
141 | * Validate that the trace is of the correct type. | |
142 | * | |
143 | * @param project the eclipse project | |
144 | * @param path the trace path | |
145 | * | |
146 | * @return true if trace is valid | |
147 | */ | |
148 | public boolean validate(IProject project, String path); | |
12c155f5 | 149 | |
8636b448 | 150 | // ------------------------------------------------------------------------ |
3118edf1 | 151 | // Basic getters |
8636b448 | 152 | // ------------------------------------------------------------------------ |
b0a282fb | 153 | |
abfad0aa | 154 | /** |
25e48683 | 155 | * @return the trace event type |
12c155f5 | 156 | */ |
13cb5f43 | 157 | public Class<T> getEventType(); |
12c155f5 FC |
158 | |
159 | /** | |
25e48683 | 160 | * @return the associated trace resource |
12c155f5 | 161 | */ |
3791b5df | 162 | public IResource getResource(); |
12c155f5 | 163 | |
25e48683 FC |
164 | /** |
165 | * @return the trace path | |
166 | */ | |
167 | public String getPath(); | |
168 | ||
20658947 FC |
169 | /** |
170 | * @return the trace cache size | |
171 | */ | |
172 | public int getCacheSize(); | |
173 | ||
25e48683 FC |
174 | // ------------------------------------------------------------------------ |
175 | // Trace characteristics getters | |
176 | // ------------------------------------------------------------------------ | |
177 | ||
12c155f5 FC |
178 | /** |
179 | * @return the number of events in the trace | |
180 | */ | |
181 | public long getNbEvents(); | |
182 | ||
183 | /** | |
3118edf1 | 184 | * @return the trace time range |
12c155f5 FC |
185 | */ |
186 | public TmfTimeRange getTimeRange(); | |
187 | ||
3118edf1 FC |
188 | /** |
189 | * @return the timestamp of the first trace event | |
190 | */ | |
4df4581d | 191 | public ITmfTimestamp getStartTime(); |
12c155f5 | 192 | |
3118edf1 FC |
193 | /** |
194 | * @return the timestamp of the last trace event | |
195 | */ | |
4df4581d | 196 | public ITmfTimestamp getEndTime(); |
62d1696a | 197 | |
13cb5f43 FC |
198 | /** |
199 | * @return the streaming interval in ms (0 if not a streaming trace) | |
200 | */ | |
201 | public long getStreamingInterval(); | |
202 | ||
25e48683 FC |
203 | // ------------------------------------------------------------------------ |
204 | // Trace positioning getters | |
205 | // ------------------------------------------------------------------------ | |
1b70b6dc | 206 | |
3118edf1 | 207 | /** |
25e48683 | 208 | * @return the current trace location |
3118edf1 | 209 | */ |
25e48683 | 210 | public ITmfLocation<?> getCurrentLocation(); |
3791b5df FC |
211 | |
212 | /** | |
25e48683 | 213 | * Returns the ratio (proportion) corresponding to the specified location. |
3791b5df | 214 | * |
25e48683 FC |
215 | * @param location a trace specific location |
216 | * @return a floating-point number between 0.0 (beginning) and 1.0 (end) | |
3791b5df | 217 | */ |
25e48683 | 218 | public double getLocationRatio(ITmfLocation<?> location); |
3791b5df | 219 | |
8636b448 | 220 | // ------------------------------------------------------------------------ |
7e6347b0 | 221 | // SeekEvent operations (returning a trace context) |
8636b448 FC |
222 | // ------------------------------------------------------------------------ |
223 | ||
12c155f5 | 224 | /** |
7e6347b0 FC |
225 | * Position the trace at the specified (trace specific) location. |
226 | * <p> | |
227 | * A null location is interpreted as seeking for the first event of the | |
228 | * trace. | |
25e48683 | 229 | * <p> |
7e6347b0 FC |
230 | * If not null, the location requested must be valid otherwise the returned |
231 | * context is undefined (up to the implementation to recover if possible). | |
25e48683 | 232 | * <p> |
7e6347b0 | 233 | * @param location the trace specific location |
3118edf1 | 234 | * @return a context which can later be used to read the corresponding event |
8c8bf09f | 235 | */ |
7e6347b0 | 236 | public ITmfContext seekEvent(ITmfLocation<?> location); |
12c155f5 | 237 | |
c76c54bb | 238 | /** |
7e6347b0 | 239 | * Position the trace at the 'rank'th event in the trace. |
09e86496 | 240 | * <p> |
7e6347b0 FC |
241 | * A rank <= 0 is interpreted as seeking for the first event of the |
242 | * trace. | |
243 | * <p> | |
244 | * If the requested rank is beyond the last trace event, the context | |
245 | * returned will yield a null event if used in a subsequent read. | |
c76c54bb | 246 | * |
7e6347b0 | 247 | * @param rank the event rank |
3118edf1 | 248 | * @return a context which can later be used to read the corresponding event |
c76c54bb | 249 | */ |
7e6347b0 | 250 | public ITmfContext seekEvent(long rank); |
12c155f5 | 251 | |
3118edf1 FC |
252 | /** |
253 | * Position the trace at the first event with the specified timestamp. If | |
254 | * there is no event with the requested timestamp, a context pointing to | |
09e86496 FC |
255 | * the next chronological event is returned. |
256 | * <p> | |
257 | * A null timestamp is interpreted as seeking for the first event of the | |
258 | * trace. | |
259 | * <p> | |
260 | * If the requested timestamp is beyond the last trace event, the context | |
261 | * returned will yield a null event if used in a subsequent read. | |
3118edf1 FC |
262 | * |
263 | * @param timestamp the timestamp of desired event | |
264 | * @return a context which can later be used to read the corresponding event | |
265 | */ | |
266 | public ITmfContext seekEvent(ITmfTimestamp timestamp); | |
267 | ||
268 | /** | |
7e6347b0 FC |
269 | * Position the trace at the event located at the specified ratio in the |
270 | * trace file. | |
09e86496 | 271 | * <p> |
7e6347b0 FC |
272 | * The notion of ratio (0.0 <= r <= 1.0) is trace specific and left |
273 | * voluntarily vague. Typically, it would refer to the event proportional | |
274 | * rank (arguably more intuitive) or timestamp in the trace file. | |
3118edf1 | 275 | * |
7e6347b0 | 276 | * @param ratio the proportional 'rank' in the trace |
3118edf1 FC |
277 | * @return a context which can later be used to read the corresponding event |
278 | */ | |
7e6347b0 | 279 | public ITmfContext seekEvent(double ratio); |
3118edf1 | 280 | |
8c8bf09f | 281 | } |