internal override async Task InitAsync(YamlMappingNode moduleOptions) { // Check input directory _inputDirectory = new DirectoryInfo(moduleOptions.GetChildNodeWithKey("input-directory").GetNodeString()); if (!_inputDirectory.Exists) { throw new ConfigurationException("Could not find input directory."); } // Try to load prefix file string preprocessedPrefixFilePath = Path.Combine(_inputDirectory.FullName, $"prefix.trace.preprocessed"); if (!File.Exists(preprocessedPrefixFilePath)) { await Logger.LogErrorAsync($"Could not find preprocessed trace prefix file."); throw new FileNotFoundException("Could not find preprocessed trace prefix file.", preprocessedPrefixFilePath); } var bytes = await File.ReadAllBytesAsync(preprocessedPrefixFilePath); _tracePrefix = new TracePrefixFile(bytes); }
public override async Task PreprocessTraceAsync(TraceEntity traceEntity) { // First test case? if (_firstTestcase) { // Paths string rawTraceFileDirectory = Path.GetDirectoryName(traceEntity.RawTraceFilePath); string prefixDataFilePath = Path.Combine(rawTraceFileDirectory !, "prefix_data.txt"); // Suppress "possible null" warning string tracePrefixFilePath = Path.Combine(rawTraceFileDirectory, "prefix.trace"); // Read image data string[] imageDataLines = await File.ReadAllLinesAsync(prefixDataFilePath); int nextImageFileId = 0; List <TracePrefixFile.ImageFileInfo> imageFiles = new List <TracePrefixFile.ImageFileInfo>(); foreach (string line in imageDataLines) { string[] imageData = line.Split('\t'); var imageFile = new TracePrefixFile.ImageFileInfo { Id = nextImageFileId++, Interesting = byte.Parse(imageData[1]) != 0, StartAddress = ulong.Parse(imageData[2], NumberStyles.HexNumber), EndAddress = ulong.Parse(imageData[3], NumberStyles.HexNumber), Name = Path.GetFileName(imageData[4]) }; imageFiles.Add(imageFile); } _imageFiles = imageFiles.OrderBy(img => img.StartAddress).ToArray(); // Prepare writer for serializing trace data Dictionary <int, Allocation> tracePrefixAllocations; using var tracePrefixFileStream = new MemoryStream(); using (var tracePrefixFileWriter = new BinaryWriter(tracePrefixFileStream, Encoding.ASCII, true)) { // Write image files tracePrefixFileWriter.Write(_imageFiles.Length); foreach (var imageFile in _imageFiles) { imageFile.Store(tracePrefixFileWriter); } // Load and parse trace prefix data PreprocessFile(tracePrefixFilePath, true, tracePrefixFileWriter, out tracePrefixAllocations); } // Create trace prefix object var preprocessedTracePrefixData = tracePrefixFileStream.GetBuffer().AsMemory(0, (int)tracePrefixFileStream.Length); _tracePrefix = new TracePrefixFile(preprocessedTracePrefixData, tracePrefixAllocations); _firstTestcase = false; // Keep raw trace data? if (!_keepRawTraces) { File.Delete(prefixDataFilePath); File.Delete(tracePrefixFilePath); } // Store to disk? if (_storeTraces) { string outputPath = Path.Combine(_outputDirectory.FullName, "prefix.trace.preprocessed"); await using var writer = new BinaryWriter(File.Open(outputPath, FileMode.Create, FileAccess.Write, FileShare.None)); writer.Write(preprocessedTracePrefixData.Span); } } // Wait for trace prefix to be fully created (might happen in different thread) while (_tracePrefix == null) { await Task.Delay(10); } // Preprocess trace data string rawTraceFilePath = traceEntity.RawTraceFilePath; Dictionary <int, Allocation> allocations; using var traceFileStream = new MemoryStream(); using (var traceFileWriter = new BinaryWriter(traceFileStream, Encoding.ASCII, true)) PreprocessFile(rawTraceFilePath, false, traceFileWriter, out allocations); // Create trace file object var preprocessedTraceData = traceFileStream.GetBuffer().AsMemory(0, (int)traceFileStream.Length); var preprocessedTraceFile = new TraceFile(_tracePrefix, preprocessedTraceData, allocations); // Keep raw trace? if (!_keepRawTraces) { File.Delete(traceEntity.RawTraceFilePath); traceEntity.RawTraceFilePath = null; } // Store to disk? if (_storeTraces) { traceEntity.PreprocessedTraceFilePath = Path.Combine(_outputDirectory.FullName, Path.GetFileName(rawTraceFilePath) + ".preprocessed"); await using var writer = new BinaryWriter(File.Open(traceEntity.PreprocessedTraceFilePath, FileMode.Create, FileAccess.Write, FileShare.None)); writer.Write(preprocessedTraceData.Span); } // Keep trace data in memory for the analysis stages traceEntity.PreprocessedTraceFile = preprocessedTraceFile; }
public override async Task PreprocessTraceAsync(TraceEntity traceEntity) { // First test case? if (_firstTestcase) { // Read image data string prefixDataFilePath = Path.Combine(Path.GetDirectoryName(traceEntity.RawTraceFilePath), "prefix_data.txt"); string[] imageDataLines = await File.ReadAllLinesAsync(prefixDataFilePath); int nextImageFileId = 0; foreach (string line in imageDataLines) { string[] imageData = line.Split('\t'); var imageFile = new TracePrefixFile.ImageFileInfo { Id = nextImageFileId++, Interesting = byte.Parse(imageData[1]) != 0, StartAddress = ulong.Parse(imageData[2], NumberStyles.HexNumber), EndAddress = ulong.Parse(imageData[3], NumberStyles.HexNumber), Name = Path.GetFileName(imageData[4]) }; _imageFiles.Add(imageFile.StartAddress, imageFile); } // Handle trace prefix file string tracePrefixFilePath = Path.Combine(Path.GetDirectoryName(traceEntity.RawTraceFilePath), "prefix.trace"); _tracePrefix = (TracePrefixFile)PreprocessFile(tracePrefixFilePath, true); _firstTestcase = false; // Keep raw trace data? if (!_keepRawTraces) { File.Delete(prefixDataFilePath); File.Delete(tracePrefixFilePath); } // Store to disk? if (_storeTraces) { string outputPath = Path.Combine(_outputDirectory.FullName, "prefix.trace.preprocessed"); using (var writer = new BinaryWriter(File.Open(outputPath, FileMode.Create, FileAccess.Write, FileShare.None))) _tracePrefix.Save(writer); } } // Wait for trace prefix to be fully created (might happen in different thread) while (_tracePrefix == null) { await Task.Delay(10); } // Preprocess trace string rawTraceFilePath = traceEntity.RawTraceFilePath; var preprocessedTraceFile = PreprocessFile(rawTraceFilePath, false); // Keep raw trace? if (!_keepRawTraces) { File.Delete(traceEntity.RawTraceFilePath); traceEntity.RawTraceFilePath = null; } // Store to disk? if (_storeTraces) { traceEntity.PreprocessedTraceFilePath = Path.Combine(_outputDirectory.FullName, Path.GetFileName(rawTraceFilePath) + ".preprocessed"); using (var writer = new BinaryWriter(File.Open(traceEntity.PreprocessedTraceFilePath, FileMode.Create, FileAccess.Write, FileShare.None))) preprocessedTraceFile.Save(writer); } // Keep trace data in memory for the analysis stages traceEntity.PreprocessedTraceFile = preprocessedTraceFile; }