Skip to content

Commit

Permalink
adding scripts to easily run and compare results
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarolf committed Jun 22, 2021
1 parent f986c7b commit b8b68fa
Show file tree
Hide file tree
Showing 23 changed files with 1,182 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ obj/
.dotnet/
.tools/
.packages/
temp/

# Per-user project properties
launchSettings.json
Expand Down
3 changes: 3 additions & 0 deletions Perf.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0eng\perf\PerfCore.ps1""" %*"
exit /b %ErrorLevel%
18 changes: 12 additions & 6 deletions RoslynAnalyzers.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28531.58
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down Expand Up @@ -188,11 +189,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonPerfUtilities", "src\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualBasicPerfUtilities", "src\PerformanceTests\Utilities\VisualBasic\VisualBasicPerfUtilities.csproj", "{8D764DDE-3762-4218-8BC4-CC1048095D5F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E1A6F359-DF41-4E51-9D4F-2E6DDF135BA7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PerformanceTests", "src\PerformanceTests\Tests\PerformanceTests.csproj", "{4FE82B4D-4AF1-4076-9E85-529205866A80}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PerformanceTests", "PerformanceTests", "{9CD62A3C-A138-4607-9231-5E2266AB59BC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PerfDiff", "src\Tools\PerfDiff\PerfDiff.csproj", "{AE549290-1702-4ECE-AE57-5FF4E85492C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerformanceTests", "src\PerformanceTests\Tests\PerformanceTests.csproj", "{4FE82B4D-4AF1-4076-9E85-529205866A80}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PerfDiff", "PerfDiff", "{BEE4B62A-86BD-4613-8F94-F40364350643}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Expand Down Expand Up @@ -498,6 +499,10 @@ Global
{4FE82B4D-4AF1-4076-9E85-529205866A80}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FE82B4D-4AF1-4076-9E85-529205866A80}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FE82B4D-4AF1-4076-9E85-529205866A80}.Release|Any CPU.Build.0 = Release|Any CPU
{AE549290-1702-4ECE-AE57-5FF4E85492C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE549290-1702-4ECE-AE57-5FF4E85492C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE549290-1702-4ECE-AE57-5FF4E85492C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE549290-1702-4ECE-AE57-5FF4E85492C6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -579,8 +584,9 @@ Global
{6A3B1816-97D3-4D30-8C6F-2F2DC288410B} = {43852421-59D7-4D63-977E-F862E1CF467D}
{8EC7A06A-01F2-49CF-9C45-4357AAD82546} = {43852421-59D7-4D63-977E-F862E1CF467D}
{8D764DDE-3762-4218-8BC4-CC1048095D5F} = {43852421-59D7-4D63-977E-F862E1CF467D}
{9CD62A3C-A138-4607-9231-5E2266AB59BC} = {E1A6F359-DF41-4E51-9D4F-2E6DDF135BA7}
{4FE82B4D-4AF1-4076-9E85-529205866A80} = {9CD62A3C-A138-4607-9231-5E2266AB59BC}
{4FE82B4D-4AF1-4076-9E85-529205866A80} = {CE87A0B7-E19B-4230-A73C-60F6D65EB7DC}
{AE549290-1702-4ECE-AE57-5FF4E85492C6} = {BEE4B62A-86BD-4613-8F94-F40364350643}
{BEE4B62A-86BD-4613-8F94-F40364350643} = {C0B86774-8307-444F-9EE4-98D62C3424F9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FC44ACA9-AEA3-4EE6-881C-2E08ED281B5F}
Expand Down
8 changes: 7 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@
<!-- Roslyn Testing -->
<MicrosoftCodeAnalysisTestingVersion>1.0.1-beta1.21202.2</MicrosoftCodeAnalysisTestingVersion>
<!-- Libs -->
<BenchmarkDotNetVersion>0.12.1</BenchmarkDotNetVersion>
<BenchmarkDotNetVersion>0.13.0</BenchmarkDotNetVersion>
<HumanizerVersion>2.2.0</HumanizerVersion>
<MicrosoftBuildLocatorVersion>1.1.2</MicrosoftBuildLocatorVersion>
<MicrosoftDiagnosticsTracingTraceEventVersion>2.0.69</MicrosoftDiagnosticsTracingTraceEventVersion>
<MicrosoftExtensionsLoggingVersion>6.0.0-preview.5.21301.5</MicrosoftExtensionsLoggingVersion>
<MicrosoftNETCoreAppRefVersion>6.0.0-preview.4.21253.7</MicrosoftNETCoreAppRefVersion>
<MicrosoftVisualBasicVersion>10.1.0</MicrosoftVisualBasicVersion>
<MicrosoftVisualStudioCompositionVersion>16.1.8</MicrosoftVisualStudioCompositionVersion>
<NewtonsoftJsonVersion>12.0.1</NewtonsoftJsonVersion>
<PerfolizerVersion>0.2.1</PerfolizerVersion>
<SQLitePCLRawVersion>1.1.2</SQLitePCLRawVersion>
<SystemCollectionsImmutableVersion>1.3.1</SystemCollectionsImmutableVersion>
<SystemCommandLineRenderingVersion>2.0.0-beta1.20074.1</SystemCommandLineRenderingVersion>
<SystemCommandLineVersion>2.0.0-beta1.21216.1</SystemCommandLineVersion>
<SystemComponentModelCompositionVersion>4.7.0</SystemComponentModelCompositionVersion>
<SystemDirectoryServicesVersion>4.7.0</SystemDirectoryServicesVersion>
<SystemReflectionMetadataVersion>1.4.2</SystemReflectionMetadataVersion>
Expand Down
3 changes: 3 additions & 0 deletions eng/perf/CIPerf.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0PerfCore.ps1""" -v diag -etl -diff %*"
exit /b %ErrorLevel%
38 changes: 38 additions & 0 deletions eng/perf/ComparePerfResults.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[CmdletBinding(PositionalBinding=$false)]
Param(
[String] $baseline, # folder that contains the baseline results
[String] $results # folder that contains the performance results
)

