lttng: Add Callstack View support for UST traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfTrace.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 Ericsson, École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 * Patrick Tasse - Updated for removal of context clone
13 * Geneviève Bastien - Added timestamp transforms, its saving to file and
14 * timestamp creation functions
15 *******************************************************************************/
16
17 package org.eclipse.linuxtools.tmf.core.trace;
18
19 import java.io.File;
20 import java.io.FileInputStream;
21 import java.io.FileNotFoundException;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.io.ObjectInputStream;
25 import java.io.ObjectOutputStream;
26 import java.util.Collections;
27 import java.util.LinkedHashMap;
28 import java.util.Map;
29
30 import org.eclipse.core.resources.IFolder;
31 import org.eclipse.core.resources.IResource;
32 import org.eclipse.core.runtime.CoreException;
33 import org.eclipse.core.runtime.IPath;
34 import org.eclipse.core.runtime.IStatus;
35 import org.eclipse.core.runtime.MultiStatus;
36 import org.eclipse.core.runtime.Status;
37 import org.eclipse.linuxtools.internal.tmf.core.Activator;
38 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
39 import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
40 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
41 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
42 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
43 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
44 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
45 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
46 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
47 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
48 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
49 import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
50 import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
51 import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform;
52 import org.eclipse.linuxtools.tmf.core.synchronization.TmfTimestampTransform;
53 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
54 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
55 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
56 import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
57 import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
58 import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
59
60 /**
61 * Abstract implementation of ITmfTrace.
62 * <p>
63 * Since the concept of 'location' is trace specific, the concrete classes have
64 * to provide the related methods, namely:
65 * <ul>
66 * <li> public ITmfLocation<?> getCurrentLocation()
67 * <li> public double getLocationRatio(ITmfLocation<?> location)
68 * <li> public ITmfContext seekEvent(ITmfLocation<?> location)
69 * <li> public ITmfContext seekEvent(double ratio)
70 * <li> public IStatus validate(IProject project, String path)
71 * </ul>
72 * A concrete trace must provide its corresponding parser. A common way to
73 * accomplish this is by making the concrete class extend TmfTrace and
74 * implement ITmfEventParser.
75 * <p>
76 * The concrete class can either specify its own indexer or use the provided
77 * TmfCheckpointIndexer (default). In this case, the trace cache size will be
78 * used as checkpoint interval.
79 *
80 * @version 1.0
81 * @author Francois Chouinard
82 *
83 * @see ITmfEvent
84 * @see ITmfTraceIndexer
85 * @see ITmfEventParser
86 */
87 public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
88
89 // ------------------------------------------------------------------------
90 // Attributes
91 // ------------------------------------------------------------------------
92
93 // The resource used for persistent properties for this trace
94 private IResource fResource;
95
96 // The trace path
97 private String fPath;
98
99 // The trace cache page size
100 private int fCacheSize = ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
101
102 // The number of events collected (so far)
103 private long fNbEvents = 0;
104
105 // The time span of the event stream
106 private ITmfTimestamp fStartTime = TmfTimestamp.BIG_BANG;
107 private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG;
108
109 // The trace streaming interval (0 = no streaming)
110 private long fStreamingInterval = 0;
111
112 // The trace indexer
113 private ITmfTraceIndexer fIndexer;
114
115 // The trace parser
116 private ITmfEventParser fParser;
117
118 // The trace's statistics
119 private ITmfStatistics fStatistics;
120
121 /**
122 * The collection of state systems that are registered with this trace. Each
123 * sub-class can decide to add its (one or many) state system to this map
124 * during their {@link #buildStateSystem()}.
125 *
126 * @since 2.0
127 */
128 protected final Map<String, ITmfStateSystem> fStateSystems =
129 new LinkedHashMap<String, ITmfStateSystem>();
130
131 private ITmfTimestampTransform fTsTransform;
132
133 private static final String SYNCHRONIZATION_FORMULA_FILE = "sync_formula"; //$NON-NLS-1$
134
135 // ------------------------------------------------------------------------
136 // Construction
137 // ------------------------------------------------------------------------
138
139 /**
140 * The default, parameterless, constructor
141 */
142 public TmfTrace() {
143 super();
144 }
145
146 /**
147 * Full constructor.
148 *
149 * @param resource
150 * The resource associated to the trace
151 * @param type
152 * The type of events that will be read from this trace
153 * @param path
154 * The path to the trace on the filesystem
155 * @param cacheSize
156 * The trace cache size. Pass '-1' to use the default specified
157 * in {@link ITmfTrace#DEFAULT_TRACE_CACHE_SIZE}
158 * @param interval
159 * The trace streaming interval. You can use '0' for post-mortem
160 * traces.
161 * @param indexer
162 * The trace indexer. You can pass 'null' to use a default
163 * checkpoint indexer.
164 * @param parser
165 * The trace event parser. Use 'null' if (and only if) the trace
166 * object itself is also the ITmfEventParser to be used.
167 * @throws TmfTraceException
168 * If something failed during the opening
169 */
170 protected TmfTrace(final IResource resource,
171 final Class<? extends ITmfEvent> type,
172 final String path,
173 final int cacheSize,
174 final long interval,
175 final ITmfTraceIndexer indexer,
176 final ITmfEventParser parser)
177 throws TmfTraceException {
178 super();
179 fCacheSize = (cacheSize > 0) ? cacheSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
180 fStreamingInterval = interval;
181 fIndexer = (indexer != null) ? indexer : new TmfCheckpointIndexer(this, fCacheSize);
182 fParser = parser;
183 initialize(resource, path, type);
184 }
185
186 /**
187 * Copy constructor
188 *
189 * @param trace the original trace
190 * @throws TmfTraceException Should not happen usually
191 */
192 public TmfTrace(final TmfTrace trace) throws TmfTraceException {
193 super();
194 if (trace == null) {
195 throw new IllegalArgumentException();
196 }
197 fCacheSize = trace.getCacheSize();
198 fStreamingInterval = trace.getStreamingInterval();
199 fIndexer = new TmfCheckpointIndexer(this);
200 fParser = trace.fParser;
201 initialize(trace.getResource(), trace.getPath(), trace.getEventType());
202 }
203
204 // ------------------------------------------------------------------------
205 // ITmfTrace - Initializers
206 // ------------------------------------------------------------------------
207
208 @Override
209 public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
210 fIndexer = new TmfCheckpointIndexer(this, fCacheSize);
211 initialize(resource, path, type);
212 }
213
214 /**
215 * Initialize the trace common attributes and the base component.
216 *
217 * @param resource the Eclipse resource (trace)
218 * @param path the trace path
219 * @param type the trace event type
220 *
221 * @throws TmfTraceException If something failed during the initialization
222 */
223 protected void initialize(final IResource resource,
224 final String path,
225 final Class<? extends ITmfEvent> type)
226 throws TmfTraceException {
227 if (path == null) {
228 throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$
229 }
230 fPath = path;
231 fResource = resource;
232 String traceName = (resource != null) ? resource.getName() : null;
233 // If no resource was provided, extract the display name the trace path
234 if (traceName == null) {
235 final int sep = path.lastIndexOf(IPath.SEPARATOR);
236 traceName = (sep >= 0) ? path.substring(sep + 1) : path;
237 }
238 if (fParser == null) {
239 if (this instanceof ITmfEventParser) {
240 fParser = (ITmfEventParser) this;
241 } else {
242 throw new TmfTraceException("Invalid trace parser"); //$NON-NLS-1$
243 }
244 }
245 super.init(traceName, type);
246 // register as VIP after super.init() because TmfComponent registers to signal manager there
247 TmfSignalManager.registerVIP(this);
248 }
249
250 /**
251 * Indicates if the path points to an existing file/directory
252 *
253 * @param path the path to test
254 * @return true if the file/directory exists
255 */
256 protected boolean fileExists(final String path) {
257 final File file = new File(path);
258 return file.exists();
259 }
260
261 /**
262 * @since 2.0
263 */
264 @Override
265 public void indexTrace(boolean waitForCompletion) {
266 getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, waitForCompletion);
267 }
268
269 /**
270 * The default implementation of TmfTrace uses a TmfStatistics back-end.
271 * Override this if you want to specify another type (or none at all).
272 *
273 * @return An IStatus indicating if the statistics could be built
274 * successfully or not.
275 * @since 3.0
276 */
277 protected IStatus buildStatistics() {
278 /*
279 * Initialize the statistics provider, but only if a Resource has been
280 * set (so we don't build it for experiments, for unit tests, etc.)
281 */
282 try {
283 fStatistics = (fResource == null ? null : new TmfStateStatistics(this) );
284 } catch (TmfTraceException e) {
285 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
286 }
287 return Status.OK_STATUS;
288 }
289
290 /**
291 * Build the state system(s) associated with this trace type.
292 *
293 * @return An IStatus indicating if the state system could be build
294 * successfully or not.
295 * @since 3.0
296 */
297 protected IStatus buildStateSystem() {
298 /*
299 * Nothing is done in the base implementation, please specify
300 * how/if to register a new state system in derived classes.
301 */
302 return Status.OK_STATUS;
303 }
304
305 /**
306 * Clears the trace
307 */
308 @Override
309 public synchronized void dispose() {
310 /* Clean up the index if applicable */
311 if (getIndexer() != null) {
312 getIndexer().dispose();
313 }
314
315 /* Clean up the statistics */
316 if (fStatistics != null) {
317 fStatistics.dispose();
318 }
319
320 /* Clean up the state systems */
321 for (ITmfStateSystem ss : fStateSystems.values()) {
322 ss.dispose();
323 }
324
325 super.dispose();
326 }
327
328 // ------------------------------------------------------------------------
329 // ITmfTrace - Basic getters
330 // ------------------------------------------------------------------------
331
332 @Override
333 public Class<ITmfEvent> getEventType() {
334 return (Class<ITmfEvent>) super.getType();
335 }
336
337 @Override
338 public IResource getResource() {
339 return fResource;
340 }
341
342 @Override
343 public String getPath() {
344 return fPath;
345 }
346
347 @Override
348 public int getCacheSize() {
349 return fCacheSize;
350 }
351
352 @Override
353 public long getStreamingInterval() {
354 return fStreamingInterval;
355 }
356
357 /**
358 * @return the trace indexer
359 * @since 3.0
360 */
361 protected ITmfTraceIndexer getIndexer() {
362 return fIndexer;
363 }
364
365 /**
366 * @return the trace parser
367 */
368 protected ITmfEventParser getParser() {
369 return fParser;
370 }
371
372 /**
373 * @since 2.0
374 */
375 @Override
376 public ITmfStatistics getStatistics() {
377 return fStatistics;
378 }
379
380 /**
381 * @since 2.0
382 */
383 @Override
384 public final Map<String, ITmfStateSystem> getStateSystems() {
385 return Collections.unmodifiableMap(fStateSystems);
386 }
387
388 /**
389 * @since 2.0
390 */
391 @Override
392 public final void registerStateSystem(String id, ITmfStateSystem ss) {
393 fStateSystems.put(id, ss);
394 }
395
396 // ------------------------------------------------------------------------
397 // ITmfTrace - Trace characteristics getters
398 // ------------------------------------------------------------------------
399
400 @Override
401 public synchronized long getNbEvents() {
402 return fNbEvents;
403 }
404
405 /**
406 * @since 2.0
407 */
408 @Override
409 public TmfTimeRange getTimeRange() {
410 return new TmfTimeRange(fStartTime, fEndTime);
411 }
412
413 /**
414 * @since 2.0
415 */
416 @Override
417 public ITmfTimestamp getStartTime() {
418 return fStartTime;
419 }
420
421 /**
422 * @since 2.0
423 */
424 @Override
425 public ITmfTimestamp getEndTime() {
426 return fEndTime;
427 }
428
429 /**
430 * @since 2.0
431 */
432 @Override
433 public ITmfTimestamp getInitialRangeOffset() {
434 final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec
435 return new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE);
436 }
437
438 /**
439 * @since 3.0
440 */
441 @Override
442 public String getHostId() {
443 return this.getName();
444 }
445
446 // ------------------------------------------------------------------------
447 // Convenience setters
448 // ------------------------------------------------------------------------
449
450 /**
451 * Set the trace cache size. Must be done at initialization time.
452 *
453 * @param cacheSize The trace cache size
454 */
455 protected void setCacheSize(final int cacheSize) {
456 fCacheSize = cacheSize;
457 }
458
459 /**
460 * Set the trace known number of events. This can be quite dynamic
461 * during indexing or for live traces.
462 *
463 * @param nbEvents The number of events
464 */
465 protected synchronized void setNbEvents(final long nbEvents) {
466 fNbEvents = (nbEvents > 0) ? nbEvents : 0;
467 }
468
469 /**
470 * Update the trace events time range
471 *
472 * @param range the new time range
473 * @since 2.0
474 */
475 protected void setTimeRange(final TmfTimeRange range) {
476 fStartTime = range.getStartTime();
477 fEndTime = range.getEndTime();
478 }
479
480 /**
481 * Update the trace chronologically first event timestamp
482 *
483 * @param startTime the new first event timestamp
484 * @since 2.0
485 */
486 protected void setStartTime(final ITmfTimestamp startTime) {
487 fStartTime = startTime;
488 }
489
490 /**
491 * Update the trace chronologically last event timestamp
492 *
493 * @param endTime the new last event timestamp
494 * @since 2.0
495 */
496 protected void setEndTime(final ITmfTimestamp endTime) {
497 fEndTime = endTime;
498 }
499
500 /**
501 * Set the polling interval for live traces (default = 0 = no streaming).
502 *
503 * @param interval the new trace streaming interval
504 */
505 protected void setStreamingInterval(final long interval) {
506 fStreamingInterval = (interval > 0) ? interval : 0;
507 }
508
509 /**
510 * Set the trace indexer. Must be done at initialization time.
511 *
512 * @param indexer the trace indexer
513 * @since 3.0
514 */
515 protected void setIndexer(final ITmfTraceIndexer indexer) {
516 fIndexer = indexer;
517 }
518
519 /**
520 * Set the trace parser. Must be done at initialization time.
521 *
522 * @param parser the new trace parser
523 */
524 protected void setParser(final ITmfEventParser parser) {
525 fParser = parser;
526 }
527
528 // ------------------------------------------------------------------------
529 // ITmfTrace - SeekEvent operations (returning a trace context)
530 // ------------------------------------------------------------------------
531
532 @Override
533 public synchronized ITmfContext seekEvent(final long rank) {
534
535 // A rank <= 0 indicates to seek the first event
536 if (rank <= 0) {
537 ITmfContext context = seekEvent((ITmfLocation) null);
538 context.setRank(0);
539 return context;
540 }
541
542 // Position the trace at the checkpoint
543 final ITmfContext context = fIndexer.seekIndex(rank);
544
545 // And locate the requested event context
546 long pos = context.getRank();
547 if (pos < rank) {
548 ITmfEvent event = getNext(context);
549 while ((event != null) && (++pos < rank)) {
550 event = getNext(context);
551 }
552 }
553 return context;
554 }
555
556 /**
557 * @since 2.0
558 */
559 @Override
560 public synchronized ITmfContext seekEvent(final ITmfTimestamp timestamp) {
561
562 // A null timestamp indicates to seek the first event
563 if (timestamp == null) {
564 ITmfContext context = seekEvent((ITmfLocation) null);
565 context.setRank(0);
566 return context;
567 }
568
569 // Position the trace at the checkpoint
570 ITmfContext context = fIndexer.seekIndex(timestamp);
571
572 // And locate the requested event context
573 ITmfLocation previousLocation = context.getLocation();
574 long previousRank = context.getRank();
575 ITmfEvent event = getNext(context);
576 while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
577 previousLocation = context.getLocation();
578 previousRank = context.getRank();
579 event = getNext(context);
580 }
581 if (event == null) {
582 context.setLocation(null);
583 context.setRank(ITmfContext.UNKNOWN_RANK);
584 } else {
585 context.dispose();
586 context = seekEvent(previousLocation);
587 context.setRank(previousRank);
588 }
589 return context;
590 }
591
592 // ------------------------------------------------------------------------
593 // ITmfTrace - Read operations (returning an actual event)
594 // ------------------------------------------------------------------------
595
596 @Override
597 public synchronized ITmfEvent getNext(final ITmfContext context) {
598 // parseEvent() does not update the context
599 final ITmfEvent event = fParser.parseEvent(context);
600 if (event != null) {
601 updateAttributes(context, event.getTimestamp());
602 context.setLocation(getCurrentLocation());
603 context.increaseRank();
604 processEvent(event);
605 }
606 return event;
607 }
608
609 /**
610 * Hook for special event processing by the concrete class
611 * (called by TmfTrace.getEvent())
612 *
613 * @param event the event
614 */
615 protected void processEvent(final ITmfEvent event) {
616 // Do nothing
617 }
618
619 /**
620 * Update the trace attributes
621 *
622 * @param context the current trace context
623 * @param timestamp the corresponding timestamp
624 * @since 2.0
625 */
626 protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) {
627 if (fStartTime.equals(TmfTimestamp.BIG_BANG) || (fStartTime.compareTo(timestamp, false) > 0)) {
628 fStartTime = timestamp;
629 }
630 if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || (fEndTime.compareTo(timestamp, false) < 0)) {
631 fEndTime = timestamp;
632 }
633 if (context.hasValidRank()) {
634 long rank = context.getRank();
635 if (fNbEvents <= rank) {
636 fNbEvents = rank + 1;
637 }
638 if (fIndexer != null) {
639 fIndexer.updateIndex(context, timestamp);
640 }
641 }
642 }
643
644 // ------------------------------------------------------------------------
645 // TmfDataProvider
646 // ------------------------------------------------------------------------
647
648 /**
649 * @since 2.0
650 */
651 @Override
652 public synchronized ITmfContext armRequest(final ITmfDataRequest request) {
653 if (executorIsShutdown()) {
654 return null;
655 }
656 if ((request instanceof ITmfEventRequest)
657 && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime())
658 && (request.getIndex() == 0))
659 {
660 final ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
661 ((ITmfEventRequest) request).setStartIndex((int) context.getRank());
662 return context;
663
664 }
665 return seekEvent(request.getIndex());
666 }
667
668 // ------------------------------------------------------------------------
669 // Signal handlers
670 // ------------------------------------------------------------------------
671
672 /**
673 * Handler for the Trace Opened signal
674 *
675 * @param signal
676 * The incoming signal
677 * @since 2.0
678 */
679 @TmfSignalHandler
680 public void traceOpened(TmfTraceOpenedSignal signal) {
681 boolean signalIsForUs = false;
682 for (ITmfTrace trace : TmfTraceManager.getTraceSet(signal.getTrace())) {
683 if (trace == this) {
684 signalIsForUs = true;
685 break;
686 }
687 }
688
689 if (!signalIsForUs) {
690 return;
691 }
692
693 /*
694 * The signal is either for this trace, or for an experiment containing
695 * this trace.
696 */
697 MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, null, null);
698 status.add(buildStatistics());
699 status.add(buildStateSystem());
700 if (!status.isOK()) {
701 Activator.log(status);
702 }
703
704 /* Refresh the project, so it can pick up new files that got created. */
705 try {
706 if (fResource != null) {
707 fResource.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
708 }
709 } catch (CoreException e) {
710 e.printStackTrace();
711 }
712
713 if (signal.getTrace() == this) {
714 /* Additionally, the signal is directly for this trace. */
715 if (getNbEvents() == 0) {
716 return;
717 }
718
719 /* For a streaming trace, the range updated signal should be sent
720 * by the subclass when a new safe time is determined.
721 */
722 if (getStreamingInterval() > 0) {
723 return;
724 }
725
726 final TmfTimeRange timeRange = new TmfTimeRange(getStartTime(), TmfTimestamp.BIG_CRUNCH);
727 final TmfTraceRangeUpdatedSignal rangeUpdatedsignal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
728
729 // Broadcast in separate thread to prevent deadlock
730 new Thread() {
731 @Override
732 public void run() {
733 broadcast(rangeUpdatedsignal);
734 }
735 }.start();
736 return;
737 }
738 }
739
740 /**
741 * Signal handler for the TmfTraceRangeUpdatedSignal signal
742 *
743 * @param signal The incoming signal
744 * @since 2.0
745 */
746 @TmfSignalHandler
747 public void traceRangeUpdated(final TmfTraceRangeUpdatedSignal signal) {
748 if (signal.getTrace() == this) {
749 getIndexer().buildIndex(getNbEvents(), signal.getRange(), false);
750 }
751 }
752
753 /**
754 * Returns the file resource used to store synchronization formula. The file
755 * may not exist.
756 *
757 * @return the synchronization file
758 */
759 private File getSyncFormulaFile() {
760 File file = null;
761 if (fResource instanceof IFolder) {
762 try {
763 String supplDirectory;
764
765 supplDirectory = fResource.getPersistentProperty(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER);
766
767 file = new File(supplDirectory + File.separator + SYNCHRONIZATION_FORMULA_FILE);
768
769 } catch (CoreException e) {
770
771 }
772 }
773 return file;
774 }
775
776 // ------------------------------------------------------------------------
777 // Timestamp transformation functions
778 // ------------------------------------------------------------------------
779
780 /**
781 * @since 3.0
782 */
783 @Override
784 public ITmfTimestampTransform getTimestampTransform() {
785 if (fTsTransform == null) {
786 /* Check if a formula is stored somewhere in the resources */
787 File sync_file = getSyncFormulaFile();
788 if (sync_file != null && sync_file.exists()) {
789
790 try {
791 FileInputStream fis = new FileInputStream(sync_file);
792 ObjectInputStream ois = new ObjectInputStream(fis);
793 fTsTransform = (ITmfTimestampTransform) ois.readObject();
794
795 ois.close();
796 fis.close();
797 } catch (ClassNotFoundException e1) {
798 fTsTransform = TmfTimestampTransform.IDENTITY;
799 } catch (FileNotFoundException e1) {
800 fTsTransform = TmfTimestampTransform.IDENTITY;
801 } catch (IOException e1) {
802 fTsTransform = TmfTimestampTransform.IDENTITY;
803 }
804 } else {
805 fTsTransform = TmfTimestampTransform.IDENTITY;
806 }
807 }
808 return fTsTransform;
809 }
810
811 /**
812 * @since 3.0
813 */
814 @Override
815 public void setTimestampTransform(final ITmfTimestampTransform tt) {
816 fTsTransform = tt;
817
818 /* Save the timestamp transform to a file */
819 File sync_file = getSyncFormulaFile();
820 if (sync_file != null) {
821 if (sync_file.exists()) {
822 sync_file.delete();
823 }
824 FileOutputStream fos;
825 ObjectOutputStream oos;
826
827 /* Save the header of the file */
828 try {
829 fos = new FileOutputStream(sync_file, false);
830 oos = new ObjectOutputStream(fos);
831
832 oos.writeObject(fTsTransform);
833 oos.close();
834 fos.close();
835 } catch (IOException e1) {
836 Activator.logError("Error writing timestamp transform for trace", e1); //$NON-NLS-1$
837 }
838 }
839 }
840
841 /**
842 * @since 3.0
843 */
844 @Override
845 public ITmfTimestamp createTimestamp(long ts) {
846 return new TmfTimestamp(getTimestampTransform().transform(ts));
847 }
848
849 // ------------------------------------------------------------------------
850 // toString
851 // ------------------------------------------------------------------------
852
853 @Override
854 @SuppressWarnings("nls")
855 public synchronized String toString() {
856 return "TmfTrace [fPath=" + fPath + ", fCacheSize=" + fCacheSize
857 + ", fNbEvents=" + fNbEvents + ", fStartTime=" + fStartTime
858 + ", fEndTime=" + fEndTime + ", fStreamingInterval=" + fStreamingInterval + "]";
859 }
860
861 }
This page took 0.050351 seconds and 5 git commands to generate.