Created
September 5, 2017 12:49
-
-
Save wallabra/be99afdf3ad9104a8a0cd6ff43944e1b to your computer and use it in GitHub Desktop.
Failed attempt at a process CPU watch
This file contains hidden or 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
@echo off | |
SETLOCAL ENABLEDELAYEDEXPANSION | |
SET /a i=0 | |
SET task=[none] | |
SET cpu=0 | |
SET biggestCpu=0 | |
SET biggestTask=[none] | |
SET midList=0 | |
FOR /f "tokens=*" %%d IN ('tasklist /v^|repl " {2,4096}" "\r\n" x') DO ( | |
IF "!midList!"=="0" ( | |
IF !i! EQU 5 ( | |
SET midList=1 | |
SET i=0 | |
) ELSE ( | |
SET /a i+=1 | |
) | |
) ELSE ( | |
IF !i! EQU 1 ( | |
SET task=%%d | |
) | |
SET /a mi=!i! %% 12 | |
IF !mi! EQU 11 ( | |
SET i=0 | |
IF "%task%" NEQ "WMIPRVSE" ( | |
SET _ktime=0 | |
SET _utime=0 | |
FOR /f "tokens=*" %%c IN ('wmic path win32_process get KernelModeTime^,Name^,UserModeTime^|find "%task%"^|repl " +" "\r\n" x') DO ( | |
IF "!_ktime!"=="0" ( | |
SET _ktime=%%c | |
) ELSE ( | |
IF "!_utime!"=="0" ( | |
SET _utime=%%c | |
) ELSE ( | |
SET /a cpu= !_ktime! + !_utime! | |
SET /a cpu= !cpu! / 10000000 | |
SET _ktime=0 | |
SET _utime=0 | |
) | |
) | |
) | |
) | |
CALL :processFound task cpu | |
) ELSE ( | |
SET /a i+=1 | |
) | |
) | |
REM ECHO %%d !i! | |
) | |
CALL :done | |
GOTO :eof | |
:processFound | |
CALL SET cpuCont=%%%2%% | |
IF %cpuCont% GTR %biggestCpu% ( | |
CALL SET biggestCpu=%%%2%% | |
CALL SET biggestTask=%%%1%% | |
) ELSE ( | |
IF %cpuCont% EQU %biggestCpu% ( | |
CALL SET biggestTask=%%biggestTask%%,%%%1%% | |
) | |
) | |
GOTO :eof | |
:done | |
ECHO == CPU Stats == | |
ECHO Task: %biggestTask% | |
ECHO CPU: %biggestCpu%%% | |
GOTO :eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment