9

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?

10

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
| improve this answer | |
  • 2
    Note: 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. – Amit Naidu Apr 18 '18 at 23:41
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

| improve this answer | |
  • To 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). – Stan Apr 22 at 18:53
2

typeperf has two drawbacks:

  1. typeperf with arguments as english names won't work on non-english machines, and
  2. 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
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.