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