This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
memory-bench.ps1
77 lines (56 loc) · 2.37 KB
/
memory-bench.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
param (
[Parameter(Mandatory=$true)][string]$browser,
[Parameter(Mandatory=$true)][string]$test
)
Write-Output "Measuring $browser for scenario $test"
$repeats = 3
$wait = 30
$braveapplication = '\BraveSoftware\Brave-Browser\Application\'
$localinstall = Test-Path -Path $ENV:LOCALAPPDATA$braveapplication
if ($localinstall) {
$workingdir = "$ENV:LOCALAPPDATA$braveapplication"
} else {
$workingdir = Get-Location
}
$userdatadir = "$pwd\mem-test\"
$scenariosdir = "$pwd\scenarios\"
Write-Output "Running scenarios $test*.txt from $scenariosdir"
$result = @{scenarios = @()}
Get-ChildItem $scenariosdir -Filter $test*.txt | Foreach-Object {
$fullname = $_.FullName
$test = $_.Name
$testresult = @{test = $test; runs = @()}
for ($i=1; $i -le $repeats; $i++) {
Start-Process -FilePath $browser -ArgumentList --user-data-dir=$userdatadir, --no-first-run
Start-Sleep -Seconds 5
Get-Content $fullname | ForEach-Object {
$page = $_
Write-Output "Opening page $page"
Start-Process -FilePath $browser -ArgumentList --user-data-dir=$userdatadir, --no-first-run, $page
Start-Sleep -Seconds 5
}
Start-Sleep -Seconds $wait
# $m = ps $browser | measure PM -Sum
$m = Get-WmiObject -class Win32_PerfFormattedData_PerfProc_Process -filter "Name LIKE '$($browser)%'" |
Select-Object -expand workingSetPrivate |
Measure-Object -sum
("$browser $test $i {0:N2}MB " -f ($m.sum / 1mb))
$testresult.runs += $m.sum
# $testresult.runs += 3000
$process = Get-Process -Name $browser
while ($process -ne $null) {
Write-Output "Browser Process Running, attempting to close main window: $process"
$process | Stop-Process -Force
Start-Sleep 5
$process = Get-Process -Name $browser -ErrorAction SilentlyContinue
}
Remove-Item -Recurse -Force $userdatadir
}
$testresult.average = ($testresult.runs | Measure-Object -Average).Average
@{memory = $testresult} | ConvertTo-Json -Depth 4 -Compress |
Out-File -FilePath memory-$test.json -Encoding UTF8
$result.scenarios += $testresult
}
$result | ConvertTo-Json -Depth 4 -Compress |
Out-File -FilePath memory-results.json -Encoding UTF8
Get-Content -Path "$pwd\memory-results.json"