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