很想知道一旦达到 GPU 阈值如何整合。
例如,当程序/应用程序的使用率低于 10% 时,程序/应用程序就会退出,如果可能的话,在批处理文件中,我尝试使用混合 CPU + 内存阈值,但这并不总是在所有应用程序中正常工作,所以我认为 GPU 阈值可以解决这个问题,因为它有时非常确定,不像 CPU + 内存阈值有时会有很大差异。
以下是需要包含 GPU 阈值的阈值批处理示例
@echo OFF
Title Autolaunch and Autoexit All Game Processes tied to Game
set VK_LAYER_PATH="" "DOOM;%VK_LAYER_PATH%"
set VK_INSTANCE_LAYERS=VK_LAYER_reshade
@start "" "DOOMLauncher.exe" +devMode_Enable 1 +com_restarted 1 +com_gameMode 1 +com_skipIntroVideo 1 +exec DOOMConfig.cfg 1 +image_usecompression 0 +com_skipKeyPressOnLoadScreens 1
::========= Set cpuThreshold [%] and memThreshold [according to displayed value in Cmd window] =========
set /a cpuThreshold=10 & set /a memThreshold=480000
::initialize vars and set process_name:
set /a low=0 & setlocal enableDelayedExpansion & set process_name=DOOMx64vk.exe
set pn=%process_name:.exe=%
::==================================================================
timeout /t 20
cd /D "C:\Program Files\NVIDIA Corporation\NVSMI\"
:GPU
for /f skip^=8^ tokens^=1-3^ delims^=^| %%a in ('"nvidia-smi.exe"') do (
for /f "tokens=1-2 delims= " %%g in ("%%c") do set z=%%g) & goto :breakForLoop
:breakForLoop
set /a z=z & timeout /t 13
if %z% Lss 5 TaskKill /F /im %process_name% & goto RUNNING
::Get NumberOfCores
for /f "tokens=*" %%f in ('wmic cpu get NumberOfCores /value ^| find "="') do set %%f
:CheckCpuAndMem
set /a process_snapshot=0 & set /a memUsg=0
::CPU
for /f skip^=2^ tokens^=3^ delims^=^" %%p in (
'typeperf "\Process(%pn%)\%% Processor Time" -sc 1') do for /f "tokens=1 delims=." %%a in (
"%%p") do set /a process_snapshot=%%a/%NumberOfCores%
if %process_snapshot% LSS %cpuThreshold% (set /a low+=1) else (set /a low=0)
::Mem
for /f "tokens=5" %%p in (
'tasklist ^|findstr %process_name%') do for /f "tokens=1,2,3 delims=." %%a in ("%%p") do set /a memUsg=%%a%%b%%c/1000
if %memUsg% lss %memThreshold% (set /a low+=1) else (set /a low=0)
::echo feedback
@echo process_snapshot: %process_snapshot%, memUsage: %memUsg%; LowCpuAndMem: %low%
::12 checks (Cpu & Mem) times 3 sec timeout plus processing delay yields ca 30 sec
if %low% GEQ 12 taskkill /F /T /IM %process_name% & goto RUNNING
timeout /t 3
tasklist|findstr %process_name% > nul && GOTO GPU
:RUNNING
tasklist|findstr %process_name% > nul && GOTO RUNNING
taskkill /F /T /IM cheatengine-x86_64.exe & taskkill /F /T /IM WerFault.exe & exit /b
答案1
@echo off && Setlocal EnableDelayedExpansion
set "_process_name=Folding.exe" && cmd /v /c "set "_pn=!_process_name:~0,-4!""
set /a "_cpuThreshold=10, _memThreshold=450000" && start "" "!_process_name!"
timeout 2 & for /f tokens^=2delims^=^= %%f in (
'wmic cpu get NumberOfCores /value')do ^< nul set "_NumberOfCores=%%~f"
:CheckCpuAndMem
set /a "_process_snapshot=0, _memUsg=0"
for /f skip^=2tokens^=3delims^=^" %%p in ('
typeperf "\Process(!_pn!)\%% Processor Time" -sc 1
')do for /f tokens^=1delims^=. %%a in ('echo\%%~p
')do set /a "_process_snapshot=%%~a/!_NumberOfCores!"
if !_process_snapshot! LSS !_cpuThreshold! (
set /a "_low+=1+0") else set /a "_low-=_low"
for /f tokens^=5 %%p in ('tasklist ^|findstr.exe "!_process_name!"
')do for /f tokens^=1*delims^=^, %%a in ("%%~p")do set "_memUsg=%%~a%%~b"
if !_memUsg! lss !_memThreshold! (set /a "_low+=1+0") else set /a "_low-=_low"
echo\process_snapshot: !_process_snapshot!, memUsage: !_memUsg!, LowCpuAndMem: !_low!
if !_low! GEQ 12 taskkill /F /T /IM !_process_name! && goto=:RUNNING // where is ???
timeout 3 & tasklist|findstr /i "!_process_name!" >nul && GOTO=:CheckCpuAndMem
exit /b
GOTO=:RUNNING // where is ???
您的代码中存在冲突,您为 定义了一个以千为单位的值,但在 中memThreshold
使用了以百为单位的条件( ) :set /a memUsg=%%a%%b%%c/1000
if memUsg
000 lss memThreshold000
set memThreshold=450000
...
) do set /a memUsg=%%a%%b%%c/1000
if %memUsg% lss %memThreshold%
rem :: is the same ::
if 148 lss 450000 ...