Command Line utility to see list of tasks CPU Usage, Memory, and execute
Solution 1
You can use the tool typeperf
.
To list all processes:
typeperf "\Process(*)\% Processor Time" -sc 1
List all processes, take 5 samples at 10 second intervals:
typeperf "\Process(*)\% Processor Time" -si 10 -sc 5
If you want a specific process, node for example:
typeperf "\Process(node)\% Processor Time" -si 10 -sc 5
You also can dump it to a csv file and filter in a spreadsheet to remotely diagnose issues.
The following gives me 5 minutes (at 10 second intervals) of all processes. The data includes not just % Processor Time, but IO, memory, paging, etc.
typeperf -qx "\Process" > config.txt
typeperf -cf config.txt -o perf.csv -f CSV -y -si 10 -sc 60
More info: https://technet.microsoft.com/en-us/library/bb490960.aspx
Solution 2
Without dependence on system localization:
typeperf "\238(*)\6" -sc 1
typeperf "\238(*)\6" -si 10 -sc 5
typeperf "\238(_Total)\6" -si 10 -sc 5
Solution 3
typeperf has two drawbacks:
-
typeperf
with arguments as english names won't work on non-english machines, and -
typeperf
with arguments as numbers will break because those numbers vary by machine. (Source: https://stackoverflow.com/a/39650695)
To avoid those drawbacks, you can use powershell's Get-WmiObject
cmdlet. It uses different names compared to typeperf, but you can get the same information, as far as I can tell.
I think that running these commands in powershell will give you what you want:
echo 'Map of process ID to command line:'
Get-WmiObject -Query "Select * from Win32_Process" | Select-Object -Property ProcessId,ExecutablePath,CommandLine | ConvertTo-Csv -NoTypeInformation
echo 'Map of process ID to memory usage:'
Get-WmiObject -Query "Select * from Win32_PerfFormattedData_PerfProc_Process" | Select-Object -Property IDProcess,Name,PageFileBytes,PoolNonpagedBytes,PoolPagedBytes,PrivateBytes,VirtualBytes,WorkingSet | ConvertTo-Csv -NoTypeInformation
echo 'Map of process ID to CPU usage:'
Get-WmiObject -Query "Select * from Win32_PerfFormattedData_PerfProc_Process" | Select-Object -Property IDProcess,Name,PercentProcessorTime | ConvertTo-Csv -NoTypeInformation
echo 'Many people want to do some massaging of the "PercentProcessorTime" numbers above,'
echo 'because in their raw form those numbers (for a single process) can be over 100 percent.'
echo 'So divide all of the "PercentProcessorTime" numbers by this number:'
Get-WmiObject -Query "Select * from Win32_ComputerSystem" | Select-Object -Property NumberOfLogicalProcessors | ConvertTo-Csv -NoTypeInformation
Solution 4
If someone does not comfort with complicated PowerShell, I suggest gotop. It is a handy CLI tool helps you check resource usage in beautiful interface.
Related videos on Youtube
Aminadav Glickshtein
Started coding at the age of seven, with the ability to program as if it were a native language. Has in-depth knowledge of software development, cloud, big data, web, desktop, cybersecurity, blockchain, DevOps and mobile development. Latest innovation: Control V
Updated on September 18, 2022Comments
-
Aminadav Glickshtein almost 2 years
I want to log, every 10 minutes, list of all the apps in windows that now running, the CPU usage, and memory usage.
I have many node.exe tasks, so I want to see the arguments of the task (for example:
node c:\myscript.js
I tried:
tasklist/?
but didn't found anything related to cpu usage.I tried:
procexp/?
but didn't found anyway to export the list to file (or show in console)I tried:
cprocess
(NirSoft), it can dump to file, and show CPU, but it don't give the arguments of the exe that runned.Any idea?
-
Amit Naidu about 6 yearsNote: In order to use typeperf, you must either be a member of the local Performance Log Users group, or the command must be executed from an elevated command window.
-
Stan about 4 yearsTo continuously save CPU usage per process, one should use something like this:
typeperf "\230(*)\6" -si 10 -o perf.csv -f CSV
, where 230 is the "Process" counter. 238 is the "Processor" counter as a whole (the command from the answer will show CPU usage per core, without tasks).