Exemple #1
0
        public bool PopEvent(out ICtfEvent ctfEvent, out ICtfPacket ctfPacket, out ulong bytesConsumed)
        {
            this.dataReadyForConsumption.Wait(this.cancellationToken);
            this.cancellationToken.ThrowIfCancellationRequested();

            lock (this.Events)
            {
                if (this.Events.Count == 0)
                {
                    // we've reached the end of the stream
                    ctfEvent      = null;
                    ctfPacket     = null;
                    bytesConsumed = 0;
                    return(false);
                }

                ctfEvent      = this.Events.Dequeue();
                ctfPacket     = this.Packets.Dequeue();
                bytesConsumed = this.BytesProcessed.Dequeue();

                if (this.Events.Count == 0 && !this.endOfStream)
                {
                    this.dataReadyForConsumption.Reset();
                }

                this.readyForNewData.Set();
            }

            return(true);
        }
        public void ProcessEvent(ICtfEvent ctfEvent, ICtfPacket eventPacket, ICtfTraceInput traceInput, ICtfInputStream ctfEventStream)
        {
            var eventDescriptor = ctfEvent.EventDescriptor as EventDescriptor;

            Debug.Assert(eventDescriptor != null);
            if (eventDescriptor == null)
            {
                throw new LTTngPlaybackException("EventDescriptor is not an LTTng descriptor.");
            }

            if (!this.streamToCpu.TryGetValue(ctfEventStream, out var cpuId))
            {
                var    cpuIndex = ctfEventStream.StreamSource.LastIndexOf('_');
                string cpu      = ctfEventStream.StreamSource.Substring(cpuIndex + 1);
                if (!uint.TryParse(cpu, out cpuId))
                {
                    Debug.Assert(false, "Unable to parse cpu from LTTng stream channel");
                    cpuId = uint.MaxValue;
                }

                this.streamToCpu.Add(ctfEventStream, cpuId);
            }

            if (!this.traceContexts.TryGetValue(traceInput, out var traceContext))
            {
                traceContext = new TraceContext(this.metadataCustomization.LTTngMetadata);
                this.traceContexts.Add(traceInput, traceContext);
            }

            var callbackEvent = new LTTngEvent(ctfEvent);

            var callbackContext = new LTTngContext(this.metadataCustomization, ctfEventStream, traceContext)
            {
                // todo: when supporting multiple traces, this timestamp needs to become relative to the earliest timestamp all traces
                // todo: when supporting multiple traces, this one event number needs to become cumulative across traces, and one specific to the current trace
                CurrentCpu                    = cpuId,
                Timestamp                     = (long)ctfEvent.Timestamp.NanosecondsFromClockBase,/// - this.baseTimestamp,
                CurrentEventNumber            = this.eventNumber,
                CurrentEventNumberWithinTrace = this.eventNumber,
            };

            foreach (var callback in this.eventCallbacks)
            {
                callback(callbackEvent, callbackContext);
            }

            ++this.eventNumber;
        }
        public bool GetTimestampsFromPacketContext(
            ICtfPacket ctfPacket,
            ICtfMetadata metadata,
            out CtfTimestamp start,
            out CtfTimestamp end)
        {
            start = null;
            end   = null;

            if (!(ctfPacket.StreamPacketContext is CtfStructValue packetContextStruct))
            {
                throw new PerfPlaybackException("The stream.packet.context is not a structure.");
            }

            if (!packetContextStruct.FieldsByName.TryGetValue("timestamp_begin", out var startFieldValue))
            {
                return(false);
            }

            if (!packetContextStruct.FieldsByName.TryGetValue("timestamp_end", out var endFieldValue))
            {
                return(false);
            }

            if (!(startFieldValue is CtfIntegerValue startFieldInteger))
            {
                return(false);
            }

            if (!(endFieldValue is CtfIntegerValue endFieldInteger))
            {
                return(false);
            }

            start = new CtfTimestamp(this.MetadataCustomization, metadata, startFieldInteger);
            end   = new CtfTimestamp(this.MetadataCustomization, metadata, endFieldInteger);
            return(true);
        }
Exemple #4
0
        private void PushEvent(ICtfEvent ctfEvent, ICtfPacket ctfPacket, ulong bytesConsumed)
        {
            Debug.Assert(ctfEvent != null);
            Debug.Assert(ctfPacket != null);
            Debug.Assert(bytesConsumed != 0);

            this.readyForNewData.Wait(this.cancellationToken);
            this.cancellationToken.ThrowIfCancellationRequested();

            lock (this.Events)
            {
                this.Events.Enqueue(ctfEvent);
                this.Packets.Enqueue(ctfPacket);
                this.BytesProcessed.Enqueue(bytesConsumed);

                if (this.Events.Count >= QueueSizeLimit)
                {
                    this.readyForNewData.Reset();
                }

                this.dataReadyForConsumption.Set();
            }
        }
        /// <inheritdoc />
        public ulong GetPacketContentBitCount(ICtfPacket ctfPacket)
        {
            CtfFieldValue streamPacketContext = ctfPacket.StreamPacketContext;

            if (streamPacketContext == null)
            {
                throw new LTTngPlaybackException("The stream.packet.context field is not set.");
            }

            if (!(streamPacketContext is CtfStructValue packetContext))
            {
                throw new LTTngPlaybackException("The stream.packet.context is not a structure.");
            }

            if (!packetContext.FieldsByName.ContainsKey("content_size"))
            {
                throw new LTTngPlaybackException(
                          "Field packet_size was not found in the stream.packet.context structure.");
            }

            var fieldValue = packetContext.FieldsByName["content_size"];

            if (!(fieldValue is CtfIntegerValue contentSize))
            {
                throw new LTTngPlaybackException(
                          "Field content_size was is not an integer value.");
            }

            if (!contentSize.Value.TryGetUInt64(out var bitCount))
            {
                throw new LTTngPlaybackException(
                          "Field content_size is not a valid ulong value.");
            }

            return(bitCount);
        }
 public CtfEvent(PacketReader packetReader, ICtfPacket owningPacket)
 {
     this.packetReader = packetReader;
     this.owningPacket = owningPacket;
 }
Exemple #7
0
 public CtfEvent(PacketReader packetReader, ICtfMetadata metadata, ICtfPacket owningPacket)
 {
     this.packetReader = packetReader;
     this.owningPacket = owningPacket;
     this.metadata     = metadata;
 }