function EnsureFolder {
param (
[String] $path
)
If(!(test-path $path))
{
New-Item -ItemType Directory -Force -Path $path
}
}

$currentLocation = Get-Location
try {

#Get result files
$baselineFolder = Join-Path $baseline "results"

$resultsFolder = Join-Path $results "results"

$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot '..\..')
$perfDiff = Join-Path $RepoRoot "src\Tools\PerfDiff\PerfDiff.csproj"
Invoke-Expression "dotnet run -c Release --project $perfDiff -- --baseline $baselineFolder --results $resultsFolder --failOnRegression --verbosity diag"
}
catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
$host.SetShouldExit(1)
exit
}
finally {
Set-Location $currentLocation
}
86 changes: 86 additions & 0 deletions eng/perf/DiffPerfToBaseLine.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[CmdletBinding(PositionalBinding=$false)]
Param(
[String] $baselineSHA, # git SHA to use as the baseline for performance
[String] $testSHA, # git SHA to use as the test for performance
[String] $output, # common folder to write the benchmark results to
[string] $projects, # semicolon separated list of relative paths to benchmark projects to run
[string] $filter, # filter for tests to run (supports wildcards)
[switch] $etl, # capture etl traces for performance tests
[switch] $ci # run in ci mode (fail fast an keep all partial artifacts)
)

function EnsureFolder {
param (
[String] $path # path to create if it does not exist
)
If(!(test-path $path))
{
New-Item -ItemType Directory -Force -Path $path
}
}

function RunTest {
param (
[String] $RunPerfTests, # path to the RunPerfTests.ps1 script
[String] $output, # common folder to write the benchmark results to
[String] $resultsFolder, # folder name to write the benchmark results to
[String] $temp, # root folder to check repos into
[String] $repoName, # folder name to place checked-out repo in
[String] $repoSHA, # git SHA run performance tests against
[String] $projects, # semicolon separated list of relative paths to benchmark projects to run
[String] $filter, # filter for tests to run (supports wildcards)
[bool] $etl, # capture etl traces for performance tests
[bool] $ci # run in ci mode (fail fast an keep all partial artifacts)
)

# Ensure output directory has been created
$resultsOutput = Join-Path $output $resultsFolder
EnsureFolder $resultsOutput

# Checkout SHA
$repoFolder = Join-Path $Temp $repoName
Invoke-Expression "git worktree add $repoFolder $repoSHA"

$commandArgs = "-root $repoFolder -output $resultsOutput -projects $projects -filter $filter"
if ($etl) {
$commandArgs = "$commandArgs -etl"
}

if ($ci) {
$commandArgs = "$commandArgs -ci"
}

Invoke-Expression "$RunPerfTests $commandArgs"
}

$currentLocation = Get-Location

# Setup paths
$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot '..\..')
$RunPerfTests = Join-Path $PSScriptRoot "RunPerfTests.ps1"
$ComparePerfResults = Join-Path $PSScriptRoot "ComparePerfResults.ps1"
$Temp = Join-Path $RepoRoot "temp"

