From: Sung Yoon Whang Date: Sat, 5 Oct 2019 22:59:36 +0000 (-0700) Subject: Add /ContinueOnError option to speedscope converter (#526) X-Git-Tag: submit/tizen/20200402.013218~14^2^2~36 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2c23d3265dd8f642a8d6cf4bb8a135a5ff8b00c2;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Add /ContinueOnError option to speedscope converter (#526) * Add /ContinueOnError option to speedscope converter * Display a warning message when we have to continue on error * Only retry if the exception thrown is from a broken trace --- diff --git a/src/Tools/dotnet-trace/TraceFileFormatConverter.cs b/src/Tools/dotnet-trace/TraceFileFormatConverter.cs index 7e7896e1e..056d56bc8 100644 --- a/src/Tools/dotnet-trace/TraceFileFormatConverter.cs +++ b/src/Tools/dotnet-trace/TraceFileFormatConverter.cs @@ -35,7 +35,24 @@ namespace Microsoft.Diagnostics.Tools.Trace case TraceFileFormat.NetTrace: break; case TraceFileFormat.Speedscope: - ConvertToSpeedscope(fileToConvert, outputFilename); + try + { + ConvertToSpeedscope(fileToConvert, outputFilename); + } + // TODO: On a broken/truncated trace, the exception we get from TraceEvent is a plain System.Exception type because it gets caught and rethrown inside TraceEvent. + // We should probably modify TraceEvent to throw a better exception. + catch (Exception ex) + { + if (ex.ToString().Contains("Read past end of stream.")) + { + Console.WriteLine("Detected a potentially broken trace. Continuing with best-efforts to convert the trace, but resulting speedscope file may contain broken stacks as a result."); + ConvertToSpeedscope(fileToConvert, outputFilename, true); + } + else + { + Console.WriteLine(ex); + } + } break; default: // Validation happened way before this, so we shoud never reach this... @@ -44,9 +61,9 @@ namespace Microsoft.Diagnostics.Tools.Trace Console.Out.WriteLine("Conversion complete"); } - private static void ConvertToSpeedscope(string fileToConvert, string outputFilename) + private static void ConvertToSpeedscope(string fileToConvert, string outputFilename, bool continueOnError=false) { - var etlxFilePath = TraceLog.CreateFromEventPipeDataFile(fileToConvert); + var etlxFilePath = TraceLog.CreateFromEventPipeDataFile(fileToConvert, null, new TraceLogOptions() { ContinueOnError = continueOnError } ); using (var symbolReader = new SymbolReader(System.IO.TextWriter.Null) { SymbolPath = SymbolPath.MicrosoftSymbolServerPath }) using (var eventLog = new TraceLog(etlxFilePath)) {