命令行实用程序用于查看任务 CPU 使用率、内存和执行列表

命令行实用程序用于查看任务 CPU 使用率、内存和执行列表

我想每 10 分钟记录一次 Windows 中当前正在运行的所有应用程序列表、CPU 使用率和内存使用率。

我有很多 node.exe 任务,所以我想查看任务的参数(例如:node c:\myscript.js

我试过:tasklist/?但没有发现任何与 CPU 使用率相关的内容。

我试过了:procexp/?但没有找到将列表导出到文件(或在控制台中显示)的方法

我试过:cprocess(NirSoft),它可以转储到文件,并显示 CPU,但它没有提供运行的 exe 的参数。

任何想法?

答案1

您可以使用该工具typeperf

列出所有进程:

typeperf "\Process(*)\% Processor Time" -sc 1

列出所有进程,每隔 10 秒进行 5 次采样:

typeperf "\Process(*)\% Processor Time" -si 10 -sc 5

如果你想要一个特定的进程,节点例如:

typeperf "\Process(node)\% Processor Time" -si 10 -sc 5

您还可以将其转储到 csv 文件并在电子表格中过滤以远程诊断问题。

下面给出了所有进程的 5 分钟内(间隔 10 秒)的数据。数据不仅包括处理器时间百分比,还包括 IO、内存、分页等。

typeperf -qx "\Process" > config.txt
typeperf -cf config.txt -o perf.csv -f CSV -y -si 10 -sc 60

更多信息:https://technet.microsoft.com/en-us/library/bb490960.aspx

答案2

typeperf 有两个缺点:

  1. typeperf带有英文名称的参数在非英语机器上不起作用,并且
  2. typeperf使用数字作为参数会出错,因为这些数字因机器而异。(来源:https://stackoverflow.com/a/39650695

为了避免这些缺点,您可以使用 powershell 的Get-WmiObjectcmdlet。据我所知,它使用的名称与 typeperf 不同,但您可以获得相同的信息。

我认为在 powershell 中运行这些命令会给你你想要的结果:

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

答案3

不依赖系统本地化:

typeperf "\238(*)\6" -sc 1

typeperf "\238(*)\6" -si 10 -sc 5

typeperf "\238(_Total)\6" -si 10 -sc 5

答案4

如果有人不喜欢复杂的 PowerShell,我建议回到顶部。它是一个方便的 CLI 工具,可帮助您在漂亮的界面中检查资源使用情况。

相关内容