Skip to content

Commit c6aa06c

Browse files
committed
perf tests script MVP
1 parent 881f572 commit c6aa06c

2 files changed

Lines changed: 172 additions & 0 deletions

File tree

scripts/perftests.ps1

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
param(
2+
[Parameter(Mandatory = $true)][string]$Cache,
3+
[Parameter(Mandatory = $true)][string]$TestsPath,
4+
[string]$Repository,
5+
[string]$Revision,
6+
[string[]]$BeforeSteps = $null,
7+
[string[]]$Projects,
8+
[string[]]$Configurations = @("Debug")
9+
)
10+
11+
class TestCase {
12+
[CheckoutSpec]$CheckoutSpec
13+
[string[]]$Projects
14+
[string[]]$Configurations = @("Debug")
15+
}
16+
17+
class Tests {
18+
[string]$Cache
19+
[TestCase[]]$Tests
20+
# TODO FSC path
21+
}
22+
23+
class CheckoutSpec {
24+
[string]$Repository
25+
[string]$Revision
26+
[string[]]$BeforeSteps = @()
27+
28+
[string]GetDir($CacheBase){
29+
return Join-Path (Join-Path $CacheBase $this.Repository) $this.Revision
30+
}
31+
[string]GetRepositoryUrl(){
32+
$repo = $this.Repository
33+
return "https://github.com/$repo"
34+
}
35+
}
36+
37+
class Checkout {
38+
[string]$Cache
39+
[CheckoutSpec]$Spec
40+
[string]GetDir(){
41+
return $this.Spec.GetDir($this.Cache)
42+
}
43+
[string]GetRepositoryUrl(){
44+
return $this.Spec.GetRepositoryUrl()
45+
}
46+
}
47+
48+
function Checkout-Codebase {
49+
[OutputType([string])]
50+
param(
51+
[Parameter(Mandatory = $true)][Checkout]$checkout
52+
)
53+
$repositoryUrl = $checkout.GetRepositoryUrl()
54+
$cacheDir = $checkout.GetDir()
55+
56+
if(Test-Path -Path $cacheDir){
57+
Write-Host "'$cacheDir' exists - assuming that it contains the correct code revision."
58+
} else {
59+
Write-Host "git clone '$repositoryUrl' into '$cacheDir'"
60+
git clone $repositoryUrl $cacheDir > Write-Host
61+
Write-Host "git clone finished"
62+
}
63+
}
64+
65+
Set-StrictMode -Version Latest
66+
$oldLocation = Get-Location
67+
68+
function SingleTest{
69+
param(
70+
[Parameter(Mandatory = $true)][string]$Cache,
71+
[Parameter(Mandatory = $true)][TestCase]$Test
72+
)
73+
$checkoutSpec = $test.CheckoutSpec
74+
$checkout = [Checkout]::new()
75+
$checkout.Cache = $Cache
76+
$checkout.Spec = $checkoutSpec
77+
Checkout-Codebase -Checkout $checkout
78+
$checkoutDir = $checkout.GetDir()
79+
Set-Location $checkoutDir
80+
81+
$beforeSteps = $checkoutSpec.BeforeSteps
82+
if($null -eq $beforeSteps){
83+
$beforeSteps = @()
84+
}
85+
foreach ($step in $beforeSteps) {
86+
Write-Host "Running BeforeStep: '$step'"
87+
Invoke-Expression "$step" > $null
88+
}
89+
90+
function BuildProjectCollectTimings{
91+
param(
92+
[Parameter(Mandatory = $true)][string]$Project,
93+
[Parameter(Mandatory = $true)][string]$Configuration
94+
)
95+
$projectDir = (Get-ChildItem -Path $Project -File).DirectoryName
96+
$projectName = (Get-ChildItem -Path $Project -File).Name
97+
Set-Location $projectDir
98+
dotnet build -c $Configuration $Project > $null
99+
$logPath = "msbuild.log"
100+
dotnet build -c $Configuration --no-incremental --no-dependencies $projectName /p:OtherFlags="--times" -fl "-flp:logfile=$logPath;verbosity=detailed" > $null
101+
$lines = Get-Content $logPath | Select-String -pattern "Realdelta" | % {$_.Line.Trim()}
102+
return $lines
103+
}
104+
105+
foreach ($configuration in $Test.Configurations) {
106+
foreach ($project in $Test.Projects) {
107+
$projectPath = Join-Path $checkoutDir -ChildPath $Project
108+
if(-not (Test-Path -Path $projectPath)) {
109+
throw "Project file '$projectPath' does not exist."
110+
}
111+
$lines = BuildProjectCollectTimings -Project $projectPath -Configuration $configuration
112+
Write-Host "Timings for '$configuration - $project':"
113+
$lines | Write-Host
114+
}
115+
}
116+
}
117+
118+
function Run-Tests{
119+
param(
120+
[Parameter(Mandatory = $true)][Tests]$Tests
121+
)
122+
foreach ($test in $Tests.Tests) {
123+
SingleTest -Cache $Tests.Cache -Test $test
124+
}
125+
}
126+
127+
function Build-SingleTest {
128+
$checkoutSpec = [CheckoutSpec]::new()
129+
$checkoutSpec.Repository = $Repository
130+
$checkoutSpec.Revision = $Revision
131+
132+
$test = [TestCase]::new()
133+
$test.CheckoutSpec = $checkoutSpec
134+
$test.Projects = $Projects
135+
$test.Configuration = $Configuration
136+
137+
$tests = [Tests]::new()
138+
$tests.Cache = $Cache
139+
$tests.Tests = @($test)
140+
}
141+
142+
function Parse-Tests {
143+
return Get-Content $TestsPath | ConvertFrom-Json
144+
}
145+
146+
#$tests = Build-SingleTest
147+
$tests = [Tests]::new()
148+
$tests.Cache = $Cache
149+
$tests.Tests = Parse-Tests
150+
Run-Tests -Tests $tests
151+
152+
Set-Location $oldLocation

scripts/tests.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"checkoutSpec": {
4+
"repository": "safesparrow/fsharp-benchmark-generator",
5+
"revision": "main",
6+
"beforeSteps": []
7+
},
8+
"projects": ["Generator.fsproj", "Runner/Runner.fsproj"],
9+
"configurations": ["Debug", "Release"]
10+
},
11+
{
12+
"checkoutSpec": {
13+
"repository": "dotnet/fsharp",
14+
"revision": "main",
15+
"beforeSteps": ["./build.cmd -noVisualStudio"]
16+
},
17+
"projects": ["src/compiler/FSharp.Compiler.Service.fsproj"],
18+
"configurations": ["Debug", "Release"]
19+
}
20+
]

0 commit comments

Comments
 (0)