From 38dea469f4f414f4642ffa19e2d9b60187e50e48 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Tue, 10 Mar 2020 15:55:10 +0100 Subject: [PATCH 1/4] bump trace event version to be able to use new file format --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index ef0c8ac9e3..d1bf29335c 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -34,7 +34,7 @@ 1.0.55801 1.1.61812 1.7.0 - 2.0.44 + 2.0.50 0.3.0-alpha.19602.1 0.3.0-alpha.19602.1 4.5.3 From 74d3bbc75fdb95ed4cb017322a89db473b77216c Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Tue, 10 Mar 2020 16:04:40 +0100 Subject: [PATCH 2/4] handle the new file format --- .../dotnet-trace/TraceFileFormatConverter.cs | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Tools/dotnet-trace/TraceFileFormatConverter.cs b/src/Tools/dotnet-trace/TraceFileFormatConverter.cs index 6b4d13451a..58017d5622 100644 --- a/src/Tools/dotnet-trace/TraceFileFormatConverter.cs +++ b/src/Tools/dotnet-trace/TraceFileFormatConverter.cs @@ -13,13 +13,14 @@ namespace Microsoft.Diagnostics.Tools.Trace { - internal enum TraceFileFormat { NetTrace, Speedscope }; + internal enum TraceFileFormat { NetTrace, Speedscope, Chromium }; internal static class TraceFileFormatConverter { - private static Dictionary TraceFileFormatExtensions = new Dictionary() { + private static IReadOnlyDictionary TraceFileFormatExtensions = new Dictionary() { { TraceFileFormat.NetTrace, "nettrace" }, - { TraceFileFormat.Speedscope, "speedscope.json" } + { TraceFileFormat.Speedscope, "speedscope.json" }, + { TraceFileFormat.Chromium, "chromium.json" } }; public static void ConvertToFormat(TraceFileFormat format, string fileToConvert, string outputFilename = "") @@ -35,9 +36,10 @@ public static void ConvertToFormat(TraceFileFormat format, string fileToConvert, case TraceFileFormat.NetTrace: break; case TraceFileFormat.Speedscope: + case TraceFileFormat.Chromium: try { - ConvertToSpeedscope(fileToConvert, outputFilename); + Convert(format, 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. @@ -46,7 +48,7 @@ public static void ConvertToFormat(TraceFileFormat format, string fileToConvert, 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); + Convert(format, fileToConvert, outputFilename, true); } else { @@ -61,10 +63,10 @@ public static void ConvertToFormat(TraceFileFormat format, string fileToConvert, Console.Out.WriteLine("Conversion complete"); } - private static void ConvertToSpeedscope(string fileToConvert, string outputFilename, bool continueOnError=false) + private static void Convert(TraceFileFormat format, string fileToConvert, string outputFilename, bool continueOnError=false) { var etlxFilePath = TraceLog.CreateFromEventPipeDataFile(fileToConvert, null, new TraceLogOptions() { ContinueOnError = continueOnError } ); - using (var symbolReader = new SymbolReader(System.IO.TextWriter.Null) { SymbolPath = SymbolPath.MicrosoftSymbolServerPath }) + using (var symbolReader = new SymbolReader(TextWriter.Null) { SymbolPath = SymbolPath.MicrosoftSymbolServerPath }) using (var eventLog = new TraceLog(etlxFilePath)) { var stackSource = new MutableTraceEventStackSource(eventLog) @@ -78,14 +80,24 @@ private static void ConvertToSpeedscope(string fileToConvert, string outputFilen }; computer.GenerateThreadTimeStacks(stackSource); - SpeedScopeStackSourceWriter.WriteStackViewAsJson(stackSource, outputFilename); + switch (format) + { + case TraceFileFormat.Speedscope: + SpeedScopeStackSourceWriter.WriteStackViewAsJson(stackSource, outputFilename); + break; + case TraceFileFormat.Chromium: + ChromiumStackSourceWriter.WriteStackViewAsJson(stackSource, outputFilename, compress: false); + break; + default: + // we should never get here + throw new ArgumentException($"Invalid TraceFileFormat \"{format}\""); + } } if (File.Exists(etlxFilePath)) { File.Delete(etlxFilePath); } - } } } From 213d6e75c188bac3cdc304edc19298b1bfbb42fc Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Wed, 11 Mar 2020 10:21:21 +0100 Subject: [PATCH 3/4] =?UTF-8?q?install=20latest=20version=20of=20System.Ru?= =?UTF-8?q?ntime.CompilerServices.Unsafe=20to=20avoid=20"Could=20not=20loa?= =?UTF-8?q?d=20file=20or=20assembly=E2=80=9D=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tools/dotnet-trace/dotnet-trace.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Tools/dotnet-trace/dotnet-trace.csproj b/src/Tools/dotnet-trace/dotnet-trace.csproj index 0739bc1ba9..fd7c06ad0c 100644 --- a/src/Tools/dotnet-trace/dotnet-trace.csproj +++ b/src/Tools/dotnet-trace/dotnet-trace.csproj @@ -13,6 +13,7 @@ + From 44aa31d79239c1aa8e58626feb4e9ca5aadcdf37 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Wed, 11 Mar 2020 18:53:47 +0100 Subject: [PATCH 4/4] update TraceEvent and revert the workaround --- eng/Versions.props | 2 +- src/Tools/dotnet-trace/dotnet-trace.csproj | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 2fb361b4a6..285fecbc3c 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -35,7 +35,7 @@ 1.1.61812 1.7.0 - 2.0.50 + 2.0.51 3.1.2 3.1.2 3.1.2 diff --git a/src/Tools/dotnet-trace/dotnet-trace.csproj b/src/Tools/dotnet-trace/dotnet-trace.csproj index fd7c06ad0c..0739bc1ba9 100644 --- a/src/Tools/dotnet-trace/dotnet-trace.csproj +++ b/src/Tools/dotnet-trace/dotnet-trace.csproj @@ -13,7 +13,6 @@ -