Skip to content

Commit

Permalink
[dotnet trace] Add Chromium Trace Event file format to list of s… (#894)
Browse files Browse the repository at this point in the history
* bump trace event version to be able to use new file format

* handle the new file format
  • Loading branch information
John Salem authored Mar 11, 2020
2 parents cd4d228 + 44aa31d commit bf74bba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<!-- Other libs -->
<MicrosoftDiagnosticsRuntimeVersion>1.1.61812</MicrosoftDiagnosticsRuntimeVersion>
<MicrosoftDiaSymReaderNativePackageVersion>1.7.0</MicrosoftDiaSymReaderNativePackageVersion>
<MicrosoftDiagnosticsTracingTraceEventVersion>2.0.44</MicrosoftDiagnosticsTracingTraceEventVersion>
<MicrosoftDiagnosticsTracingTraceEventVersion>2.0.51</MicrosoftDiagnosticsTracingTraceEventVersion>
<MicrosoftExtensionsConfigurationJsonVersion>3.1.2</MicrosoftExtensionsConfigurationJsonVersion>
<MicrosoftExtensionsConfigurationKeyPerFileVersion>3.1.2</MicrosoftExtensionsConfigurationKeyPerFileVersion>
<MicrosoftExtensionsLoggingVersion>3.1.2</MicrosoftExtensionsLoggingVersion>
Expand Down
30 changes: 21 additions & 9 deletions src/Tools/dotnet-trace/TraceFileFormatConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TraceFileFormat, string> TraceFileFormatExtensions = new Dictionary<TraceFileFormat, string>() {
private static IReadOnlyDictionary<TraceFileFormat, string> TraceFileFormatExtensions = new Dictionary<TraceFileFormat, string>() {
{ 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 = "")
Expand All @@ -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.
Expand All @@ -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
{
Expand All @@ -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)
Expand All @@ -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);
}

}
}
}

0 comments on commit bf74bba

Please sign in to comment.