try {
# Get baseline results
RunTest -RunPerfTests $RunPerfTests -output $output -resultsFolder "baseline" -temp $Temp -repoName "perfBaseline" -repoSHA $baselineSHA -projects $projects -filter $filter -etl $etl.IsPresent -ci $ci.IsPresent

# Get perf results
RunTest -RunPerfTests $RunPerfTests -output $output -resultsFolder "perfTest" -temp $Temp -repoName "perfTest" -repoSHA $testSHA -projects $projects -filter $filter -etl $etl.IsPresent -ci $ci.IsPresent

# Diff perf results
Invoke-Expression "$ComparePerfResults -baseline $baselineOutput -results $testOutput"
}
catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
$host.SetShouldExit(1)
exit
}
finally {
Invoke-Expression 'git worktree remove perfBaseline'
Invoke-Expression 'git worktree remove perfTest'
Invoke-Expression 'git worktree prune'
Set-Location $currentLocation
}
86 changes: 86 additions & 0 deletions eng/perf/PerfCore.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[CmdletBinding(PositionalBinding=$false)]
Param(
[string] $projects,
[string][Alias('v')]$verbosity = "minimal",
[string] $filter,
[switch] $etl,
[switch] $diff,
[switch] $ci,
[switch] $help,
[Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
)

function Print-Usage() {
Write-Host "Common settings:"
Write-Host " -verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
Write-Host " -help Print help and exit"
Write-Host ""

Write-Host "Actions:"
Write-Host " -diff Compare HEAD to baseline perf results"
Write-Host ""

Write-Host "Advanced settings:"
Write-Host " -etl Capture ETL traces of performance tests (requires admin permissions, default value is 'false')"
Write-Host " -filter Filter for tests to run (supports wildcards)"
Write-Host " -projects <value> Semi-colon delimited list of relative paths to benchmark projects."
Write-Host ""

Write-Host "Command line arguments not listed above are passed thru to msbuild."
Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)."
}

try {
if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) {
Print-Usage
exit 0
}

if ([string]::IsNullOrWhiteSpace($projects)) {
$projects = "src\PerformanceTests\Tests\PerformanceTests.csproj"
}

if ([string]::IsNullOrWhiteSpace($filter)) {
$filter = "*"
}

$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot '..\..')
$output = Join-Path $RepoRoot "artifacts\performance\perfResults"

# Diff two different SHAs
if ($diff) {
$DiffPerfToBaseLine = Join-Path $RepoRoot "eng\perf\DiffPerfToBaseLine.ps1"
$baselinejson = Get-Content -Raw -Path (Join-Path $RepoRoot "eng\perf\baseline.json") | ConvertFrom-Json
$baselineSHA = $baselinejson.sha
$commandArguments = "-baselineSHA $baselineSHA -testSHA HEAD -projects '$projects' -output '$output' -filter '$filter'"
if ($etl) {
$commandArguments = "$commandArguments -etl"
}
if ($ci) {
$commandArguments = "$commandArguments -ci"
}
Invoke-Expression "$DiffPerfToBaseLine $commandArguments"
exit
}

$commandArguments = "-projects '$projects' -root '$RepoRoot' -output '$output\perfTest' -filter '$filter'"
if ($etl) {
$commandArguments = "$commandArguments -etl"
}
if ($ci) {
$commandArguments = "$commandArguments -ci"
}

$RunPerfTests = Join-Path $RepoRoot "eng\perf\RunPerfTests.ps1"
Invoke-Expression "$RunPerfTests $commandArguments"
exit
}
catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
$host.SetShouldExit(1)
exit
}
finally {
}
35 changes: 35 additions & 0 deletions eng/perf/RunPerfTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[CmdletBinding(PositionalBinding=$false)]
Param(
[string] $projects, # semicolon separated list of relative paths to benchmark projects to run
[string] $filter, # filter for tests to run (supports wildcards)
[String] $root, # root folder all of the benchmark projects share
[String] $output, # folder to write the benchmark results to
[switch] $etl, # capture etl traces for performance tests
[switch] $ci # run in ci mode (fail fast an keep all partial artifacts)
)

try {
$projectsList = $projects -split ";"
foreach ($project in $projectsList){
$projectFullPath = Join-Path $root $project
$comandArguments = "run -c Release --project $projectFullPath -- --memory --exporters JSON --artifacts $output"
if ($ci) {
$comandArguments = "$comandArguments --stopOnFirstError --keepFiles"
}
if ($etl) {
Start-Process -Wait -FilePath "dotnet" -Verb RunAs -ArgumentList "$comandArguments --profiler ETW --filter $filter"
}
else {
Invoke-Expression "dotnet $comandArguments --filter $filter"
}
}
}
catch {
Write-Host $_
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
$host.SetShouldExit(1)
exit
}
finally {
}
5 changes: 5 additions & 0 deletions eng/perf/baseline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"release": "6.0",
"label": "roslyn analyzers baseline for main",
"sha": "f986c7b7aff265feb7536e1c7f98efcb9f14e077"
}
8 changes: 8 additions & 0 deletions src/Tools/PerfDiff/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Configuration for PublicAPI analyzers executed on this folder ###
[*.{cs,vb}]

dotnet_diagnostic.IDE1030.severity = none
dotnet_diagnostic.CA1052.severity = none
dotnet_diagnostic.CA1063.severity = none
dotnet_diagnostic.CA1724.severity = none
dotnet_diagnostic.CA1819.severity = none
Loading

0 comments on commit b8b68fa

Please sign in to comment.