Created
October 17, 2017 00:19
-
-
Save lzybkr/7eabc6e9963e6be7cb58351c3cd46883 to your computer and use it in GitHub Desktop.
Run PowerShell via perfview with PowerShell EventSource sources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
$etlFile = '.\perfviewdata.etl', | |
$scenario = 'echo 1', | |
$logFile = '.\perfview.log') | |
$perfViewArgs = @( | |
'/AcceptEula' | |
'/ThreadTime' | |
"/LogFile=$logFile" | |
"/DataFile:$etlFile" | |
'/noRundown' | |
'/Merge' | |
'/Zip:False' | |
# '/ClrEvents=default+GCSampledObjectAllocationHigh' | |
'/Providers:*Microsoft-PowerShell-Runspaces,*Microsoft-PowerShell-CommandDiscovery,*Microsoft-PowerShell-Parser,*Microsoft.Windows.PowerShell' | |
'run' | |
'c:\windows\sysnative\windowspowershell\v1.0\powershell.exe' | |
'-nop' | |
'-command' | |
$scenario | |
) | |
$process = Start-Process -FilePath PerfView.exe -ArgumentList $perfViewArgs -PassThru | |
$rs = [runspacefactory]::CreateRunspace($host) | |
$rs.Open() | |
$ps = [powershell]::Create() | |
$ps.Runspace = $rs | |
$null = $ps.AddCommand("Get-Content"). | |
AddArgument($logFile). | |
AddParameter("Wait"). | |
AddParameter("Tail", 0) | |
$null = $ps.AddCommand("Out-Host") | |
# If log file doesn't exist yet, wait a little bit so Get-Content doesn't fail | |
while (!(Test-Path $logFile)) | |
{ | |
Start-Sleep -Seconds 1 | |
} | |
$null = $ps.BeginInvoke() | |
$process.WaitForExit() | |
$ps.Stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment