Commit | Line | Data |
---|---|---|
8c8bf09f | 1 | /******************************************************************************* |
09e86496 | 2 | * Copyright (c) 2009, 2010, 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: | |
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; |
c7e2f194 | 19 | import org.eclipse.core.runtime.Path; |
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. | |
f7703ed6 | 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 | */ |
3791b5df | 56 | public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T> implements ITmfTrace<T> { |
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 FC |
81 | // The trace indexer |
82 | private ITmfTraceIndexer<ITmfTrace<ITmfEvent>> fIndexer; | |
20658947 | 83 | |
0316808c FC |
84 | // The trace parser |
85 | private ITmfEventParser<T> 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 FC |
99 | * The standard constructor (non-live trace). Applicable when the trace |
100 | * implements its own parser and if at checkpoint-based index is OK. | |
3791b5df | 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 | */ |
b4f71e4a | 108 | protected TmfTrace(final IResource resource, final Class<T> 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. | |
20658947 FC |
115 | * |
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 | */ |
b4f71e4a | 123 | protected TmfTrace(final IResource resource, final Class<T> 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. | |
3791b5df | 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 | */ |
20658947 | 138 | protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize, |
b4f71e4a | 139 | final long interval, final ITmfTraceIndexer<?> indexer) throws TmfTraceException { |
0316808c | 140 | this(resource, type, path, cacheSize, interval, indexer, null); |
13cb5f43 FC |
141 | } |
142 | ||
143 | /** | |
144 | * The full constructor where trace specific indexer/parser are provided. | |
145 | * | |
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 FC |
153 | */ |
154 | @SuppressWarnings({ "unchecked", "rawtypes" }) | |
155 | protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize, | |
2352aed9 | 156 | final long interval, final ITmfTraceIndexer<?> indexer, final ITmfEventParser<T> 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 | |
167 | * | |
168 | * @param trace the original trace | |
169 | */ | |
20658947 | 170 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
b4f71e4a | 171 | public TmfTrace(final TmfTrace<T> 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 | |
9dc3dee2 | 191 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
b4f71e4a | 192 | public void initTrace(final IResource resource, final String path, final Class<T> type) throws TmfTraceException { |
9dc3dee2 | 193 | fIndexer = new TmfCheckpointIndexer(this, fCacheSize); |
7e6347b0 | 194 | initialize(resource, path, type); |
7e6347b0 FC |
195 | } |
196 | ||
09e86496 | 197 | /** |
1703b536 FC |
198 | * Initialize the trace common attributes and the base component. |
199 | * | |
200 | * @param resource the Eclipse resource (trace) | |
201 | * @param path the trace path | |
202 | * @param type the trace event type | |
203 | * | |
0316808c | 204 | * @throws TmfTraceException |
3791b5df | 205 | */ |
2352aed9 | 206 | @SuppressWarnings("unchecked") |
b4f71e4a | 207 | protected void initialize(final IResource resource, final String path, final Class<T> type) throws TmfTraceException { |
0316808c | 208 | if (path == null) { |
b4f71e4a | 209 | throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$ |
0316808c | 210 | } |
3791b5df | 211 | fPath = path; |
1703b536 | 212 | fResource = resource; |
25e48683 | 213 | String traceName = (resource != null) ? resource.getName() : null; |
1703b536 FC |
214 | // If no resource was provided, extract the display name the trace path |
215 | if (traceName == null) { | |
216 | final int sep = path.lastIndexOf(Path.SEPARATOR); | |
217 | traceName = (sep >= 0) ? path.substring(sep + 1) : path; | |
218 | } | |
2352aed9 FC |
219 | if (fParser == null) { |
220 | if (this instanceof ITmfEventParser) { | |
221 | fParser = (ITmfEventParser<T>) this; | |
222 | } else { | |
223 | throw new TmfTraceException("Invalid trace parser"); //$NON-NLS-1$ | |
224 | } | |
225 | } | |
3791b5df FC |
226 | super.init(traceName, type); |
227 | } | |
228 | ||
2352aed9 FC |
229 | /** |
230 | * Indicates if the path points to an existing file/directory | |
20658947 | 231 | * |
2352aed9 FC |
232 | * @param path the path to test |
233 | * @return true if the file/directory exists | |
3791b5df | 234 | */ |
2352aed9 | 235 | protected boolean fileExists(final String path) { |
085d898f | 236 | final File file = new File(path); |
3791b5df FC |
237 | return file.exists(); |
238 | } | |
239 | ||
c7e1020d FC |
240 | /** |
241 | * Index the trace | |
242 | * | |
243 | * @param waitForCompletion index synchronously (true) or not (false) | |
244 | */ | |
245 | protected void indexTrace(boolean waitForCompletion) { | |
9e0640dc | 246 | getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, waitForCompletion); |
c7e1020d FC |
247 | } |
248 | ||
b5ee6881 FC |
249 | /** |
250 | * Clears the trace | |
251 | */ | |
252 | @Override | |
253 | public synchronized void dispose() { | |
254 | // Clean up the index | |
255 | getIndexer().dispose(); | |
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 | |
09e86496 | 267 | @SuppressWarnings("unchecked") |
13cb5f43 | 268 | public Class<T> getEventType() { |
09e86496 | 269 | return (Class<T>) super.getType(); |
25e48683 FC |
270 | } |
271 | ||
09e86496 FC |
272 | /* (non-Javadoc) |
273 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource() | |
62d1696a | 274 | */ |
d4011df2 | 275 | @Override |
09e86496 FC |
276 | public IResource getResource() { |
277 | return fResource; | |
8c8bf09f ASL |
278 | } |
279 | ||
09e86496 FC |
280 | /* (non-Javadoc) |
281 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getPath() | |
62d1696a | 282 | */ |
d4011df2 | 283 | @Override |
09e86496 FC |
284 | public String getPath() { |
285 | return fPath; | |
8c8bf09f ASL |
286 | } |
287 | ||
20658947 FC |
288 | /* (non-Javadoc) |
289 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getIndexPageSize() | |
290 | */ | |
291 | @Override | |
292 | public int getCacheSize() { | |
293 | return fCacheSize; | |
294 | } | |
295 | ||
296 | /* (non-Javadoc) | |
297 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStreamingInterval() | |
298 | */ | |
299 | @Override | |
300 | public long getStreamingInterval() { | |
301 | return fStreamingInterval; | |
302 | } | |
303 | ||
0316808c FC |
304 | /** |
305 | * @return the trace indexer | |
306 | */ | |
307 | protected ITmfTraceIndexer<ITmfTrace<ITmfEvent>> getIndexer() { | |
308 | return fIndexer; | |
309 | } | |
310 | ||
311 | /** | |
312 | * @return the trace parser | |
313 | */ | |
314 | protected ITmfEventParser<T> getParser() { | |
315 | return fParser; | |
316 | } | |
317 | ||
09e86496 FC |
318 | // ------------------------------------------------------------------------ |
319 | // ITmfTrace - Trace characteristics getters | |
320 | // ------------------------------------------------------------------------ | |
321 | ||
322 | /* (non-Javadoc) | |
323 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNbEvents() | |
b0a282fb | 324 | */ |
d4011df2 | 325 | @Override |
afc86f78 | 326 | public synchronized long getNbEvents() { |
3791b5df | 327 | return fNbEvents; |
b0a282fb FC |
328 | } |
329 | ||
09e86496 FC |
330 | /* (non-Javadoc) |
331 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getTimeRange() | |
62d1696a | 332 | */ |
d4011df2 | 333 | @Override |
12c155f5 | 334 | public TmfTimeRange getTimeRange() { |
cb866e08 | 335 | return new TmfTimeRange(fStartTime, fEndTime); |
8c8bf09f ASL |
336 | } |
337 | ||
09e86496 FC |
338 | /* (non-Javadoc) |
339 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStartTime() | |
e31e01e8 | 340 | */ |
d4011df2 | 341 | @Override |
4df4581d | 342 | public ITmfTimestamp getStartTime() { |
20658947 | 343 | return fStartTime.clone(); |
146a887c FC |
344 | } |
345 | ||
09e86496 FC |
346 | /* (non-Javadoc) |
347 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEndTime() | |
e31e01e8 | 348 | */ |
d4011df2 | 349 | @Override |
4df4581d | 350 | public ITmfTimestamp getEndTime() { |
20658947 FC |
351 | return fEndTime.clone(); |
352 | } | |
353 | ||
354 | // ------------------------------------------------------------------------ | |
0316808c | 355 | // Convenience setters/getters |
20658947 FC |
356 | // ------------------------------------------------------------------------ |
357 | ||
0316808c FC |
358 | /** |
359 | * Set the trace cache size. Must be done at initialization time. | |
360 | * | |
361 | * @param cacheSize The trace cache size | |
362 | */ | |
363 | protected void setCacheSize(final int cacheSize) { | |
364 | fCacheSize = cacheSize; | |
365 | } | |
366 | ||
367 | /** | |
368 | * Set the trace known number of events. This can be quite dynamic | |
369 | * during indexing or for live traces. | |
370 | * | |
371 | * @param nbEvents The number of events | |
372 | */ | |
373 | protected synchronized void setNbEvents(final long nbEvents) { | |
374 | fNbEvents = (nbEvents > 0) ? nbEvents : 0; | |
375 | } | |
376 | ||
20658947 FC |
377 | /** |
378 | * Update the trace events time range | |
379 | * | |
380 | * @param range the new time range | |
381 | */ | |
382 | protected void setTimeRange(final TmfTimeRange range) { | |
383 | fStartTime = range.getStartTime().clone(); | |
384 | fEndTime = range.getEndTime().clone(); | |
385 | } | |
386 | ||
387 | /** | |
388 | * Update the trace chronologically first event timestamp | |
389 | * | |
390 | * @param startTime the new first event timestamp | |
391 | */ | |
392 | protected void setStartTime(final ITmfTimestamp startTime) { | |
393 | fStartTime = startTime.clone(); | |
394 | } | |
395 | ||
396 | /** | |
397 | * Update the trace chronologically last event timestamp | |
398 | * | |
399 | * @param endTime the new last event timestamp | |
400 | */ | |
401 | protected void setEndTime(final ITmfTimestamp endTime) { | |
402 | fEndTime = endTime.clone(); | |
403 | } | |
404 | ||
405 | /** | |
0316808c | 406 | * Set the polling interval for live traces (default = 0 = no streaming). |
20658947 FC |
407 | * |
408 | * @param interval the new trace streaming interval | |
409 | */ | |
410 | protected void setStreamingInterval(final long interval) { | |
1703b536 | 411 | fStreamingInterval = (interval > 0) ? interval : 0; |
146a887c FC |
412 | } |
413 | ||
0316808c FC |
414 | /** |
415 | * Set the trace indexer. Must be done at initialization time. | |
416 | * | |
417 | * @param indexer the trace indexer | |
418 | */ | |
419 | protected void setIndexer(final ITmfTraceIndexer<ITmfTrace<ITmfEvent>> indexer) { | |
420 | fIndexer = indexer; | |
421 | } | |
422 | ||
423 | /** | |
424 | * Set the trace parser. Must be done at initialization time. | |
425 | * | |
426 | * @param parser the new trace parser | |
427 | */ | |
428 | protected void setParser(final ITmfEventParser<T> parser) { | |
429 | fParser = parser; | |
430 | } | |
431 | ||
09e86496 | 432 | // ------------------------------------------------------------------------ |
7e6347b0 | 433 | // ITmfTrace - SeekEvent operations (returning a trace context) |
09e86496 FC |
434 | // ------------------------------------------------------------------------ |
435 | ||
436 | /* (non-Javadoc) | |
7e6347b0 | 437 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(long) |
1b70b6dc PT |
438 | */ |
439 | @Override | |
7e6347b0 | 440 | public synchronized ITmfContext seekEvent(final long rank) { |
09e86496 | 441 | |
7e6347b0 | 442 | // A rank <= 0 indicates to seek the first event |
2352aed9 FC |
443 | if (rank <= 0) { |
444 | ITmfContext context = seekEvent((ITmfLocation<?>) null); | |
445 | context.setRank(0); | |
446 | return context; | |
447 | } | |
09e86496 | 448 | |
09e86496 | 449 | // Position the trace at the checkpoint |
7e6347b0 | 450 | final ITmfContext context = fIndexer.seekIndex(rank); |
09e86496 FC |
451 | |
452 | // And locate the requested event context | |
7e6347b0 FC |
453 | long pos = context.getRank(); |
454 | if (pos < rank) { | |
c32744d6 | 455 | ITmfEvent event = getNext(context); |
7e6347b0 | 456 | while (event != null && ++pos < rank) { |
c32744d6 | 457 | event = getNext(context); |
7e6347b0 | 458 | } |
09e86496 FC |
459 | } |
460 | return context; | |
1b70b6dc PT |
461 | } |
462 | ||
09e86496 | 463 | /* (non-Javadoc) |
7e6347b0 | 464 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp) |
09e86496 FC |
465 | */ |
466 | @Override | |
7e6347b0 | 467 | public synchronized ITmfContext seekEvent(final ITmfTimestamp timestamp) { |
09e86496 | 468 | |
7e6347b0 | 469 | // A null timestamp indicates to seek the first event |
2352aed9 FC |
470 | if (timestamp == null) { |
471 | ITmfContext context = seekEvent((ITmfLocation<?>) null); | |
472 | context.setRank(0); | |
473 | return context; | |
474 | } | |
09e86496 | 475 | |
1703b536 | 476 | // Position the trace at the checkpoint |
7e6347b0 | 477 | final ITmfContext context = fIndexer.seekIndex(timestamp); |
09e86496 FC |
478 | |
479 | // And locate the requested event context | |
7e6347b0 | 480 | final ITmfContext nextEventContext = context.clone(); // Must use clone() to get the right subtype... |
c32744d6 | 481 | ITmfEvent event = getNext(nextEventContext); |
7e6347b0 FC |
482 | while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) { |
483 | context.setLocation(nextEventContext.getLocation().clone()); | |
484 | context.increaseRank(); | |
c32744d6 | 485 | event = getNext(nextEventContext); |
09e86496 | 486 | } |
0316808c FC |
487 | if (event == null) { |
488 | context.setLocation(null); | |
489 | context.setRank(ITmfContext.UNKNOWN_RANK); | |
490 | } | |
09e86496 FC |
491 | return context; |
492 | } | |
493 | ||
09e86496 FC |
494 | // ------------------------------------------------------------------------ |
495 | // ITmfTrace - Read operations (returning an actual event) | |
496 | // ------------------------------------------------------------------------ | |
497 | ||
d337369a | 498 | /* (non-Javadoc) |
b4f71e4a | 499 | * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext) |
abfad0aa | 500 | */ |
d4011df2 | 501 | @Override |
c32744d6 | 502 | public synchronized T getNext(final ITmfContext context) { |
09e86496 | 503 | // parseEvent() does not update the context |
c32744d6 | 504 | final T event = fParser.parseEvent(context); |
09e86496 | 505 | if (event != null) { |
d337369a | 506 | updateAttributes(context, event.getTimestamp()); |
09e86496 FC |
507 | context.setLocation(getCurrentLocation()); |
508 | context.increaseRank(); | |
509 | processEvent(event); | |
510 | } | |
511 | return event; | |
512 | } | |
513 | ||
514 | /** | |
d337369a | 515 | * Hook for special event processing by the concrete class |
7e6347b0 | 516 | * (called by TmfTrace.getEvent()) |
09e86496 | 517 | * |
d337369a | 518 | * @param event the event |
09e86496 FC |
519 | */ |
520 | protected void processEvent(final ITmfEvent event) { | |
d337369a | 521 | // Do nothing |
09e86496 FC |
522 | } |
523 | ||
d337369a FC |
524 | /** |
525 | * Update the trace attributes | |
526 | * | |
527 | * @param context the current trace context | |
2848c377 | 528 | * @param timestamp the corresponding timestamp |
d337369a FC |
529 | */ |
530 | protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) { | |
4cf201de | 531 | if (fStartTime.equals(TmfTimestamp.BIG_BANG) || fStartTime.compareTo(timestamp, false) > 0) { |
49e2f79a | 532 | fStartTime = timestamp.clone(); |
09e86496 | 533 | } |
4cf201de | 534 | if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || fEndTime.compareTo(timestamp, false) < 0) { |
49e2f79a | 535 | fEndTime = timestamp.clone(); |
09e86496 FC |
536 | } |
537 | if (context.hasValidRank()) { | |
d337369a | 538 | long rank = context.getRank(); |
09e86496 FC |
539 | if (fNbEvents <= rank) { |
540 | fNbEvents = rank + 1; | |
541 | } | |
d337369a | 542 | fIndexer.updateIndex(context, timestamp); |
09e86496 | 543 | } |
abfad0aa FC |
544 | } |
545 | ||
3791b5df | 546 | // ------------------------------------------------------------------------ |
d337369a | 547 | // TmfDataProvider |
3791b5df FC |
548 | // ------------------------------------------------------------------------ |
549 | ||
d337369a FC |
550 | /* (non-Javadoc) |
551 | * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#armRequest(org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest) | |
552 | */ | |
3791b5df | 553 | @Override |
9e0640dc | 554 | protected ITmfContext armRequest(final ITmfDataRequest<T> request) { |
3791b5df | 555 | if (request instanceof ITmfEventRequest<?> |
0316808c FC |
556 | && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest<T>) request).getRange().getStartTime()) |
557 | && request.getIndex() == 0) | |
558 | { | |
085d898f | 559 | final ITmfContext context = seekEvent(((ITmfEventRequest<T>) request).getRange().getStartTime()); |
3791b5df FC |
560 | ((ITmfEventRequest<T>) request).setStartIndex((int) context.getRank()); |
561 | return context; | |
562 | ||
563 | } | |
564 | return seekEvent(request.getIndex()); | |
565 | } | |
566 | ||
3791b5df | 567 | // ------------------------------------------------------------------------ |
09e86496 | 568 | // toString |
3791b5df FC |
569 | // ------------------------------------------------------------------------ |
570 | ||
d337369a FC |
571 | /* (non-Javadoc) |
572 | * @see java.lang.Object#toString() | |
573 | */ | |
12c155f5 | 574 | @Override |
09e86496 | 575 | @SuppressWarnings("nls") |
afc86f78 | 576 | public synchronized String toString() { |
20658947 FC |
577 | return "TmfTrace [fPath=" + fPath + ", fCacheSize=" + fCacheSize |
578 | + ", fNbEvents=" + fNbEvents + ", fStartTime=" + fStartTime | |
579 | + ", fEndTime=" + fEndTime + ", fStreamingInterval=" + fStreamingInterval + "]"; | |
12c155f5 FC |
580 | } |
581 | ||
8c8bf09f | 582 | } |