예제 #1
0
        private void InitializeTraceHandle()
        {
            if (this.traceHandle.id < 0)
            {
                // initializing for reading traces with iterator at oldest trace event so we can query the total number of events lost in the session.
                StringBuilder sbPath = new StringBuilder();
                sbPath.Append(this.path);

                // trace is always initialized with first and last events since
                // the timerange is always reset for each ReadEvents call
                LttngReaderStatusCode res = LttngReaderBindings.initialize_trace_processing(
                    sbPath,
                    (ulong)LTTngTraceTimestampFlag.FIRST_TRACE_TIMESTAMP,
                    (ulong)LTTngTraceTimestampFlag.LAST_TRACE_TIMESTAMP,
                    out this.traceHandle);

                if (res != LttngReaderStatusCode.SUCCESS)
                {
                    string errorMessage = LttngReaderStatusMessage.GetMessage(res);
                    throw new InvalidDataException($"{errorMessage}. Occured while trying to initialize processing of LTTng traces for folder {this.path}");
                }

                this.EventsLost = (uint)this.traceHandle.trace_info.events_lost;
            }
        }
예제 #2
0
        public void Dispose()
        {
            if (this.disposed)
            {
                return;
            }

            this.disposed = true;

            if (this.traceHandle.id >= 0)
            {
                LttngReaderBindings.finalize_trace_processing(ref this.traceHandle);
            }

            GC.SuppressFinalize(this);
        }
예제 #3
0
        private LttngReaderStatusCode ProcessTrace(DateTime startTime, DateTime endTime, ref LTTngTraceHandle traceHandle, out ulong eventReadFailureCount)
        {
            EventRecord eventRecord       = new EventRecord();
            ulong       lastReadTimestamp = 0;

            // needed for processing unstructured events in Linux
            bool          isUnstructured     = false;
            StringBuilder unstructuredRecord = new StringBuilder(LttngReaderBindings.MAX_LTTNG_UNSTRUCTURED_EVENT_LEN + 1);
            StringBuilder taskNameEventName  = new StringBuilder(LttngReaderBindings.MAX_LTTNG_TASK_EVENT_NAME_LEN + 1);

            ulong startTimeEpochNanoS = LttngTraceFolderEventReader.ConvertToUnixEpoch(startTime);
            ulong endTimeEpochNanoS   = LttngTraceFolderEventReader.ConvertToUnixEpoch(endTime);

            // set start and end time for reading traces
            LttngReaderStatusCode res = LttngReaderBindings.set_start_end_time(ref traceHandle, startTimeEpochNanoS, endTimeEpochNanoS);

            eventReadFailureCount = 0;

            if (res != LttngReaderStatusCode.SUCCESS)
            {
                return(res);
            }

            res = LttngReaderBindings.read_next_event(ref traceHandle, ref eventRecord, unstructuredRecord, taskNameEventName, ref lastReadTimestamp, ref isUnstructured);

            while (res == LttngReaderStatusCode.SUCCESS || res == LttngReaderStatusCode.FAILED_TO_READ_EVENT)
            {
                if (res == LttngReaderStatusCode.FAILED_TO_READ_EVENT)
                {
                    eventReadFailureCount++;
                    continue;
                }

                EventRecordEventArgs eventRecordEventArgs;
                this.lastEventReadTimestamp = lastReadTimestamp;

                if (isUnstructured)
                {
                    try
                    {
                        eventRecord.EventHeader.TimeStamp = LttngTraceFolderEventReader.ConvertFromUnixEpoch(lastReadTimestamp).ToFileTimeUtc();
                    }
                    catch (Exception)
                    {
                        // Flagging error with minimum timestamp so we can continue processing other events.
                        eventRecord.EventHeader.TimeStamp = 0;
                    }

                    eventRecordEventArgs = new EventRecordEventArgs(eventRecord);

                    eventRecordEventArgs.IsUnstructured     = isUnstructured;
                    eventRecordEventArgs.TaskNameEventName  = taskNameEventName.ToString();
                    eventRecordEventArgs.UnstructuredRecord = unstructuredRecord.ToString();
                }
                else
                {
                    eventRecordEventArgs = new EventRecordEventArgs(eventRecord);
                }

                this.EventRead(this, eventRecordEventArgs);

                if (eventRecordEventArgs.Cancel)
                {
                    return(LttngReaderStatusCode.SUCCESS);
                }

                res = LttngReaderBindings.read_next_event(ref traceHandle, ref eventRecord, unstructuredRecord, taskNameEventName, ref lastReadTimestamp, ref isUnstructured);
            }

            return(res);
        }