Skip to content

Commit

Permalink
Add dotnet-trace as profiler for Net (#5572)
Browse files Browse the repository at this point in the history
* Add dotnet-trace as profiler for Net

* Install dotnet-trace

* Specify Working Directory

* Update tests.yml

* Use PowerShell@2

* Add arguments to profile output file

---------

Co-authored-by: Mike Harder <[email protected]>
  • Loading branch information
AlexanderSher and mikeharder authored Mar 13, 2023
1 parent 1b1812d commit 4a95b74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tools/perf-automation/Azure.Sdk.Tools.PerfAutomation/Net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public override async Task<IterationResult> RunAsync(
var dllName = Path.GetFileNameWithoutExtension(project) + ".dll";
var dllPath = Path.Combine(PublishDirectory, dllName);

var processArguments = $"{dllPath} {testName} {arguments}";

var result = await Util.RunAsync("dotnet", processArguments, WorkingDirectory, throwOnError: false);
var result = profile
? await Util.RunAsync("dotnet-trace", $"collect --format NetTrace --show-child-io --output {GetProfileOutputFile(testName, arguments)} -- dotnet {dllPath} {testName} {arguments}", WorkingDirectory, throwOnError: false)
: await Util.RunAsync("dotnet", $"{dllPath} {testName} {arguments}", WorkingDirectory, throwOnError: false);

// Completed 693,696 operations in a weighted-average of 1.00s (692,328.31 ops/s, 0.000 s/op)
var match = Regex.Match(result.StandardOutput, @"\((.*) ops/s", RegexOptions.IgnoreCase | RegexOptions.RightToLeft);
Expand All @@ -123,6 +123,12 @@ public override async Task<IterationResult> RunAsync(
};
}

private string GetProfileOutputFile(string testName, string arguments)
{
var fileName = $"{testName}_{arguments.Replace(" --", "_").Replace("--", "_").Replace(" ", "-")}_{DateTime.Now.ToString("yyyyMMdd_hhmmss")}.nettrace";
return Path.GetFullPath(Path.Combine(Util.GetProfileDirectory(WorkingDirectory), fileName));
}

// === Versions ===
// Runtime: 3.1.27
// Azure.Core:
Expand Down
7 changes: 7 additions & 0 deletions tools/perf-automation/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ stages:
- template: /eng/pipelines/templates/steps/install-dotnet.yml@azure-sdk-for-net
parameters:
EnableNuGetCache: false
- ${{ if parameters.Profile }}:
- task: PowerShell@2
displayName: 'Install dotnet-trace'
inputs:
targetType: 'inline'
script: 'dotnet tool install -g dotnet-trace'
workingDirectory: '$(Build.SourcesDirectory)/sdk'
ServiceDirectory: ${{ parameters.NetServiceDirectory }}
PackageVersions: ${{ parameters.PackageVersions }}
Tests: ${{ parameters.Tests }}
Expand Down

0 comments on commit 4a95b74

Please sign in to comment.