Last active
May 30, 2023 10:03
-
-
Save he3als/17a2214a864eafeff03ab2ec138cf761 to your computer and use it in GitHub Desktop.
DPC latency script using xperf
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
<# : batch portion | |
@echo off & cls | |
:: script made by he3als | |
::::::::::::::::::: | |
:: Configuration :: | |
::::::::::::::::::: | |
set "tempDir=%windir%\Temp" | |
:: uncomment if you want to skip the file picker prompt | |
:: set "selectedFilePath=%userprofile%\Downloads\dpcisr.txt" | |
:: uncomment if you want to skip the duration prompt | |
:: set "timeout=30" | |
:: manually define xperf path | |
:: set "xperfPath=C:\xperf.exe" | |
:: credit to privacy.sexy | |
fltmc >nul 2>&1 || ( | |
echo Administrator privileges are required. | |
powershell -NoProfile Start -Verb RunAs '%0' 2> nul || ( | |
echo Right-click on the script and select "Run as administrator". | |
pause & exit /b 1 | |
) | |
exit /b | |
) | |
if defined xperfPath (set "PATH=%PATH%;%xperfPath%") | |
where xperf.exe > nul 2>&1 || ( | |
echo You need xperf in PATH for this script to work, get the Windows ADK. | |
echo Alternatively, manually define it in the script's configuration. | |
echo] | |
pause | |
exit /b 1 | |
) | |
:filePicker | |
if defined selectedFilePath goto time | |
echo Launching folder picker to save the final output TXT to... | |
set "psScript=%~f0" | |
powershell -noprofile -command "Get-Content """$env:psScript""" -Raw | iex" > nul | |
if not exist "%tempDir%\filePickerPath.txt" goto filePickerError | |
for /f "tokens=* usebackq" %%a in (`type "%tempDir%\filePickerPath.txt"`) do (set selectedFilePath=%%a) | |
if "%selectedFilePath%"=="none" (exit /b) else ( | |
if "%selectedFilePath%"=="" (goto filePickerError) else (goto time) | |
) | |
:filePickerError | |
echo Something went wrong with the file picker. | |
echo If you cannot solve this problem, | |
echo] | |
pause | |
exit /b 1 | |
:time | |
if defined timeout goto xperf | |
echo] | |
set /p timeout=Enter the time you want xperf to run for in seconds (pressing enter will set 30 seconds): || set timeout=30 | |
:xperf | |
cls | |
echo Running xperf... | |
echo -------------------------------------- | |
xperf -on base+dpc+interrupt > nul | |
timeout /nobreak /t %timeout% | |
echo] | |
echo Saving trace and cleaning up... | |
echo -------------------------------------- | |
xperf -d "%tempDir%\dpcisr.etl" > nul | |
xperf -i "%tempDir%\dpcisr.etl" -o "%selectedFilePath%" -a dpcisr > nul | |
del /f /q "%tempDir%\dpcisr.etl" > nul 2>&1 | |
:: this trace is always generated, not sure why | |
del /f /q "C:\kernel.etl" > nul 2>&1 | |
echo] | |
echo Completed, you will find the data at "%selectedFilePath%" | |
echo] | |
echo [1] Exit - [2] Open file | |
choice /c:12 /n > nul | |
if %errorlevel%==1 (exit /b) else (start "DPC ISR Latency Document" "%selectedFilePath%" & exit /b) | |
: end batch / begin powershell #> | |
Add-Type -AssemblyName System.Windows.Forms | |
$saveFileDialog = New-Object System.Windows.Forms.SaveFileDialog | |
$saveFileDialog.Title = "Select place to save the report text file to" | |
$saveFileDialog.InitialDirectory = "$env:userprofile\Downloads" | |
$saveFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*" | |
if ($saveFileDialog.ShowDialog() -eq "OK") { | |
$filename = $saveFileDialog.FileName | |
if (Test-Path "$env:tempDir\filePickerPath.txt") {Remove-Item "$env:tempDir\filePickerPath.txt" -Force | Out-Null} | |
$filename.Trim('"') > "$env:tempDir\filePickerPath.txt" | |
} else { | |
if (Test-Path "$env:tempDir\filePickerPath.txt") {Remove-Item "$env:tempDir\filePickerPath.txt" -Force | Out-Null} | |
"none" > "$env:tempDir\filePickerPath.txt" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment