Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
09e86496 | 2 | * Copyright (c) 2009, 2010, 2012 Ericsson |
0bfb7d06 | 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 | |
0bfb7d06 | 8 | * |
8c8bf09f | 9 | * Contributors: |
20658947 FC |
10 | * Francois Chouinard - Initial API and implementation |
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 | |
6f4a1d2b | 16 | import java.io.File; |
8c8bf09f | 17 | |
828e5592 | 18 | import org.eclipse.core.resources.IResource; |
9b749023 | 19 | import org.eclipse.core.runtime.IPath; |
6c13869b | 20 | import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider; |
72f1e62a | 21 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
4df4581d | 22 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b FC |
23 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; |
24 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
b4f71e4a | 25 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
6c13869b FC |
26 | import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest; |
27 | import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; | |
7898bb21 | 28 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
8c8bf09f ASL |
29 | |
30 | /** | |
09e86496 FC |
31 | * Abstract implementation of ITmfTrace. |
32 | * <p> | |
13cb5f43 FC |
33 | * Since the concept of 'location' is trace specific, the concrete classes have |
34 | * to provide the related methods, namely: | |
35 | * <ul> | |
36 | * <li> public ITmfLocation<?> getCurrentLocation() | |
37 | * <li> public double getLocationRatio(ITmfLocation<?> location) | |
38 | * <li> public ITmfContext seekEvent(ITmfLocation<?> location) | |
39 | * <li> public ITmfContext seekEvent(double ratio) | |
2848c377 | 40 | * <li> public boolean validate(IProject project, String path) |
13cb5f43 FC |
41 | * </ul> |
42 | * A concrete trace must provide its corresponding parser. A common way to | |
43 | * accomplish this is by making the concrete class extend TmfTrace and | |
44 | * implement ITmfEventParser. | |
45 | * <p> | |
46 | * The concrete class can either specify its own indexer or use the provided | |
47 | * TmfCheckpointIndexer (default). In this case, the trace cache size will be | |
48 | * used as checkpoint interval. | |
0bfb7d06 | 49 | * |
f7703ed6 FC |
50 | * @version 1.0 |
51 | * @author Francois Chouinard | |
52 | * | |
f7703ed6 FC |
53 | * @see ITmfEvent |
54 | * @see ITmfTraceIndexer | |
55 | * @see ITmfEventParser | |
8c8bf09f | 56 | */ |
6256d8ad | 57 | public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { |
62d1696a | 58 | |
e31e01e8 | 59 | // ------------------------------------------------------------------------ |
8c8bf09f | 60 | // Attributes |
e31e01e8 | 61 | // ------------------------------------------------------------------------ |
8c8bf09f | 62 | |
09e86496 FC |
63 | // The resource used for persistent properties for this trace |
64 | private IResource fResource; | |
65 | ||
b0a282fb | 66 | // The trace path |
12c155f5 | 67 | private String fPath; |
b0a282fb | 68 | |
0316808c FC |
69 | // The trace cache page size |
70 | private int fCacheSize = ITmfTrace.DEFAULT_TRACE_CACHE_SIZE; | |
62d1696a | 71 | |
0316808c FC |
72 | // The number of events collected (so far) |
73 | private long fNbEvents = 0; | |
62d1696a FC |
74 | |
75 | // The time span of the event stream | |
a4115405 FC |
76 | private ITmfTimestamp fStartTime = TmfTimestamp.BIG_CRUNCH; |
77 | private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG; | |
62d1696a | 78 | |
0316808c FC |
79 | // The trace streaming interval (0 = no streaming) |
80 | private long fStreamingInterval = 0; | |
085d898f | 81 | |
0316808c | 82 | // The trace indexer |
6256d8ad | 83 | private ITmfTraceIndexer fIndexer; |
20658947 | 84 | |
0316808c | 85 | // The trace parser |
6256d8ad | 86 | private ITmfEventParser fParser; |
7e6347b0 | 87 | |
e31e01e8 | 88 | // ------------------------------------------------------------------------ |
3791b5df | 89 | // Construction |
e31e01e8 | 90 | // ------------------------------------------------------------------------ |
8c8bf09f | 91 | |
62d1696a | 92 | /** |
3791b5df | 93 | * The default, parameterless, constructor |
62d1696a | 94 | */ |
3791b5df FC |
95 | public TmfTrace() { |
96 | super(); | |
05bd3318 FC |
97 | } |
98 | ||
99 | /** | |
13cb5f43 | 100 | * The standard constructor (non-live trace). Applicable when the trace |
0bfb7d06 MK |
101 | * implements its own parser and if at checkpoint-based index is OK. |
102 | * | |
20658947 FC |
103 | * @param resource the resource associated to the trace |
104 | * @param type the trace event type | |
105 | * @param path the trace path | |
106 | * @param cacheSize the trace cache size | |
2352aed9 | 107 | * @throws TmfTraceException |
20658947 | 108 | */ |
6256d8ad | 109 | protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize) throws TmfTraceException { |
9e0640dc | 110 | this(resource, type, path, cacheSize, 0); |
20658947 FC |
111 | } |
112 | ||
113 | /** | |
13cb5f43 FC |
114 | * The standard constructor (live trace). Applicable when the trace |
115 | * implements its own parser and if at checkpoint-based index is OK. | |
0bfb7d06 | 116 | * |
20658947 | 117 | * @param resource the resource associated to the trace |
3791b5df FC |
118 | * @param type the trace event type |
119 | * @param path the trace path | |
20658947 FC |
120 | * @param cacheSize the trace cache size |
121 | * @param interval the trace streaming interval | |
2352aed9 | 122 | * @throws TmfTraceException |
05bd3318 | 123 | */ |
6256d8ad | 124 | protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize, final long interval) throws TmfTraceException { |
20658947 | 125 | this(resource, type, path, cacheSize, interval, null); |
05bd3318 FC |
126 | } |
127 | ||
128 | /** | |
13cb5f43 FC |
129 | * The 'non-default indexer' constructor. Allows to provide a trace |
130 | * specific indexer. | |
0bfb7d06 | 131 | * |
20658947 | 132 | * @param resource the resource associated to the trace |
3791b5df FC |
133 | * @param type the trace event type |
134 | * @param path the trace path | |
20658947 FC |
135 | * @param cacheSize the trace cache size |
136 | * @param indexer the trace indexer | |
2352aed9 | 137 | * @throws TmfTraceException |
05bd3318 | 138 | */ |
6256d8ad AM |
139 | protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize, |
140 | final long interval, final ITmfTraceIndexer indexer) throws TmfTraceException { | |
0316808c | 141 | this(resource, type, path, cacheSize, interval, indexer, null); |
13cb5f43 FC |
142 | } |
143 | ||
144 | /** | |
0bfb7d06 MK |
145 | * The full constructor where trace specific indexer/parser are provided. |
146 | * | |
13cb5f43 FC |
147 | * @param resource the resource associated to the trace |
148 | * @param type the trace event type | |
149 | * @param path the trace path | |
150 | * @param cacheSize the trace cache size | |
151 | * @param indexer the trace indexer | |
152 | * @param parser the trace event parser | |
2352aed9 | 153 | * @throws TmfTraceException |
13cb5f43 | 154 | */ |
6256d8ad AM |
155 | protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize, |
156 | final long interval, final ITmfTraceIndexer indexer, final ITmfEventParser parser) throws TmfTraceException { | |
00641a97 | 157 | super(); |
0316808c | 158 | fCacheSize = (cacheSize > 0) ? cacheSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE; |
3791b5df | 159 | fStreamingInterval = interval; |
7e6347b0 | 160 | fIndexer = (indexer != null) ? indexer : new TmfCheckpointIndexer(this, fCacheSize); |
13cb5f43 | 161 | fParser = parser; |
09e86496 | 162 | initialize(resource, path, type); |
8c8bf09f ASL |
163 | } |
164 | ||
3791b5df FC |
165 | /** |
166 | * Copy constructor | |
0bfb7d06 | 167 | * |
3791b5df | 168 | * @param trace the original trace |
063f0d27 | 169 | * @throws TmfTraceException Should not happen usually |
3791b5df | 170 | */ |
6256d8ad | 171 | public TmfTrace(final TmfTrace trace) throws TmfTraceException { |
3791b5df | 172 | super(); |
0316808c | 173 | if (trace == null) { |
3791b5df | 174 | throw new IllegalArgumentException(); |
0316808c | 175 | } |
20658947 FC |
176 | fCacheSize = trace.getCacheSize(); |
177 | fStreamingInterval = trace.getStreamingInterval(); | |
7e6347b0 | 178 | fIndexer = new TmfCheckpointIndexer(this); |
13cb5f43 FC |
179 | fParser = trace.fParser; |
180 | initialize(trace.getResource(), trace.getPath(), trace.getEventType()); | |
3791b5df FC |
181 | } |
182 | ||
7e6347b0 FC |
183 | // ------------------------------------------------------------------------ |
184 | // ITmfTrace - Initializers | |
185 | // ------------------------------------------------------------------------ | |
186 | ||
187 | /* (non-Javadoc) | |
188 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(org.eclipse.core.resources.IResource, java.lang.String, java.lang.Class) | |
189 | */ | |
190 | @Override | |
6256d8ad | 191 | public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException { |
9dc3dee2 | 192 | fIndexer = new TmfCheckpointIndexer(this, fCacheSize); |
7e6347b0 | 193 | initialize(resource, path, type); |
7e6347b0 FC |
194 | } |
195 | ||
09e86496 | 196 | /** |
1703b536 | 197 | * Initialize the trace common attributes and the base component. |
0bfb7d06 MK |
198 | * |
199 | * @param resource the Eclipse resource (trace) | |
1703b536 FC |
200 | * @param path the trace path |
201 | * @param type the trace event type | |
0bfb7d06 | 202 | * |
0316808c | 203 | * @throws TmfTraceException |
3791b5df | 204 | */ |
6256d8ad | 205 | protected void initialize(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException { |
0316808c | 206 | if (path == null) { |
b4f71e4a | 207 | throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$ |
0316808c | 208 | } |
3791b5df | 209 | fPath = path; |
1703b536 | 210 | fResource = resource; |
25e48683 | 211 | String traceName = (resource != null) ? resource.getName() : null; |
1703b536 FC |
212 | // If no resource was provided, extract the display name the trace path |
213 | if (traceName == null) { | |
9b749023 | 214 | final int sep = path.lastIndexOf(IPath.SEPARATOR); |
1703b536 FC |
215 | traceName = (sep >= 0) ? path.substring(sep + 1) : path; |
216 | } | |
2352aed9 FC |
217 | if (fParser == null) { |
218 | if (this instanceof ITmfEventParser) { | |
6256d8ad | 219 | fParser = (ITmfEventParser) this; |
2352aed9 FC |
220 | } else { |
221 | throw new TmfTraceException("Invalid trace parser"); //$NON-NLS-1$ | |
222 | } | |
223 | } | |
3791b5df FC |
224 | super.init(traceName, type); |
225 | } | |
226 | ||
2352aed9 FC |
227 | /** |
228 | * Indicates if the path points to an existing file/directory | |
0bfb7d06 | 229 | * |
2352aed9 FC |
230 | * @param path the path to test |
231 | * @return true if the file/directory exists | |
3791b5df | 232 | */ |
2352aed9 | 233 | protected boolean fileExists(final String path) { |
085d898f | 234 | final File file = new File(path); |
3791b5df FC |
235 | return file.exists(); |
236 | } | |
237 | ||
c7e1020d FC |
238 | /** |
239 | * Index the trace | |
0bfb7d06 | 240 | * |
c7e1020d FC |
241 | * @param waitForCompletion index synchronously (true) or not (false) |
242 | */ | |
243 | protected void indexTrace(boolean waitForCompletion) { | |
9e0640dc | 244 | getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, waitForCompletion); |
c7e1020d FC |
245 | } |
246 | ||
b5ee6881 FC |
247 | /** |
248 | * Clears the trace | |
249 | */ | |
250 | @Override | |
251 | public synchronized void dispose() { | |
77551cc2 FC |
252 | // Clean up the index if applicable |
253 | if (getIndexer() != null) { | |
254 | getIndexer().dispose(); | |
255 | } | |
b5ee6881 FC |
256 | super.dispose(); |
257 | } | |
258 | ||
3791b5df | 259 | // ------------------------------------------------------------------------ |
09e86496 | 260 | // ITmfTrace - Basic getters |
e31e01e8 | 261 | // ------------------------------------------------------------------------ |
8c8bf09f | 262 | |
09e86496 | 263 | /* (non-Javadoc) |
13cb5f43 | 264 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEventType() |
25e48683 FC |
265 | */ |
266 | @Override | |
6256d8ad AM |
267 | public Class<ITmfEvent> getEventType() { |
268 | return (Class<ITmfEvent>) super.getType(); | |
25e48683 FC |
269 | } |
270 | ||
09e86496 FC |
271 | /* (non-Javadoc) |
272 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource() | |
62d1696a | 273 | */ |
d4011df2 | 274 | @Override |
09e86496 FC |
275 | public IResource getResource() { |
276 | return fResource; | |
8c8bf09f ASL |
277 | } |
278 | ||
09e86496 FC |
279 | /* (non-Javadoc) |
280 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getPath() | |
62d1696a | 281 | */ |
d4011df2 | 282 | @Override |
09e86496 FC |
283 | public String getPath() { |
284 | return fPath; | |
8c8bf09f ASL |
285 | } |
286 | ||
20658947 FC |
287 | /* (non-Javadoc) |
288 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getIndexPageSize() | |
289 | */ | |
290 | @Override | |
291 | public int getCacheSize() { | |
292 | return fCacheSize; | |
293 | } | |
294 | ||
295 | /* (non-Javadoc) | |
296 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStreamingInterval() | |
297 | */ | |
298 | @Override | |
299 | public long getStreamingInterval() { | |
300 | return fStreamingInterval; | |
301 | } | |
302 | ||
0316808c FC |
303 | /** |
304 | * @return the trace indexer | |
305 | */ | |
6256d8ad | 306 | protected ITmfTraceIndexer getIndexer() { |
0316808c FC |
307 | return fIndexer; |
308 | } | |
309 | ||
310 | /** | |
311 | * @return the trace parser | |
312 | */ | |
6256d8ad | 313 | protected ITmfEventParser getParser() { |
0316808c FC |
314 | return fParser; |
315 | } | |
316 | ||
7898bb21 AM |
317 | /** |
318 | * @since 2.0 | |
319 | */ | |
320 | @Override | |
321 | public ITmfStateSystem getStateSystem() { | |
322 | /* | |
323 | * By default, no state system is used. Sub-classes can specify their | |
324 | * own behaviour. | |
325 | */ | |
326 | return null; | |
327 | } | |
328 | ||
09e86496 FC |
329 | // ------------------------------------------------------------------------ |
330 | // ITmfTrace - Trace characteristics getters | |
331 | // ------------------------------------------------------------------------ | |
332 | ||
333 | /* (non-Javadoc) | |
334 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNbEvents() | |
b0a282fb | 335 | */ |
d4011df2 | 336 | @Override |
afc86f78 | 337 | public synchronized long getNbEvents() { |
3791b5df | 338 | return fNbEvents; |
b0a282fb FC |
339 | } |
340 | ||
09e86496 FC |
341 | /* (non-Javadoc) |
342 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getTimeRange() | |
62d1696a | 343 | */ |
d4011df2 | 344 | @Override |
12c155f5 | 345 | public TmfTimeRange getTimeRange() { |
cb866e08 | 346 | return new TmfTimeRange(fStartTime, fEndTime); |
8c8bf09f ASL |
347 | } |
348 | ||
09e86496 FC |
349 | /* (non-Javadoc) |
350 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStartTime() | |
e31e01e8 | 351 | */ |
d4011df2 | 352 | @Override |
4df4581d | 353 | public ITmfTimestamp getStartTime() { |
20658947 | 354 | return fStartTime.clone(); |
146a887c FC |
355 | } |
356 | ||
09e86496 FC |
357 | /* (non-Javadoc) |
358 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEndTime() | |
e31e01e8 | 359 | */ |
d4011df2 | 360 | @Override |
4df4581d | 361 | public ITmfTimestamp getEndTime() { |
20658947 FC |
362 | return fEndTime.clone(); |
363 | } | |
364 | ||
365 | // ------------------------------------------------------------------------ | |
0316808c | 366 | // Convenience setters/getters |
20658947 FC |
367 | // ------------------------------------------------------------------------ |
368 | ||
0316808c FC |
369 | /** |
370 | * Set the trace cache size. Must be done at initialization time. | |
0bfb7d06 | 371 | * |
0316808c FC |
372 | * @param cacheSize The trace cache size |
373 | */ | |
374 | protected void setCacheSize(final int cacheSize) { | |
375 | fCacheSize = cacheSize; | |
376 | } | |
377 | ||
378 | /** | |
379 | * Set the trace known number of events. This can be quite dynamic | |
380 | * during indexing or for live traces. | |
0bfb7d06 | 381 | * |
0316808c FC |
382 | * @param nbEvents The number of events |
383 | */ | |
384 | protected synchronized void setNbEvents(final long nbEvents) { | |
385 | fNbEvents = (nbEvents > 0) ? nbEvents : 0; | |
386 | } | |
387 | ||
20658947 FC |
388 | /** |
389 | * Update the trace events time range | |
0bfb7d06 | 390 | * |
20658947 FC |
391 | * @param range the new time range |
392 | */ | |
393 | protected void setTimeRange(final TmfTimeRange range) { | |
394 | fStartTime = range.getStartTime().clone(); | |
395 | fEndTime = range.getEndTime().clone(); | |
396 | } | |
397 | ||
398 | /** | |
399 | * Update the trace chronologically first event timestamp | |
0bfb7d06 | 400 | * |
20658947 FC |
401 | * @param startTime the new first event timestamp |
402 | */ | |
403 | protected void setStartTime(final ITmfTimestamp startTime) { | |
404 | fStartTime = startTime.clone(); | |
405 | } | |
406 | ||
407 | /** | |
408 | * Update the trace chronologically last event timestamp | |
0bfb7d06 | 409 | * |
20658947 FC |
410 | * @param endTime the new last event timestamp |
411 | */ | |
412 | protected void setEndTime(final ITmfTimestamp endTime) { | |
413 | fEndTime = endTime.clone(); | |
414 | } | |
415 | ||
416 | /** | |
0316808c | 417 | * Set the polling interval for live traces (default = 0 = no streaming). |
0bfb7d06 | 418 | * |
20658947 FC |
419 | * @param interval the new trace streaming interval |
420 | */ | |
421 | protected void setStreamingInterval(final long interval) { | |
1703b536 | 422 | fStreamingInterval = (interval > 0) ? interval : 0; |
146a887c FC |
423 | } |
424 | ||
0316808c FC |
425 | /** |
426 | * Set the trace indexer. Must be done at initialization time. | |
0bfb7d06 | 427 | * |
0316808c FC |
428 | * @param indexer the trace indexer |
429 | */ | |
6256d8ad | 430 | protected void setIndexer(final ITmfTraceIndexer indexer) { |
0316808c FC |
431 | fIndexer = indexer; |
432 | } | |
433 | ||
434 | /** | |
435 | * Set the trace parser. Must be done at initialization time. | |
0bfb7d06 | 436 | * |
0316808c FC |
437 | * @param parser the new trace parser |
438 | */ | |
6256d8ad | 439 | protected void setParser(final ITmfEventParser parser) { |
0316808c FC |
440 | fParser = parser; |
441 | } | |
442 | ||
09e86496 | 443 | // ------------------------------------------------------------------------ |
7e6347b0 | 444 | // ITmfTrace - SeekEvent operations (returning a trace context) |
09e86496 FC |
445 | // ------------------------------------------------------------------------ |
446 | ||
447 | /* (non-Javadoc) | |
7e6347b0 | 448 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(long) |
1b70b6dc PT |
449 | */ |
450 | @Override | |
7e6347b0 | 451 | public synchronized ITmfContext seekEvent(final long rank) { |
09e86496 | 452 | |
7e6347b0 | 453 | // A rank <= 0 indicates to seek the first event |
2352aed9 | 454 | if (rank <= 0) { |
1e1bef82 | 455 | ITmfContext context = seekEvent((ITmfLocation) null); |
2352aed9 FC |
456 | context.setRank(0); |
457 | return context; | |
458 | } | |
09e86496 | 459 | |
09e86496 | 460 | // Position the trace at the checkpoint |
7e6347b0 | 461 | final ITmfContext context = fIndexer.seekIndex(rank); |
09e86496 FC |
462 | |
463 | // And locate the requested event context | |
7e6347b0 FC |
464 | long pos = context.getRank(); |
465 | if (pos < rank) { | |
c32744d6 | 466 | ITmfEvent event = getNext(context); |
0bfb7d06 | 467 | while ((event != null) && (++pos < rank)) { |
c32744d6 | 468 | event = getNext(context); |
7e6347b0 | 469 | } |
09e86496 FC |
470 | } |
471 | return context; | |
1b70b6dc PT |
472 | } |
473 | ||
09e86496 | 474 | /* (non-Javadoc) |
7e6347b0 | 475 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp) |
09e86496 FC |
476 | */ |
477 | @Override | |
7e6347b0 | 478 | public synchronized ITmfContext seekEvent(final ITmfTimestamp timestamp) { |
09e86496 | 479 | |
7e6347b0 | 480 | // A null timestamp indicates to seek the first event |
2352aed9 | 481 | if (timestamp == null) { |
1e1bef82 | 482 | ITmfContext context = seekEvent((ITmfLocation) null); |
2352aed9 FC |
483 | context.setRank(0); |
484 | return context; | |
485 | } | |
09e86496 | 486 | |
1703b536 | 487 | // Position the trace at the checkpoint |
408e65d2 | 488 | ITmfContext context = fIndexer.seekIndex(timestamp); |
09e86496 FC |
489 | |
490 | // And locate the requested event context | |
7e6347b0 | 491 | final ITmfContext nextEventContext = context.clone(); // Must use clone() to get the right subtype... |
c32744d6 | 492 | ITmfEvent event = getNext(nextEventContext); |
7e6347b0 | 493 | while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) { |
3cec7398 | 494 | context = nextEventContext.clone(); |
c32744d6 | 495 | event = getNext(nextEventContext); |
09e86496 | 496 | } |
0316808c FC |
497 | if (event == null) { |
498 | context.setLocation(null); | |
499 | context.setRank(ITmfContext.UNKNOWN_RANK); | |
500 | } | |
09e86496 FC |
501 | return context; |
502 | } | |
0283f7ff | 503 | |
09e86496 FC |
504 | // ------------------------------------------------------------------------ |
505 | // ITmfTrace - Read operations (returning an actual event) | |
506 | // ------------------------------------------------------------------------ | |
507 | ||
d337369a | 508 | /* (non-Javadoc) |
b4f71e4a | 509 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext) |
abfad0aa | 510 | */ |
d4011df2 | 511 | @Override |
6256d8ad | 512 | public synchronized ITmfEvent getNext(final ITmfContext context) { |
09e86496 | 513 | // parseEvent() does not update the context |
6256d8ad | 514 | final ITmfEvent event = fParser.parseEvent(context); |
09e86496 | 515 | if (event != null) { |
d337369a | 516 | updateAttributes(context, event.getTimestamp()); |
09e86496 FC |
517 | context.setLocation(getCurrentLocation()); |
518 | context.increaseRank(); | |
519 | processEvent(event); | |
520 | } | |
521 | return event; | |
522 | } | |
523 | ||
524 | /** | |
d337369a | 525 | * Hook for special event processing by the concrete class |
7e6347b0 | 526 | * (called by TmfTrace.getEvent()) |
0bfb7d06 | 527 | * |
d337369a | 528 | * @param event the event |
09e86496 FC |
529 | */ |
530 | protected void processEvent(final ITmfEvent event) { | |
d337369a | 531 | // Do nothing |
09e86496 FC |
532 | } |
533 | ||
d337369a FC |
534 | /** |
535 | * Update the trace attributes | |
0bfb7d06 | 536 | * |
d337369a | 537 | * @param context the current trace context |
2848c377 | 538 | * @param timestamp the corresponding timestamp |
d337369a FC |
539 | */ |
540 | protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) { | |
0bfb7d06 | 541 | if (fStartTime.equals(TmfTimestamp.BIG_BANG) || (fStartTime.compareTo(timestamp, false) > 0)) { |
49e2f79a | 542 | fStartTime = timestamp.clone(); |
09e86496 | 543 | } |
0bfb7d06 | 544 | if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || (fEndTime.compareTo(timestamp, false) < 0)) { |
49e2f79a | 545 | fEndTime = timestamp.clone(); |
09e86496 FC |
546 | } |
547 | if (context.hasValidRank()) { | |
d337369a | 548 | long rank = context.getRank(); |
09e86496 FC |
549 | if (fNbEvents <= rank) { |
550 | fNbEvents = rank + 1; | |
551 | } | |
d337369a | 552 | fIndexer.updateIndex(context, timestamp); |
09e86496 | 553 | } |
abfad0aa FC |
554 | } |
555 | ||
3791b5df | 556 | // ------------------------------------------------------------------------ |
d337369a | 557 | // TmfDataProvider |
3791b5df FC |
558 | // ------------------------------------------------------------------------ |
559 | ||
d337369a FC |
560 | /* (non-Javadoc) |
561 | * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#armRequest(org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest) | |
562 | */ | |
3791b5df | 563 | @Override |
6256d8ad AM |
564 | protected ITmfContext armRequest(final ITmfDataRequest request) { |
565 | if ((request instanceof ITmfEventRequest) | |
566 | && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime()) | |
0bfb7d06 | 567 | && (request.getIndex() == 0)) |
0316808c | 568 | { |
6256d8ad AM |
569 | final ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime()); |
570 | ((ITmfEventRequest) request).setStartIndex((int) context.getRank()); | |
3791b5df FC |
571 | return context; |
572 | ||
573 | } | |
574 | return seekEvent(request.getIndex()); | |
575 | } | |
576 | ||
3791b5df | 577 | // ------------------------------------------------------------------------ |
09e86496 | 578 | // toString |
3791b5df FC |
579 | // ------------------------------------------------------------------------ |
580 | ||
d337369a FC |
581 | /* (non-Javadoc) |
582 | * @see java.lang.Object#toString() | |
583 | */ | |
12c155f5 | 584 | @Override |
09e86496 | 585 | @SuppressWarnings("nls") |
afc86f78 | 586 | public synchronized String toString() { |
20658947 FC |
587 | return "TmfTrace [fPath=" + fPath + ", fCacheSize=" + fCacheSize |
588 | + ", fNbEvents=" + fNbEvents + ", fStartTime=" + fStartTime | |
589 | + ", fEndTime=" + fEndTime + ", fStreamingInterval=" + fStreamingInterval + "]"; | |
12c155f5 FC |
590 | } |
591 | ||
8c8bf09f | 592 | } |