internal void OnEtlFileReadStart(string fileName, bool isActiveEtl, string currentBookmark) { // Trace file subfolder to write bookmarks to this.traceFileSubFolder = this.GetTraceFileSubFolder(fileName); // Reset the last event index this.lastEventIndex.Set(DateTime.MinValue, -1); // Get the index up to which we have already processed. this.maxIndexAlreadyProcessed = this.GetMaxIndexAlreadyProcessed(this.traceFileSubFolder); // Create a new in-memory sink. this.inMemorySink = new InMemorySink( this.TraceSource, this.LogSourceId, this.traceFileSubFolder, this.inMemoryConsumer.ConsumerProcessTraceEventAction); // Signal start of processing to consumer this.inMemoryConsumer.OnProcessingPeriodStart(fileName, isActiveEtl, this.traceFileSubFolder); this.TraceSource.WriteInfo( this.LogSourceId, "Filtered traces from {0} will be written to an in-memory buffer.", fileName); }
internal void OnEtlFileReadStart(string fileName, bool isActiveEtl, string currentBookmark) { // Reset the last event index this.lastEventIndex.Set(DateTime.MinValue, -1); // Get the index up to which we have already processed events from // this file. this.maxIndexAlreadyProcessed = this.GetMaxIndexAlreadyProcessed( fileName); // Create a new file sink. this.fileSink = new InternalFileSink( this.TraceSource, this.LogSourceId); this.fileSink.Initialize(); this.TraceSource.WriteInfo( this.LogSourceId, "Filtered traces from {0} will be written to {1}.", fileName, this.fileSink.TempFileName); }
internal int CompareTo(EventIndex index) { int dateTimeCompareResult = this.Timestamp.CompareTo(index.Timestamp); if (dateTimeCompareResult != 0) { return(dateTimeCompareResult); } if (this.TimestampDifferentiator < index.TimestampDifferentiator) { return(-1); } else if (this.TimestampDifferentiator == index.TimestampDifferentiator) { return(0); } else { return(1); } }
private EventIndex GetMaxIndexAlreadyProcessed(string etlFileName) { // From the ETW CSV directory, retrieve the names of all CSV files // that we generated from this ETL file string traceFilePattern = string.Format( CultureInfo.InvariantCulture, "{0}_{1}_*.{2}*", this.fabricNodeId, Path.GetFileNameWithoutExtension(etlFileName), EtlConsumerConstants.FilteredEtwTraceFileExtension); string subFolder = this.GetTraceFileSubFolder(etlFileName); string folderToSearch = Path.Combine(this.filteredTraceDirName, subFolder); EventIndex index = new EventIndex(); string[] traceFiles; try { InternalFileSink.GetFilesMatchingPattern( folderToSearch, traceFilePattern, out traceFiles); } catch (Exception e) { this.TraceSource.WriteError( this.LogSourceId, "Failed to retrieve files matching pattern {0} in directory {1}. This may cause events to be duplicated in multiple files. {2}", traceFilePattern, this.filteredTraceDirName, e); // We'll assume that no events from this file have been processed yet. // This may end up being an incorrect assumption, in which case some // events can end up duplicated in multiple files. index.Set(DateTime.MinValue, -1); return(index); } if (traceFiles.Length == 0) { // No events from this file have been processed yet index.Set(DateTime.MinValue, -1); return(index); } // Sort the files based on file name and get the name of the newest // file Array.Sort(traceFiles); string newestFile = traceFiles[traceFiles.Length - 1]; // From the name of the newest file, extract the maximum index already // processed string newestFileWithoutExtension = Path.GetFileNameWithoutExtension(newestFile); if (DtrRegEx.IsMatch(newestFileWithoutExtension)) { newestFileWithoutExtension = Path.GetFileNameWithoutExtension(newestFileWithoutExtension); } string[] fileNameParts = newestFileWithoutExtension.Split('_'); Debug.Assert(fileNameParts.Length >= 4, "All file name schemas have at least 4 '_' seperated parts."); long timestampTicks = long.Parse( fileNameParts[fileNameParts.Length - 2], CultureInfo.InvariantCulture); DateTime timestamp = new DateTime(timestampTicks); int timestampDifferentiator = int.Parse( fileNameParts[fileNameParts.Length - 1], CultureInfo.InvariantCulture); index.Set(timestamp, timestampDifferentiator); return(index); }