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