analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / trace / TmfTrace.java
CommitLineData
8c8bf09f 1/*******************************************************************************
fbe2a7b2 2 * Copyright (c) 2009, 2015 Ericsson, École Polytechnique de Montréal
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
ea271da6 12 * Patrick Tasse - Updated for removal of context clone
e73a4ba5
GB
13 * Geneviève Bastien - Added timestamp transforms, its saving to file and
14 * timestamp creation functions
8c8bf09f
ASL
15 *******************************************************************************/
16
2bdf0193 17package org.eclipse.tracecompass.tmf.core.trace;
8c8bf09f 18
5db5a3a4
AM
19import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
20
6f4a1d2b 21import java.io.File;
b04903a2 22import java.util.Collection;
35c160d9 23import java.util.Collections;
ff3f02c8 24import java.util.HashSet;
35c160d9 25import java.util.LinkedHashMap;
a51b2b9f 26import java.util.Map;
ff3f02c8 27import java.util.Set;
8c8bf09f 28
828e5592 29import org.eclipse.core.resources.IResource;
42459d24 30import org.eclipse.core.runtime.IStatus;
b22a582a 31import org.eclipse.core.runtime.MultiStatus;
032ecd45 32import org.eclipse.core.runtime.Path;
42459d24 33import org.eclipse.core.runtime.Status;
ba27dd38 34import org.eclipse.jdt.annotation.NonNull;
2b0005f0 35import org.eclipse.jdt.annotation.Nullable;
2bdf0193
AM
36import org.eclipse.tracecompass.internal.tmf.core.Activator;
37import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
38import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
39import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
40import org.eclipse.tracecompass.tmf.core.component.TmfEventProvider;
41import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
b04903a2 42import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
2bdf0193
AM
43import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
44import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
45import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
46import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
47import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
48import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
49import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
50import org.eclipse.tracecompass.tmf.core.signal.TmfTraceUpdatedSignal;
51import org.eclipse.tracecompass.tmf.core.synchronization.ITmfTimestampTransform;
52import org.eclipse.tracecompass.tmf.core.synchronization.TimestampTransformFactory;
53import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
54import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
55import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
56import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
57import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
58import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
59import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
8c8bf09f 60
b04903a2 61import com.google.common.collect.ImmutableList;
ff7b95a5 62import com.google.common.collect.Multimap;
b04903a2 63
8c8bf09f 64/**
09e86496
FC
65 * Abstract implementation of ITmfTrace.
66 * <p>
13cb5f43
FC
67 * Since the concept of 'location' is trace specific, the concrete classes have
68 * to provide the related methods, namely:
69 * <ul>
70 * <li> public ITmfLocation<?> getCurrentLocation()
71 * <li> public double getLocationRatio(ITmfLocation<?> location)
72 * <li> public ITmfContext seekEvent(ITmfLocation<?> location)
73 * <li> public ITmfContext seekEvent(double ratio)
da1a4b39 74 * <li> public IStatus validate(IProject project, String path)
13cb5f43 75 * </ul>
13cb5f43 76 * <p>
6b44794a
MK
77 * When constructing an event, the concrete trace should use the trace's
78 * timestamp transform to create the timestamp, by either transforming the
79 * parsed time value directly or by using the method createTimestamp().
80 * <p>
13cb5f43
FC
81 * The concrete class can either specify its own indexer or use the provided
82 * TmfCheckpointIndexer (default). In this case, the trace cache size will be
83 * used as checkpoint interval.
0bfb7d06 84 *
f7703ed6
FC
85 * @version 1.0
86 * @author Francois Chouinard
87 *
f7703ed6
FC
88 * @see ITmfEvent
89 * @see ITmfTraceIndexer
90 * @see ITmfEventParser
8c8bf09f 91 */
5733be39 92public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace, ITmfEventParser, ITmfTraceCompleteness {
62d1696a 93
e31e01e8 94 // ------------------------------------------------------------------------
b04903a2
AM
95 // Class attributes
96 // ------------------------------------------------------------------------
97
98 /**
99 * Basic aspects that should be valid for all trace types.
100 */
8192209b 101 public static final @NonNull Collection<ITmfEventAspect> BASE_ASPECTS =
5db5a3a4 102 checkNotNull(ImmutableList.of(
b04903a2
AM
103 ITmfEventAspect.BaseAspects.TIMESTAMP,
104 ITmfEventAspect.BaseAspects.EVENT_TYPE,
105 ITmfEventAspect.BaseAspects.CONTENTS
5db5a3a4 106 ));
b04903a2
AM
107
108 // ------------------------------------------------------------------------
109 // Instance attributes
e31e01e8 110 // ------------------------------------------------------------------------
8c8bf09f 111
09e86496
FC
112 // The resource used for persistent properties for this trace
113 private IResource fResource;
114
2b0005f0
PT
115 // The trace type id
116 private @Nullable String fTraceTypeId;
117
b0a282fb 118 // The trace path
12c155f5 119 private String fPath;
b0a282fb 120
0316808c
FC
121 // The trace cache page size
122 private int fCacheSize = ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
62d1696a 123
0316808c 124 // The number of events collected (so far)
e9a6e38e 125 private volatile long fNbEvents = 0;
62d1696a
FC
126
127 // The time span of the event stream
6cfc180e
GB
128 private @NonNull ITmfTimestamp fStartTime = TmfTimestamp.BIG_BANG;
129 private @NonNull ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG;
62d1696a 130
0316808c
FC
131 // The trace streaming interval (0 = no streaming)
132 private long fStreamingInterval = 0;
085d898f 133
0316808c 134 // The trace indexer
6256d8ad 135 private ITmfTraceIndexer fIndexer;
20658947 136
e73a4ba5
GB
137 private ITmfTimestampTransform fTsTransform;
138
ff3f02c8
AM
139 private final Map<String, IAnalysisModule> fAnalysisModules =
140 Collections.synchronizedMap(new LinkedHashMap<String, IAnalysisModule>());
c068a752 141
e31e01e8 142 // ------------------------------------------------------------------------
3791b5df 143 // Construction
e31e01e8 144 // ------------------------------------------------------------------------
8c8bf09f 145
62d1696a 146 /**
3791b5df 147 * The default, parameterless, constructor
62d1696a 148 */
3791b5df
FC
149 public TmfTrace() {
150 super();
fbe2a7b2 151 fIndexer = new TmfCheckpointIndexer(this);
05bd3318
FC
152 }
153
154 /**
8cf330ae 155 * Full constructor.
0bfb7d06 156 *
8cf330ae
AM
157 * @param resource
158 * The resource associated to the trace
159 * @param type
160 * The type of events that will be read from this trace
161 * @param path
162 * The path to the trace on the filesystem
163 * @param cacheSize
164 * The trace cache size. Pass '-1' to use the default specified
165 * in {@link ITmfTrace#DEFAULT_TRACE_CACHE_SIZE}
166 * @param interval
167 * The trace streaming interval. You can use '0' for post-mortem
168 * traces.
8cf330ae
AM
169 * @throws TmfTraceException
170 * If something failed during the opening
20658947 171 */
8cf330ae
AM
172 protected TmfTrace(final IResource resource,
173 final Class<? extends ITmfEvent> type,
174 final String path,
175 final int cacheSize,
5733be39
AM
176 final long interval)
177 throws TmfTraceException {
00641a97 178 super();
0316808c 179 fCacheSize = (cacheSize > 0) ? cacheSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
3791b5df 180 fStreamingInterval = interval;
09e86496 181 initialize(resource, path, type);
8c8bf09f
ASL
182 }
183
3791b5df
FC
184 /**
185 * Copy constructor
0bfb7d06 186 *
3791b5df 187 * @param trace the original trace
063f0d27 188 * @throws TmfTraceException Should not happen usually
3791b5df 189 */
6256d8ad 190 public TmfTrace(final TmfTrace trace) throws TmfTraceException {
3791b5df 191 super();
0316808c 192 if (trace == null) {
3791b5df 193 throw new IllegalArgumentException();
0316808c 194 }
20658947
FC
195 fCacheSize = trace.getCacheSize();
196 fStreamingInterval = trace.getStreamingInterval();
13cb5f43 197 initialize(trace.getResource(), trace.getPath(), trace.getEventType());
3791b5df
FC
198 }
199
032ecd45
MAL
200 /**
201 * Creates the indexer instance. Classes extending this class can override
202 * this to provide a different indexer implementation.
203 *
204 * @param interval the checkpoints interval
205 *
206 * @return the indexer
032ecd45
MAL
207 */
208 protected ITmfTraceIndexer createIndexer(int interval) {
209 return new TmfCheckpointIndexer(this, interval);
210 }
211
7e6347b0
FC
212 // ------------------------------------------------------------------------
213 // ITmfTrace - Initializers
214 // ------------------------------------------------------------------------
215
339d539c 216 @Override
2b0005f0 217 public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type, String name, String traceTypeId) throws TmfTraceException {
6d8922ce
GB
218 if (name == null) {
219 throw new IllegalArgumentException();
220 }
339d539c 221 setName(name);
2b0005f0 222 fTraceTypeId = traceTypeId;
339d539c
PT
223 initTrace(resource, path, type);
224 }
225
7e6347b0 226 @Override
6256d8ad 227 public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
7e6347b0 228 initialize(resource, path, type);
7e6347b0
FC
229 }
230
09e86496 231 /**
1703b536 232 * Initialize the trace common attributes and the base component.
0bfb7d06
MK
233 *
234 * @param resource the Eclipse resource (trace)
1703b536
FC
235 * @param path the trace path
236 * @param type the trace event type
0bfb7d06 237 *
6f4e8ec0 238 * @throws TmfTraceException If something failed during the initialization
3791b5df 239 */
248af329
AM
240 protected void initialize(final IResource resource,
241 final String path,
242 final Class<? extends ITmfEvent> type)
243 throws TmfTraceException {
0316808c 244 if (path == null) {
b4f71e4a 245 throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$
0316808c 246 }
3791b5df 247 fPath = path;
1703b536 248 fResource = resource;
339d539c 249 String traceName = getName();
d40ddf8a 250 if (traceName.isEmpty()) {
339d539c 251 traceName = (resource != null) ? resource.getName() : new Path(path).lastSegment();
1703b536 252 }
3791b5df 253 super.init(traceName, type);
fec1ac0b
BH
254 // register as VIP after super.init() because TmfComponent registers to signal manager there
255 TmfSignalManager.registerVIP(this);
1a3f1ec3
GB
256 if (fIndexer != null) {
257 fIndexer.dispose();
258 }
ab186fbb 259 fIndexer = createIndexer(fCacheSize);
3791b5df
FC
260 }
261
2352aed9
FC
262 /**
263 * Indicates if the path points to an existing file/directory
0bfb7d06 264 *
2352aed9
FC
265 * @param path the path to test
266 * @return true if the file/directory exists
3791b5df 267 */
2352aed9 268 protected boolean fileExists(final String path) {
085d898f 269 final File file = new File(path);
3791b5df
FC
270 return file.exists();
271 }
272
51e75066
AM
273 @Override
274 public void indexTrace(boolean waitForCompletion) {
9e0640dc 275 getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, waitForCompletion);
c7e1020d
FC
276 }
277
c068a752
GB
278 /**
279 * Instantiate the applicable analysis modules and executes the analysis
280 * modules that are meant to be automatically executed
281 *
282 * @return An IStatus indicating whether the analysis could be run
283 * successfully or not
c068a752
GB
284 */
285 protected IStatus executeAnalysis() {
286 MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, null, null);
ba27dd38 287
ff7b95a5 288 Multimap<String, IAnalysisModuleHelper> modules = TmfAnalysisManager.getAnalysisModules();
c068a752
GB
289 for (IAnalysisModuleHelper helper : modules.values()) {
290 try {
291 IAnalysisModule module = helper.newModule(this);
f479550c
GB
292 if (module == null) {
293 continue;
294 }
c068a752
GB
295 fAnalysisModules.put(module.getId(), module);
296 if (module.isAutomatic()) {
297 status.add(module.schedule());
298 }
299 } catch (TmfAnalysisException e) {
26683871 300 status.add(new Status(IStatus.WARNING, Activator.PLUGIN_ID, e.getMessage()));
c068a752
GB
301 }
302 }
303 return status;
304 }
305
306 @Override
ff3f02c8 307 public IAnalysisModule getAnalysisModule(String analysisId) {
c068a752
GB
308 return fAnalysisModules.get(analysisId);
309 }
310
ff3f02c8 311
ff3f02c8
AM
312 @Override
313 public Iterable<IAnalysisModule> getAnalysisModules() {
314 synchronized (fAnalysisModules) {
315 Set<IAnalysisModule> modules = new HashSet<>(fAnalysisModules.values());
316 return modules;
317 }
318 }
319
b04903a2
AM
320 @Override
321 public Iterable<ITmfEventAspect> getEventAspects() {
322 /* By default we provide only the base aspects valid for all trace types */
323 return BASE_ASPECTS;
324 }
325
b5ee6881
FC
326 /**
327 * Clears the trace
328 */
329 @Override
330 public synchronized void dispose() {
1a4205d9 331 /* Clean up the index if applicable */
77551cc2
FC
332 if (getIndexer() != null) {
333 getIndexer().dispose();
334 }
1a4205d9 335
a1529f38 336 /* Clean up the analysis modules */
ff3f02c8
AM
337 synchronized (fAnalysisModules) {
338 for (IAnalysisModule module : fAnalysisModules.values()) {
339 module.dispose();
340 }
6ef5ae35 341 fAnalysisModules.clear();
a1529f38
AM
342 }
343
b5ee6881
FC
344 super.dispose();
345 }
346
3791b5df 347 // ------------------------------------------------------------------------
09e86496 348 // ITmfTrace - Basic getters
e31e01e8 349 // ------------------------------------------------------------------------
8c8bf09f 350
25e48683 351 @Override
0f89d4ba
AM
352 public Class<? extends ITmfEvent> getEventType() {
353 return super.getType();
25e48683
FC
354 }
355
d4011df2 356 @Override
09e86496
FC
357 public IResource getResource() {
358 return fResource;
8c8bf09f
ASL
359 }
360
2b0005f0
PT
361 @Override
362 public @Nullable String getTraceTypeId() {
363 return fTraceTypeId;
364 }
365
d4011df2 366 @Override
09e86496
FC
367 public String getPath() {
368 return fPath;
8c8bf09f
ASL
369 }
370
20658947
FC
371 @Override
372 public int getCacheSize() {
373 return fCacheSize;
374 }
375
20658947
FC
376 @Override
377 public long getStreamingInterval() {
378 return fStreamingInterval;
379 }
380
0316808c
FC
381 /**
382 * @return the trace indexer
383 */
6256d8ad 384 protected ITmfTraceIndexer getIndexer() {
0316808c
FC
385 return fIndexer;
386 }
387
09e86496
FC
388 // ------------------------------------------------------------------------
389 // ITmfTrace - Trace characteristics getters
390 // ------------------------------------------------------------------------
391
d4011df2 392 @Override
e9a6e38e 393 public long getNbEvents() {
3791b5df 394 return fNbEvents;
b0a282fb
FC
395 }
396
d4011df2 397 @Override
6cfc180e 398 public @NonNull TmfTimeRange getTimeRange() {
cb866e08 399 return new TmfTimeRange(fStartTime, fEndTime);
8c8bf09f
ASL
400 }
401
d4011df2 402 @Override
4df4581d 403 public ITmfTimestamp getStartTime() {
4593bd5b 404 return fStartTime;
146a887c
FC
405 }
406
d4011df2 407 @Override
4df4581d 408 public ITmfTimestamp getEndTime() {
4593bd5b 409 return fEndTime;
20658947
FC
410 }
411
66262ad8
BH
412 @Override
413 public ITmfTimestamp getInitialRangeOffset() {
d7ee91bb
PT
414 final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec
415 return new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE);
416 }
417
bb52f9bc
GB
418 @Override
419 public String getHostId() {
420 return this.getName();
421 }
422
20658947 423 // ------------------------------------------------------------------------
d7ee91bb 424 // Convenience setters
20658947
FC
425 // ------------------------------------------------------------------------
426
0316808c
FC
427 /**
428 * Set the trace cache size. Must be done at initialization time.
0bfb7d06 429 *
0316808c
FC
430 * @param cacheSize The trace cache size
431 */
432 protected void setCacheSize(final int cacheSize) {
433 fCacheSize = cacheSize;
434 }
435
436 /**
437 * Set the trace known number of events. This can be quite dynamic
438 * during indexing or for live traces.
0bfb7d06 439 *
0316808c
FC
440 * @param nbEvents The number of events
441 */
442 protected synchronized void setNbEvents(final long nbEvents) {
443 fNbEvents = (nbEvents > 0) ? nbEvents : 0;
444 }
445
20658947
FC
446 /**
447 * Update the trace events time range
0bfb7d06 448 *
20658947
FC
449 * @param range the new time range
450 */
6cfc180e 451 protected void setTimeRange(final @NonNull TmfTimeRange range) {
4593bd5b
AM
452 fStartTime = range.getStartTime();
453 fEndTime = range.getEndTime();
20658947
FC
454 }
455
456 /**
457 * Update the trace chronologically first event timestamp
0bfb7d06 458 *
20658947
FC
459 * @param startTime the new first event timestamp
460 */
6cfc180e 461 protected void setStartTime(final @NonNull ITmfTimestamp startTime) {
4593bd5b 462 fStartTime = startTime;
20658947
FC
463 }
464
465 /**
466 * Update the trace chronologically last event timestamp
0bfb7d06 467 *
20658947
FC
468 * @param endTime the new last event timestamp
469 */
6cfc180e 470 protected void setEndTime(final @NonNull ITmfTimestamp endTime) {
4593bd5b 471 fEndTime = endTime;
20658947
FC
472 }
473
474 /**
0316808c 475 * Set the polling interval for live traces (default = 0 = no streaming).
0bfb7d06 476 *
20658947
FC
477 * @param interval the new trace streaming interval
478 */
479 protected void setStreamingInterval(final long interval) {
1703b536 480 fStreamingInterval = (interval > 0) ? interval : 0;
146a887c
FC
481 }
482
09e86496 483 // ------------------------------------------------------------------------
7e6347b0 484 // ITmfTrace - SeekEvent operations (returning a trace context)
09e86496
FC
485 // ------------------------------------------------------------------------
486
1b70b6dc 487 @Override
7e6347b0 488 public synchronized ITmfContext seekEvent(final long rank) {
09e86496 489
7e6347b0 490 // A rank <= 0 indicates to seek the first event
2352aed9 491 if (rank <= 0) {
1e1bef82 492 ITmfContext context = seekEvent((ITmfLocation) null);
2352aed9
FC
493 context.setRank(0);
494 return context;
495 }
09e86496 496
09e86496 497 // Position the trace at the checkpoint
7e6347b0 498 final ITmfContext context = fIndexer.seekIndex(rank);
09e86496
FC
499
500 // And locate the requested event context
7e6347b0
FC
501 long pos = context.getRank();
502 if (pos < rank) {
c32744d6 503 ITmfEvent event = getNext(context);
0bfb7d06 504 while ((event != null) && (++pos < rank)) {
c32744d6 505 event = getNext(context);
7e6347b0 506 }
09e86496
FC
507 }
508 return context;
1b70b6dc
PT
509 }
510
09e86496 511 @Override
7e6347b0 512 public synchronized ITmfContext seekEvent(final ITmfTimestamp timestamp) {
09e86496 513
7e6347b0 514 // A null timestamp indicates to seek the first event
2352aed9 515 if (timestamp == null) {
1e1bef82 516 ITmfContext context = seekEvent((ITmfLocation) null);
2352aed9
FC
517 context.setRank(0);
518 return context;
519 }
09e86496 520
1703b536 521 // Position the trace at the checkpoint
408e65d2 522 ITmfContext context = fIndexer.seekIndex(timestamp);
09e86496
FC
523
524 // And locate the requested event context
ea271da6
PT
525 ITmfLocation previousLocation = context.getLocation();
526 long previousRank = context.getRank();
527 ITmfEvent event = getNext(context);
065cc19b 528 while (event != null && event.getTimestamp().compareTo(timestamp) < 0) {
ea271da6
PT
529 previousLocation = context.getLocation();
530 previousRank = context.getRank();
531 event = getNext(context);
09e86496 532 }
0316808c
FC
533 if (event == null) {
534 context.setLocation(null);
535 context.setRank(ITmfContext.UNKNOWN_RANK);
ea271da6
PT
536 } else {
537 context.dispose();
538 context = seekEvent(previousLocation);
539 context.setRank(previousRank);
0316808c 540 }
09e86496
FC
541 return context;
542 }
0283f7ff 543
09e86496 544 // ------------------------------------------------------------------------
5733be39 545 // Read operations (returning an actual event)
09e86496
FC
546 // ------------------------------------------------------------------------
547
5733be39
AM
548 @Override
549 public abstract ITmfEvent parseEvent(ITmfContext context);
550
d4011df2 551 @Override
6256d8ad 552 public synchronized ITmfEvent getNext(final ITmfContext context) {
09e86496 553 // parseEvent() does not update the context
5733be39 554 final ITmfEvent event = parseEvent(context);
09e86496 555 if (event != null) {
6cfc180e
GB
556 ITmfTimestamp timestamp = event.getTimestamp();
557 updateAttributes(context, timestamp);
09e86496
FC
558 context.setLocation(getCurrentLocation());
559 context.increaseRank();
09e86496
FC
560 }
561 return event;
562 }
563
d337369a
FC
564 /**
565 * Update the trace attributes
0bfb7d06 566 *
d337369a 567 * @param context the current trace context
2848c377 568 * @param timestamp the corresponding timestamp
d337369a 569 */
6cfc180e 570 protected synchronized void updateAttributes(final ITmfContext context, final @NonNull ITmfTimestamp timestamp) {
065cc19b 571 if (fStartTime.equals(TmfTimestamp.BIG_BANG) || (fStartTime.compareTo(timestamp) > 0)) {
4593bd5b 572 fStartTime = timestamp;
09e86496 573 }
065cc19b 574 if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || (fEndTime.compareTo(timestamp) < 0)) {
4593bd5b 575 fEndTime = timestamp;
09e86496
FC
576 }
577 if (context.hasValidRank()) {
d337369a 578 long rank = context.getRank();
09e86496
FC
579 if (fNbEvents <= rank) {
580 fNbEvents = rank + 1;
581 }
200789b3
AM
582 if (fIndexer != null) {
583 fIndexer.updateIndex(context, timestamp);
584 }
09e86496 585 }
abfad0aa
FC
586 }
587
3791b5df 588 // ------------------------------------------------------------------------
d337369a 589 // TmfDataProvider
3791b5df
FC
590 // ------------------------------------------------------------------------
591
592 @Override
fd3f1eff 593 public synchronized ITmfContext armRequest(final ITmfEventRequest request) {
faa38350
PT
594 if (executorIsShutdown()) {
595 return null;
596 }
fd3f1eff
AM
597 if (!TmfTimestamp.BIG_BANG.equals(request.getRange().getStartTime())
598 && (request.getIndex() == 0)) {
599 final ITmfContext context = seekEvent(request.getRange().getStartTime());
600 request.setStartIndex((int) context.getRank());
8584dc20 601 return context;
8584dc20 602
5419a136
AM
603 }
604 return seekEvent(request.getIndex());
3791b5df
FC
605 }
606
faa38350
PT
607 // ------------------------------------------------------------------------
608 // Signal handlers
609 // ------------------------------------------------------------------------
610
611 /**
612 * Handler for the Trace Opened signal
613 *
614 * @param signal
615 * The incoming signal
faa38350
PT
616 */
617 @TmfSignalHandler
618 public void traceOpened(TmfTraceOpenedSignal signal) {
b9a5bf8f
AM
619 boolean signalIsForUs = false;
620 for (ITmfTrace trace : TmfTraceManager.getTraceSet(signal.getTrace())) {
621 if (trace == this) {
622 signalIsForUs = true;
fe0c44c4 623 break;
faa38350
PT
624 }
625 }
faa38350 626
b9a5bf8f 627 if (!signalIsForUs) {
fe0c44c4
AM
628 return;
629 }
630
631 /*
b9a5bf8f 632 * The signal is either for this trace, or for an experiment containing
fe0c44c4
AM
633 * this trace.
634 */
be4a197a 635 IStatus status = executeAnalysis();
b22a582a
AM
636 if (!status.isOK()) {
637 Activator.log(status);
fe0c44c4
AM
638 }
639
b5e8ee95 640 TmfTraceManager.refreshSupplementaryFiles(this);
fe0c44c4 641
faa38350 642 if (signal.getTrace() == this) {
f8fc4a3a 643 /* Additionally, the signal is directly for this trace. */
faa38350
PT
644 if (getNbEvents() == 0) {
645 return;
646 }
647
f8fc4a3a
PT
648 /* For a streaming trace, the range updated signal should be sent
649 * by the subclass when a new safe time is determined.
650 */
651 if (getStreamingInterval() > 0) {
652 return;
653 }
654
6fd3c6e9
MAL
655 if (isComplete()) {
656 final TmfTimeRange timeRange = new TmfTimeRange(getStartTime(), TmfTimestamp.BIG_CRUNCH);
657 final TmfTraceRangeUpdatedSignal rangeUpdatedsignal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
faa38350 658
6fd3c6e9
MAL
659 // Broadcast in separate thread to prevent deadlock
660 broadcastAsync(rangeUpdatedsignal);
661 }
faa38350
PT
662 return;
663 }
664 }
665
666 /**
667 * Signal handler for the TmfTraceRangeUpdatedSignal signal
668 *
669 * @param signal The incoming signal
faa38350
PT
670 */
671 @TmfSignalHandler
672 public void traceRangeUpdated(final TmfTraceRangeUpdatedSignal signal) {
673 if (signal.getTrace() == this) {
674 getIndexer().buildIndex(getNbEvents(), signal.getRange(), false);
675 }
676 }
677
032ecd45
MAL
678 /**
679 * Signal handler for the TmfTraceUpdatedSignal signal
680 *
681 * @param signal The incoming signal
032ecd45
MAL
682 */
683 @TmfSignalHandler
684 public void traceUpdated(final TmfTraceUpdatedSignal signal) {
685 if (signal.getSource() == getIndexer()) {
686 fNbEvents = signal.getNbEvents();
687 fStartTime = signal.getRange().getStartTime();
688 fEndTime = signal.getRange().getEndTime();
689 }
690 }
691
e73a4ba5
GB
692 // ------------------------------------------------------------------------
693 // Timestamp transformation functions
694 // ------------------------------------------------------------------------
695
e73a4ba5
GB
696 @Override
697 public ITmfTimestampTransform getTimestampTransform() {
698 if (fTsTransform == null) {
6b44794a 699 fTsTransform = TimestampTransformFactory.getTimestampTransform(getResource());
e73a4ba5
GB
700 }
701 return fTsTransform;
702 }
703
e73a4ba5
GB
704 @Override
705 public void setTimestampTransform(final ITmfTimestampTransform tt) {
706 fTsTransform = tt;
6b44794a 707 TimestampTransformFactory.setTimestampTransform(getResource(), tt);
e73a4ba5
GB
708 }
709
e73a4ba5 710 @Override
6cfc180e 711 public @NonNull ITmfTimestamp createTimestamp(long ts) {
b2c463c5 712 return new TmfNanoTimestamp(getTimestampTransform().transform(ts));
e73a4ba5
GB
713 }
714
3791b5df 715 // ------------------------------------------------------------------------
09e86496 716 // toString
3791b5df
FC
717 // ------------------------------------------------------------------------
718
12c155f5 719 @Override
09e86496 720 @SuppressWarnings("nls")
5419a136 721 public synchronized String toString() {
20658947
FC
722 return "TmfTrace [fPath=" + fPath + ", fCacheSize=" + fCacheSize
723 + ", fNbEvents=" + fNbEvents + ", fStartTime=" + fStartTime
724 + ", fEndTime=" + fEndTime + ", fStreamingInterval=" + fStreamingInterval + "]";
12c155f5
FC
725 }
726
6fd3c6e9
MAL
727 @Override
728 public boolean isComplete() {
729 /*
730 * Be default, all traces are "complete" which means no more data will
731 * be added later
732 */
733 return true;
734 }
735
6fd3c6e9
MAL
736 @Override
737 public void setComplete(boolean isComplete) {
738 /*
739 * This should be overridden by trace classes that can support live
740 * reading (traces in an incomplete state)
741 */
742 }
8c8bf09f 743}
This page took 0.157412 seconds and 5 git commands to generate.