-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunOpenProjectBenchmarks.ps1
140 lines (108 loc) · 4.65 KB
/
runOpenProjectBenchmarks.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
param(
$studioPath = "C:\Dev\beta\Studio\Output\bin\Debug\UiPath.Studio.exe",
$logsPath = "C:\Users\andrei.ungureanu\AppData\Local\UiPath\Logs",
$benchmarkProjectsRootPath = "C:\PerformancePipeline\Projects",
$tempRunFolder = "C:\temp",
$timeoutPerRunInSeconds = 30,
$iterationsPerBenchmark = 1
)
Write-Host $studioPath
Write-Host $logsPath
Write-Host $benchmarkProjectsRootPath
Write-Host $tempRunFolder
Write-Host $timeoutPerRunInSeconds
Write-Host $iterationsPerBenchmark
class PerformanceBenchmark {
[string]$label
[string]$duration
[string]$projectName
[string]$targetFramework
[string]$expressionLanguage
[string] ToString() {
return "Label: $($this.label), Start Time: $($this.startTime), End Time: $($this.endTime), Duration: $($this.duration)"
}
}
[string[]]$labels =
"OpenProject\s$",
"LoadAssemblies",
"Register API",
"AfterRegistration",
"Register Metadata",
"LoadActivitiesAsync",
"ExecuteStageOneOpen",
"Register Activities Root",
"InitializeGlobalVariables",
"SetActivitiesTypeInformation",
"InitializeActivitiesFromAssemblies",
"Entities fix broken installations on project open"
"Just-in-Time Custom Types fix broken installations on project open"
[PerformanceBenchmark[]]$results = @();
Set-Item -Path env:STUDIO_ENABLE_PERFORMANCE_LOG -Value "test"
$benchmarks = Get-ChildItem -Path $benchmarkProjectsRootPath -Directory
Write-Host "Identified the following benchmarks for running:"
foreach ($benchmark in $benchmarks) {
Write-Host $benchmark.Name
}
Write-Host ""
function Kill-Studio {
$processes = Get-Process | Where-Object { $_.ProcessName -like "*UiPath*" }
$processes | ForEach-Object { Stop-Process $_.Id -Force -ErrorAction SilentlyContinue }
# Wait for the processes to close
Start-Sleep -Seconds 1
}
function Run-Benchmark {
}
foreach ($benchmark in $benchmarks) {
Write-Host "Running benchmark: " $benchmark.Name
$i = 0;
for ($i = 0; $i -lt $iterationsPerBenchmark; $i++) {
Write-Host "Iteration:" $i
$startTime = Get-Date
Kill-Studio
Remove-Item $logsPath\* -Recurse
$benchmarkFolder = $benchmarkProjectsRootPath + "\" + $benchmark
$iterationTempFolder = $tempRunFolder + "\" + $benchmark + "_" + $i
Copy-Item -Path $benchmarkFolder -Destination $iterationTempFolder -Recurse
$projectJsonPath = $iterationTempFolder + "\project.json"
$projectJson = Get-Content $projectJsonPath | Out-String | ConvertFrom-Json
$name = $projectJson.name
$targetFramework = $projectJson.TargetFramework
$expressionLanguage = $projectJson.ExpressionLanguage
Start-Process -FilePath "`"$studioPath`"" -ArgumentList "`"$projectJsonPath`""
$shellLogFile = Get-ChildItem -Path $logsPath -Filter "*_UiPath.Studio.log" | Select-Object -First 1
while ($shellLogFile -eq $null -or !(Select-String -Path $shellLogFile -Pattern "process side open complete" | Select-Object -Last 1)) {
$elapsed = ((Get-Date) - $startTime).TotalSeconds
if ($elapsed > $timeoutPerRunInSeconds) {
break
}
Start-Sleep -Seconds 1
$shellLogFile = Get-ChildItem -Path $logsPath -Filter "*_UiPath.Studio.log" | Select-Object -First 1
}
$timestampString = "HH:mm:ss.fffffff"
$regexPattern = '^\d{2}:\d{2}:\d{2}\.\d+'
foreach ($label in $labels)
{
$beginLine = Select-String -Path $shellLogFile -Pattern "Begin $label" | Select-Object -ExpandProperty Line
$endLine = Select-String -Path $shellLogFile -Pattern "End $label" | Select-Object -ExpandProperty Line
$beginTimestampString = [regex]::Matches($beginLine, $regexPattern).Value
$endTimestampString = [regex]::Matches($endLine, $regexPattern).Value
$beginTimestamp = [DateTime]::ParseExact($beginTimestampString, $timestampString, $null)
$endTimestamp = [DateTime]::ParseExact($endTimestampString, $timestampString, $null)
$taskDuration = $endTimestamp.Subtract($beginTimestamp)
$results += [PerformanceBenchmark]@{
label = $label;
projectName = $name;
duration = $taskDuration;
targetFramework = $targetFramework;
expressionLanguage = $expressionLanguage;
}
}
foreach ($result in $results)
{
Write-Host $result.ToString()
}
Kill-Studio
Remove-Item -Path $iterationTempFolder -Recurse -Force
}
$results | ConvertTo-Json | Out-File -FilePath "results.json"
}