示例#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 ReadEvents(DateTime startTime, DateTime endTime)
        {
            if (startTime > endTime)
            {
                throw new ArgumentException(StringResources.ETLReaderError_StartTimeGreaterThanEndTime, "startTime");
            }

            if (this.EventRead == null)
            {
                throw new InvalidOperationException(StringResources.ETLReaderError_NoSubscribersForEventRead);
            }

            // initialize trace handle
            InitializeTraceHandle();

            ulong eventReadFailureCount;

            LttngReaderStatusCode res = ProcessTrace(startTime, endTime, ref this.traceHandle, out eventReadFailureCount);

            if (res != LttngReaderStatusCode.SUCCESS && res != LttngReaderStatusCode.END_OF_TRACE)
            {
                string errorMessage = LttngReaderStatusMessage.GetMessage(res);
                throw new InvalidDataException(
                          $"{errorMessage}. When processing traces at folder: {this.path}.\n" +
                          $"Last event successfully read has timestamp: {LttngTraceFolderEventReader.ConvertFromUnixEpoch(this.lastEventReadTimestamp).ToString("o")}\n" +
                          $"Total events events skipped due to failure before exception : {eventReadFailureCount}");
            }

            if (eventReadFailureCount != 0)
            {
                throw new InvalidDataException(
                          $"Failed to read {eventReadFailureCount} events from trace at {this.path}" +
                          $"StartTime: {startTime}, EndTime: {endTime}");
            }
        }