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