-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code to support decoding nettrace files
- Loading branch information
Showing
9 changed files
with
238 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright (c) Alexandre Mutel. All rights reserved. | ||
// Licensed under the BSD-Clause 2 license. | ||
// See license.txt file in the project root for full license information. | ||
|
||
namespace Ultra.Core; | ||
|
||
/// <summary> | ||
/// Converts a list of trace files (one ETL file or a list of nettrace files) to a Firefox profile. | ||
/// </summary> | ||
public abstract class UltraConverterToFirefox : IDisposable | ||
{ | ||
private protected readonly List<UltraProfilerTraceFile> TraceFiles; | ||
private protected readonly UltraProfilerOptions Options; | ||
private protected FirefoxProfiler.Profile ProfilerResult; | ||
|
||
/// <summary> | ||
/// A generic other category. | ||
/// </summary> | ||
public const int CategoryOther = 0; | ||
|
||
/// <summary> | ||
/// The kernel category. | ||
/// </summary> | ||
public const int CategoryKernel = 1; | ||
|
||
/// <summary> | ||
/// The native category. | ||
/// </summary> | ||
public const int CategoryNative = 2; | ||
|
||
/// <summary> | ||
/// The managed category. | ||
/// </summary> | ||
public const int CategoryManaged = 3; | ||
|
||
/// <summary> | ||
/// The GC category. | ||
/// </summary> | ||
public const int CategoryGc = 4; | ||
|
||
/// <summary> | ||
/// The JIT category. | ||
/// </summary> | ||
public const int CategoryJit = 5; | ||
|
||
/// <summary> | ||
/// The CLR category. | ||
/// </summary> | ||
public const int CategoryClr = 6; | ||
|
||
private protected UltraConverterToFirefox(List<UltraProfilerTraceFile> traceFiles, UltraProfilerOptions options) | ||
{ | ||
TraceFiles = traceFiles; | ||
this.Options = options; | ||
ProfilerResult = new FirefoxProfiler.Profile(); // Create an empty profile (not used and override by the derived class) | ||
} | ||
|
||
/// <inheritdoc /> | ||
public abstract void Dispose(); | ||
|
||
/// <summary> | ||
/// Converts a list of trace files (one ETL file, or a list of nettrace files) to a Firefox profile. | ||
/// </summary> | ||
/// <param name="traceFiles">The list of trace files to convert.</param> | ||
/// <param name="options">The options used for converting.</param> | ||
/// <param name="processIds">The list of process ids to extract from the trace files.</param> | ||
/// <returns>The converted Firefox profile.</returns> | ||
public static FirefoxProfiler.Profile Convert(List<UltraProfilerTraceFile> traceFiles, UltraProfilerOptions options, List<int> processIds) | ||
{ | ||
var extensions = traceFiles.Select(x => Path.GetExtension(x.FileName)).ToHashSet(StringComparer.OrdinalIgnoreCase); | ||
|
||
if (extensions.Count != 1) | ||
{ | ||
throw new ArgumentException($"All trace files must have the same extension. Instead got [{string.Join(", ", extensions)}]"); | ||
} | ||
|
||
var extension = extensions.First(); | ||
if (extension == ".etl") | ||
{ | ||
if (traceFiles.Count > 1) | ||
{ | ||
throw new ArgumentException("Only one ETL file is supported"); | ||
} | ||
|
||
using var converter = new UltraConverterToFirefoxEtw(traceFiles, options); | ||
return converter.Convert(processIds); | ||
} | ||
else if (extension == ".nettrace") | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
else | ||
{ | ||
throw new ArgumentException($"Unsupported trace file extension [{extension}]"); | ||
} | ||
} | ||
|
||
private FirefoxProfiler.Profile Convert(List<int> processIds) | ||
{ | ||
ConvertImpl(processIds); | ||
return ProfilerResult; | ||
} | ||
|
||
private protected abstract void ConvertImpl(List<int> processIds); | ||
} |
Oops, something went wrong.