1 /*******************************************************************************
2 * Copyright (c) 2012, 2017 Ericsson, École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are made
5 * 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
10 * Matthew Khouzam - Initial API and implementation
11 * Patrick Tasse - Updated for removal of context clone
12 * Geneviève Bastien - Added the createTimestamp function
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
;
17 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
19 import java
.nio
.BufferOverflowException
;
20 import java
.nio
.ByteBuffer
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Collection
;
23 import java
.util
.Collections
;
24 import java
.util
.HashMap
;
25 import java
.util
.HashSet
;
26 import java
.util
.List
;
28 import java
.util
.Objects
;
31 import org
.eclipse
.core
.resources
.IProject
;
32 import org
.eclipse
.core
.resources
.IResource
;
33 import org
.eclipse
.core
.runtime
.CoreException
;
34 import org
.eclipse
.core
.runtime
.IStatus
;
35 import org
.eclipse
.core
.runtime
.Status
;
36 import org
.eclipse
.jdt
.annotation
.NonNull
;
37 import org
.eclipse
.jdt
.annotation
.Nullable
;
38 import org
.eclipse
.tracecompass
.ctf
.core
.CTFException
;
39 import org
.eclipse
.tracecompass
.ctf
.core
.event
.CTFCallsite
;
40 import org
.eclipse
.tracecompass
.ctf
.core
.event
.CTFClock
;
41 import org
.eclipse
.tracecompass
.ctf
.core
.event
.IEventDeclaration
;
42 import org
.eclipse
.tracecompass
.ctf
.core
.event
.types
.StructDeclaration
;
43 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFStreamInput
;
44 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTrace
;
45 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFTraceReader
;
46 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.ICTFStream
;
47 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.Metadata
;
48 import org
.eclipse
.tracecompass
.internal
.tmf
.ctf
.core
.Activator
;
49 import org
.eclipse
.tracecompass
.internal
.tmf
.ctf
.core
.trace
.iterator
.CtfIterator
;
50 import org
.eclipse
.tracecompass
.internal
.tmf
.ctf
.core
.trace
.iterator
.CtfIteratorManager
;
51 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
52 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
53 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventField
;
54 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.ITmfEventAspect
;
55 import org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
.TmfBaseAspects
;
56 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfTraceException
;
57 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.ITmfPropertiesProvider
;
58 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
59 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
60 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ICyclesConverter
;
61 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
62 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTraceKnownSize
;
63 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTraceWithPreDefinedEvents
;
64 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTrace
;
65 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TraceValidationStatus
;
66 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.indexer
.ITmfPersistentlyIndexable
;
67 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.indexer
.ITmfTraceIndexer
;
68 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.indexer
.TmfBTreeTraceIndexer
;
69 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.indexer
.checkpoint
.ITmfCheckpoint
;
70 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.indexer
.checkpoint
.TmfCheckpoint
;
71 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.location
.ITmfLocation
;
72 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.CtfConstants
;
73 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.context
.CtfLocation
;
74 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.context
.CtfLocationInfo
;
75 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.context
.CtfTmfContext
;
76 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
77 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEventFactory
;
78 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEventType
;
79 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.aspect
.CtfChannelAspect
;
80 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.aspect
.CtfCpuAspect
;
81 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.lookup
.CtfTmfCallsite
;
83 import com
.google
.common
.collect
.ImmutableList
;
84 import com
.google
.common
.collect
.ImmutableSet
;
87 * The CTf trace handler
90 * @author Matthew khouzam
92 public class CtfTmfTrace
extends TmfTrace
93 implements ITmfPropertiesProvider
, ITmfPersistentlyIndexable
,
94 ITmfTraceWithPreDefinedEvents
, ITmfTraceKnownSize
, ICyclesConverter
{
96 // -------------------------------------------
98 // -------------------------------------------
101 * Clock offset property
105 public static final String CLOCK_OFFSET
= "clock_offset"; //$NON-NLS-1$
108 * Default cache size for CTF traces
110 protected static final int DEFAULT_CACHE_SIZE
= 50000;
113 * Event aspects available for all CTF traces
117 protected static final @NonNull Collection
<@NonNull ITmfEventAspect
<?
>> CTF_ASPECTS
= ImmutableList
.of(
118 TmfBaseAspects
.getTimestampAspect(),
119 new CtfChannelAspect(),
121 TmfBaseAspects
.getEventTypeAspect(),
122 TmfBaseAspects
.getContentsAspect());
125 * The Ctf clock unique identifier field
127 private static final String CLOCK_HOST_PROPERTY
= "uuid"; //$NON-NLS-1$
128 private static final int CONFIDENCE
= 10;
129 private static final int MIN_CONFIDENCE
= 1;
132 * This is a reduction factor to avoid overflows.
134 private static final long REDUCTION_FACTOR
= 4096;
137 * Average CTF event size, used to estimate the trace size. (Inspired by
138 * empirical observations with LTTng kernel traces, to avoid hanging at 100%
141 * TODO: Find a more suitable approximation, perhaps per concrete trace type
142 * or per trace directly with the metadata
144 private static final int CTF_AVG_EVENT_SIZE
= 16;
146 // -------------------------------------------
148 // -------------------------------------------
150 private final Map
<@NonNull String
, @NonNull CtfTmfEventType
> fContainedEventTypes
= Collections
.synchronizedMap(new HashMap
<>());
152 private final CtfIteratorManager fIteratorManager
= new CtfIteratorManager(this);
154 private final @NonNull CtfTmfEventFactory fEventFactory
;
156 /** Reference to the CTF Trace */
157 private CTFTrace fTrace
;
159 // -------------------------------------------
161 // -------------------------------------------
164 * Default constructor
166 public CtfTmfTrace() {
169 /* Use default event factory */
170 fEventFactory
= CtfTmfEventFactory
.instance();
174 * Constructor for sub-classes to specify their own event factory.
176 * @param eventFactory
177 * The event factory to use to generate trace events
180 protected CtfTmfTrace(@NonNull CtfTmfEventFactory eventFactory
) {
182 fEventFactory
= eventFactory
;
185 // -------------------------------------------
186 // TmfTrace Overrides
187 // -------------------------------------------
192 * The resource associated with this trace
194 * The path to the trace file
196 * The type of events that will be read from this trace
197 * @throws TmfTraceException
198 * If something went wrong while reading the trace
201 public void initTrace(final IResource resource
, final String path
, final Class
<?
extends ITmfEvent
> eventType
)
202 throws TmfTraceException
{
204 * Set the cache size. This has to be done before the call to super()
205 * because the super needs to know the cache size.
209 super.initTrace(resource
, path
, eventType
);
212 this.fTrace
= new CTFTrace(path
);
214 /* Set the start and (current) end times for this trace */
215 ctx
= (CtfTmfContext
) seekEvent(0L);
216 CtfTmfEvent event
= getNext(ctx
);
217 if ((ctx
.getLocation().equals(CtfIterator
.NULL_LOCATION
)) || (ctx
.getCurrentEvent() == null)) {
218 /* Handle the case where the trace is empty */
219 this.setStartTime(TmfTimestamp
.BIG_BANG
);
221 final ITmfTimestamp curTime
= event
.getTimestamp();
222 this.setStartTime(curTime
);
223 this.setEndTime(curTime
);
226 * Register every event type. When you call getType, it will
227 * register a trace to that type in the TmfEventTypeManager
229 try (CtfIterator iter
= fIteratorManager
.getIterator(ctx
)) {
230 Set
<@NonNull ITmfEventField
> streamContextNames
= new HashSet
<>();
231 for (IEventDeclaration ied
: iter
.getEventDeclarations()) {
232 CtfTmfEventType ctfTmfEventType
= fContainedEventTypes
.get(ied
.getName());
233 if (ctfTmfEventType
== null) {
234 List
<ITmfEventField
> content
= new ArrayList
<>();
236 /* Should only return null the first time */
237 final StructDeclaration fields
= ied
.getFields();
238 if (fields
!= null) {
239 for (String fieldName
: fields
.getFieldsList()) {
240 content
.add(new TmfEventField(checkNotNull(fieldName
), null, null));
244 /* Add stream contexts */
245 final StructDeclaration streamContexts
= ied
.getStream().getEventContextDecl();
246 if (streamContextNames
.isEmpty()) {
247 if (streamContexts
!= null) {
248 for (String fieldName
: streamContexts
.getFieldsList()) {
249 streamContextNames
.add(new TmfEventField(checkNotNull(CtfConstants
.CONTEXT_FIELD_PREFIX
+ fieldName
), null, null));
253 content
.addAll(streamContextNames
);
255 if (!content
.isEmpty()) {
256 ITmfEventField contentTree
= new TmfEventField(
257 ITmfEventField
.ROOT_FIELD_ID
,
259 content
.toArray(new ITmfEventField
[content
.size()]));
261 ctfTmfEventType
= new CtfTmfEventType(checkNotNull(ied
.getName()), contentTree
);
262 fContainedEventTypes
.put(ctfTmfEventType
.getName(), ctfTmfEventType
);
268 } catch (final CTFException e
) {
270 * If it failed at the init(), we can assume it's because the file
271 * was not found or was not recognized as a CTF trace. Throw into
272 * the new type of exception expected by the rest of TMF.
274 throw new TmfTraceException(e
.getMessage(), e
);
279 public synchronized void dispose() {
280 fIteratorManager
.dispose();
281 if (fTrace
!= null) {
290 * The default implementation of a CTF trace.
292 * Firstly a weak validation of the metadata is done to determine if the
293 * path is actually for a CTF trace. After that a full validation is done.
295 * If the weak and full validation are successful the confidence is set to
298 * If the weak validation was successful, but the full validation fails a
299 * TraceValidationStatus with severity warning and confidence of 1 is
302 * If both weak and full validation fails an error status is returned.
305 public IStatus
validate(final IProject project
, final String path
) {
306 boolean isMetadataFile
= false;
308 isMetadataFile
= Metadata
.preValidate(path
);
309 } catch (final CTFException e
) {
310 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.CtfTmfTrace_ReadingError
+ ": " + e
.toString(), e
); //$NON-NLS-1$
313 if (isMetadataFile
) {
314 // Trace is pre-validated, continue will full validation
316 final CTFTrace trace
= new CTFTrace(path
);
317 if (!trace
.majorIsSet()) {
318 if (isMetadataFile
) {
319 return new TraceValidationStatus(MIN_CONFIDENCE
, IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.CtfTmfTrace_MajorNotSet
, null);
321 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.CtfTmfTrace_MajorNotSet
);
324 // Validate using reader initialization
325 try (CTFTraceReader ctfTraceReader
= new CTFTraceReader(trace
)) {
329 // Trace is validated, return with confidence
330 return new CtfTraceValidationStatus(CONFIDENCE
, Activator
.PLUGIN_ID
, trace
.getEnvironment());
332 } catch (final CTFException
| BufferOverflowException e
) {
333 // return warning since it's a CTF trace but with errors in it
334 return new TraceValidationStatus(MIN_CONFIDENCE
, IStatus
.WARNING
, Activator
.PLUGIN_ID
, Messages
.CtfTmfTrace_ReadingError
+ ": " + e
.toString(), e
); //$NON-NLS-1$
337 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.CtfTmfTrace_ReadingError
);
341 public Iterable
<ITmfEventAspect
<?
>> getEventAspects() {
346 * Method getCurrentLocation. This is not applicable in CTF
348 * @return null, since the trace has no knowledge of the current location
349 * @see org.eclipse.tracecompass.tmf.core.trace.ITmfTrace#getCurrentLocation()
352 public ITmfLocation
getCurrentLocation() {
357 public double getLocationRatio(ITmfLocation location
) {
358 final CtfLocation curLocation
= (CtfLocation
) location
;
359 final long startTime
= getStartTime().getValue();
360 final double diff
= curLocation
.getLocationInfo().getTimestamp() - startTime
;
361 final double total
= getEndTime().getValue() - startTime
;
362 return Math
.max(0.0, Math
.min(1.0, diff
/ total
));
370 * @return ITmfContext
373 public synchronized ITmfContext
seekEvent(final ITmfLocation location
) {
374 CtfLocation currentLocation
= (CtfLocation
) location
;
375 CtfTmfContext context
= new CtfTmfContext(this);
376 if (fTrace
== null) {
377 context
.setLocation(null);
378 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
382 * The rank is set to 0 if the iterator seeks the beginning. If not, it
383 * will be set to UNKNOWN_RANK, since CTF traces don't support seeking
386 if (currentLocation
== null) {
387 currentLocation
= new CtfLocation(new CtfLocationInfo(0L, 0L));
390 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
392 /* This will seek and update the location after the seek */
393 context
.setLocation(currentLocation
);
398 public synchronized ITmfContext
seekEvent(double ratio
) {
399 CtfTmfContext context
= new CtfTmfContext(this);
400 if (fTrace
== null) {
401 context
.setLocation(null);
402 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
405 final long end
= getEndTime().getValue();
406 final long start
= getStartTime().getValue();
407 final long diff
= end
- start
;
408 final long ratioTs
= Math
.round(diff
* ratio
) + start
;
409 context
.seek(ratioTs
);
410 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
415 * Method readNextEvent.
419 * @return CtfTmfEvent
420 * @see org.eclipse.tracecompass.tmf.core.trace.ITmfTrace#getNext(ITmfContext)
423 public synchronized CtfTmfEvent
getNext(final ITmfContext context
) {
424 if (fTrace
== null) {
427 CtfTmfEvent event
= null;
428 if (context
instanceof CtfTmfContext
) {
429 if (context
.getLocation() == null || CtfLocation
.INVALID_LOCATION
.equals(context
.getLocation().getLocationInfo())) {
432 CtfTmfContext ctfContext
= (CtfTmfContext
) context
;
433 event
= ctfContext
.getCurrentEvent();
436 updateAttributes(context
, event
);
437 ctfContext
.advance();
438 ctfContext
.increaseRank();
446 * Ctf traces have a clock with a unique uuid that will be used to identify
447 * the host. Traces with the same clock uuid will be known to have been made
448 * on the same machine.
450 * Note: uuid is an optional field, it may not be there for a clock.
453 public String
getHostId() {
454 CTFClock clock
= fTrace
.getClock();
456 String clockHost
= (String
) clock
.getProperty(CLOCK_HOST_PROPERTY
);
457 if (clockHost
!= null) {
461 return super.getHostId();
465 * Get the first callsite that matches the event name
468 * The event name to look for
469 * @return The best callsite candidate
472 public @Nullable CtfTmfCallsite
getCallsite(String eventName
) {
473 for (ICTFStream stream
: fTrace
.getStreams()) {
474 for (IEventDeclaration eventDeclaration
: stream
.getEventDeclarations()) {
475 if (eventDeclaration
!= null && Objects
.equals(eventDeclaration
.getName(), eventName
) &&
476 !eventDeclaration
.getCallsites().isEmpty()) {
477 return new CtfTmfCallsite(eventDeclaration
.getCallsites().get(0));
485 * Get the closest matching callsite for given event name and instruction
491 * The instruction pointer
492 * @return The closest matching callsite
495 public @Nullable CtfTmfCallsite
getCallsite(String eventName
, long ip
) {
496 CtfTmfCallsite callsite
= null;
497 for (ICTFStream stream
: fTrace
.getStreams()) {
498 for (IEventDeclaration eventDeclaration
: stream
.getEventDeclarations()) {
499 if (eventDeclaration
!= null && Objects
.equals(eventDeclaration
.getName(), eventName
)) {
500 for (CTFCallsite cs
: eventDeclaration
.getCallsites()) {
501 if (cs
.getIp() >= ip
&& (callsite
== null || cs
.getIp() < callsite
.getIntructionPointer())) {
502 callsite
= new CtfTmfCallsite(cs
);
512 * Get the CTF environment variables defined in this CTF trace, in <name,
513 * value> form. This comes from the trace's CTF metadata.
515 * @return The CTF environment
517 public Map
<String
, String
> getEnvironment() {
518 return fTrace
.getEnvironment();
521 // -------------------------------------------
522 // ITmfPropertiesProvider
523 // -------------------------------------------
529 public Map
<String
, String
> getProperties() {
530 Map
<String
, String
> properties
= new HashMap
<>();
531 properties
.putAll(fTrace
.getEnvironment());
532 properties
.put(CLOCK_OFFSET
, Long
.toUnsignedString(fTrace
.getOffset()));
533 properties
.put(Messages
.CtfTmfTrace_HostID
, getHostId());
537 // -------------------------------------------
539 // -------------------------------------------
542 * Gets the clock offset with respect to POSIX.1 Epoch in cycles
544 * @return the clock offset with respect to POSIX.1 Epoch in cycles
546 public long getOffset() {
547 if (fTrace
!= null) {
548 return fTrace
.getOffset();
554 * Convert a CTF timestamp in CPU cycles to its equivalent in nanoseconds
558 * The timestamp in cycles, relative to the clock offset
559 * @return The timestamp in nanoseconds, relative to POSIX.1 Epoch
561 public long timestampCyclesToNanos(long cycles
) {
562 return fTrace
.timestampCyclesToNanos(cycles
);
566 * Convert a CTF timestamp in nanoseconds to its equivalent in CPU cycles
570 * The timestamp in nanoseconds, relative to POSIX.1 Epoch
571 * @return The timestamp in cycles, relative to the clock offset
573 public long timestampNanoToCycles(long nanos
) {
574 return fTrace
.timestampNanoToCycles(nanos
);
578 * Gets the list of declared events
581 public Set
<@NonNull CtfTmfEventType
> getContainedEventTypes() {
582 return ImmutableSet
.copyOf(fContainedEventTypes
.values());
586 * Register an event type to this trace.
588 * Public visibility so that {@link CtfTmfEvent#getType} can call it.
590 * FIXME This could probably be made cleaner?
593 * The event type to register
595 public void registerEventType(CtfTmfEventType eventType
) {
596 fContainedEventTypes
.put(eventType
.getName(), eventType
);
599 // -------------------------------------------
601 // -------------------------------------------
604 public CtfTmfEvent
parseEvent(ITmfContext context
) {
605 CtfTmfEvent event
= null;
606 if (context
instanceof CtfTmfContext
) {
607 final ITmfContext tmpContext
= seekEvent(context
.getLocation());
608 event
= getNext(tmpContext
);
614 * Sets the cache size for a CtfTmfTrace.
616 protected void setCacheSize() {
617 setCacheSize(DEFAULT_CACHE_SIZE
);
620 // -------------------------------------------
621 // CtfIterator factory methods
622 // -------------------------------------------
625 * Get the event factory for this trace to generate new events for it.
627 * @return The event factory
630 public @NonNull CtfTmfEventFactory
getEventFactory() {
631 return fEventFactory
;
635 * Get an iterator to the trace
637 * @return an iterator to the trace
639 public ITmfContext
createIterator() {
641 return new CtfIterator(fTrace
, this);
642 } catch (CTFException e
) {
643 Activator
.getDefault().logError(e
.getMessage(), e
);
649 * Get an iterator to the trace, , which will initially point to the given
652 * @param ctfLocationData
653 * The initial timestamp the iterator will be pointing to
656 * @return The new iterator
658 public ITmfContext
createIterator(CtfLocationInfo ctfLocationData
, long rank
) {
660 return new CtfIterator(fTrace
, this, ctfLocationData
, rank
);
661 } catch (CTFException e
) {
662 Activator
.getDefault().logError(e
.getMessage(), e
);
668 * Create the 'CtfIterator' object from a CtfTmfContext.
671 * The iterator will initially be pointing to this context
672 * @return A new CtfIterator object
675 public ITmfContext
createIteratorFromContext(CtfTmfContext context
) {
676 return fIteratorManager
.getIterator(context
);
680 * Dispose an iterator that was create with
681 * {@link #createIteratorFromContext}
684 * The last context that was pointed to by the iterator (this is
685 * the 'key' to find the correct iterator to dispose).
688 public void disposeContext(CtfTmfContext context
) {
689 fIteratorManager
.removeIterator(context
);
692 // ------------------------------------------------------------------------
693 // Timestamp transformation functions
694 // ------------------------------------------------------------------------
700 public @NonNull ITmfTimestamp
createTimestamp(long ts
) {
701 return TmfTimestamp
.fromNanos(getTimestampTransform().transform(ts
));
704 private static int fCheckpointSize
= -1;
707 public synchronized int getCheckpointSize() {
708 if (fCheckpointSize
== -1) {
709 TmfCheckpoint c
= new TmfCheckpoint(TmfTimestamp
.fromNanos(0), new CtfLocation(0, 0), 0);
710 ByteBuffer b
= ByteBuffer
.allocate(ITmfCheckpoint
.MAX_SERIALIZE_SIZE
);
713 fCheckpointSize
= b
.position();
716 return fCheckpointSize
;
720 protected ITmfTraceIndexer
createIndexer(int interval
) {
721 return new TmfBTreeTraceIndexer(this, interval
);
725 public ITmfLocation
restoreLocation(ByteBuffer bufferIn
) {
726 return new CtfLocation(bufferIn
);
730 public boolean isComplete() {
731 if (getResource() == null) {
737 String sessionName
= null;
739 host
= getResource().getPersistentProperty(CtfConstants
.LIVE_HOST
);
740 port
= getResource().getPersistentProperty(CtfConstants
.LIVE_PORT
);
741 sessionName
= getResource().getPersistentProperty(CtfConstants
.LIVE_SESSION_NAME
);
742 } catch (CoreException e
) {
743 Activator
.getDefault().logError(e
.getMessage(), e
);
744 // Something happened to the resource, assume we won't get any more
748 return host
== null || port
== null || sessionName
== null;
752 public void setComplete(final boolean isComplete
) {
753 super.setComplete(isComplete
);
756 getResource().setPersistentProperty(CtfConstants
.LIVE_HOST
, null);
757 getResource().setPersistentProperty(CtfConstants
.LIVE_PORT
, null);
758 getResource().setPersistentProperty(CtfConstants
.LIVE_SESSION_NAME
, null);
760 } catch (CoreException e
) {
761 Activator
.getDefault().logError(e
.getMessage(), e
);
766 * @return the number of estimated chunks of events read. This reads the
767 * file size of the trace and divides it by a factor and the average
768 * event size, this is not accurate but can give a ball park figure
769 * of how much is done.
775 CTFTrace trace
= fTrace
;
777 Iterable
<ICTFStream
> streams
= trace
.getStreams();
778 for (ICTFStream stream
: streams
) {
779 for (CTFStreamInput si
: stream
.getStreamInputs()) {
780 size
+= si
.getFile().length();
784 return (int) (size
/ REDUCTION_FACTOR
/ CTF_AVG_EVENT_SIZE
);
788 * @return the number of events divided a reduction factor. Is monotonic.
792 public int progress() {
793 return (int) (getNbEvents() / REDUCTION_FACTOR
);
800 public long cyclesToNanos(long cycles
) {
801 // CTFTrace adds the clock offset in cycles to the input
802 return fTrace
.timestampCyclesToNanos(cycles
- fTrace
.getOffset());
809 public long nanosToCycles(long nanos
) {
810 // CTFTrace subtracts the clock offset in cycles from the output
811 return fTrace
.timestampNanoToCycles(nanos
) + fTrace
.getOffset();
818 public ITmfTimestamp
readStart() {
819 return getStartTime();
826 public ITmfTimestamp
readEnd() {
827 try (CTFTraceReader reader
= new CTFTraceReader(fTrace
)) {
828 reader
.goToLastEvent();
829 long end
= reader
.getEndTime();
830 return createTimestamp(end
);
831 } catch (CTFException e
) {