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