public static string GetMessage(LttngReaderStatusCode error) { switch (error) { case LttngReaderStatusCode.END_OF_TRACE: return("Success - End of trace reached."); case LttngReaderStatusCode.SUCCESS: return("Success - No error found during execution."); case LttngReaderStatusCode.FAILED_TO_READ_EVENT: return("Recoverable Error - Failed to read single event. It may be possible to continue reading traces."); case LttngReaderStatusCode.ERROR: return("Unrecoverable error happened when trying to read event. Unable to proceed processing traces."); case LttngReaderStatusCode.NOT_ENOUGH_MEM: return("Failed allocating memory."); case LttngReaderStatusCode.INVALID_BUFFER_SIZE: return("Not enough space in buffer provided."); case LttngReaderStatusCode.INVALID_ARGUMENT: return("One of the provided arguments is not valid."); case LttngReaderStatusCode.NO_LTTNG_SESSION_FOUND: return("No active LTTng trace session found."); case LttngReaderStatusCode.FAILED_TO_LOAD_TRACES: return("Failed opening trace folder for reading traces."); case LttngReaderStatusCode.FAILED_INITIALIZING_TRACEINFO: return("Failure when initializing trace."); case LttngReaderStatusCode.FAILED_TO_MOVE_ITERATOR: return("Failure occuring when trying to move iterator to next event."); case LttngReaderStatusCode.INVALID_CTF_ITERATOR: return("Invalid (null) CTF iterator provided."); case LttngReaderStatusCode.UNEXPECTED_END_OF_TRACE: return("Unexpectedly reached the end of the trace."); default: return("Invalid error code provided."); } }
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; } }
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}"); } }
private string GetServiceFabricSessionOutputPath() { StringBuilder serviceFabricSessionName = new StringBuilder(LttProducerWorker.ServiceFabricSessionName); StringBuilder serviceFabricSessionOutputPath = new StringBuilder(LttProducerWorker.PathMaxSize); // If processing traces from container LTTng session the session is not accessible from host. // In this case the the active session is the one and only one folder inside the Log/Containers/sf-containerid/lttng-traces folder. string containerTraceFolder; if (this.TryGetContainerTraceFolder(out containerTraceFolder)) { return(containerTraceFolder); } LttngReaderStatusCode res = LttngReaderBindings.get_active_lttng_session_path(serviceFabricSessionName, serviceFabricSessionOutputPath, LttProducerWorker.PathMaxSize); if (res == LttngReaderStatusCode.SUCCESS) { return(serviceFabricSessionOutputPath.ToString().TrimEnd(Path.DirectorySeparatorChar)); } else { string errorMessage = LttngReaderStatusMessage.GetMessage(res); this.traceSource.WriteWarning( this.logSourceId, "Unable to find active Service Fabric Ltt trace session with name starting with: {0}.\nInner error : {1}", LttProducerWorker.ServiceFabricSessionName, errorMessage); } return(null); }
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); }