windows 跟踪每个进程的 CPU 和内存使用情况
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/69332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tracking CPU and Memory usage per process
提问by Eli Bendersky
I suspect that one of my applications eats more CPU cycles than I want it to. The problem is - it happens in bursts, and just looking at the task manager doesn't help me as it shows immediate usage only.
我怀疑我的一个应用程序占用了比我想要的更多的 CPU 周期。问题是 - 它是突然发生的,只是查看任务管理器对我没有帮助,因为它只显示即时使用情况。
Is there a way (on Windows) to track the history of CPU & Memory usage for some process. E.g. I will start tracking "firefox", and after an hour or so will see a graph of its CPU & memory usage during that hour.
有没有办法(在 Windows 上)跟踪某个进程的 CPU 和内存使用历史。例如,我将开始跟踪“firefox”,大约一小时后将看到该小时内其 CPU 和内存使用情况的图表。
I'm looking for either a ready-made tool or a programmatic way to achieve this.
我正在寻找现成的工具或编程方式来实现这一目标。
回答by Martin08
Just type perfmon
into Start > Run
and press enter. When the Performance window is open, click on the + sign to add new counters to the graph. The counters are different aspects of how your PC works and are grouped by similarity into groups called "Performance Object".
只需键入perfmon
到Start > Run
,然后按回车。当 Performance 窗口打开时,单击 + 号将新计数器添加到图表中。计数器是 PC 工作方式的不同方面,并按相似性分组到称为“性能对象”的组中。
For your questions, you can choose the "Process", "Memory" and "Processor" performance objects. You then can see these counters in real time
对于您的问题,您可以选择“进程”、“内存”和“处理器”性能对象。然后你可以实时看到这些计数器
You can also specify the utility to save the performance data for your inspection later. To do this, select "Performance Logs and Alerts" in the left-hand panel. (It's right under the System Monitor console which provides us with the above mentioned counters. If it is not there, click "File" > "Add/remove snap-in", click Add and select "Performance Logs and Alerts" in the list".) From the "Performance Logs and Alerts", create a new monitoring configuration under "Counter Logs". Then you can add the counters, specify the sampling rate, the log format (binary or plain text) and log location.
您还可以指定实用程序来保存性能数据以供以后检查。为此,请在左侧面板中选择“性能日志和警报”。(它就在 System Monitor 控制台下方,它为我们提供了上述计数器。如果没有,请单击“文件”>“添加/删除管理单元”,单击“添加”并在列表中选择“性能日志和警报” ".) 从“性能日志和警报”中,在“计数器日志”下创建一个新的监控配置。然后您可以添加计数器、指定采样率、日志格式(二进制或纯文本)和日志位置。
回答by Niall
Process Explorercan show total CPU time taken by a process, as well as a history graph per process.
Process Explorer可以显示进程占用的总 CPU 时间,以及每个进程的历史图表。
回答by CppNoob
Using perfmon.exe, I have tried using the "Private Bytes" counter under "Process" counters for tracking memory usage and it works well.
使用 perfmon.exe,我尝试使用“进程”计数器下的“私有字节”计数器来跟踪内存使用情况,并且效果很好。
回答by Rich Kreider
maybe you can use this. It should work for you and will report processor time for the specified process.
也许你可以使用这个。它应该适合您,并将报告指定进程的处理器时间。
@echo off
: Rich Kreider <[email protected]>
: report processor time for given process until process exits (could be expanded to use a PID to be more
: precise)
: Depends: typeperf
: Usage: foo.cmd <processname>
set process=%~1
echo Press CTRL-C To Stop...
:begin
for /f "tokens=2 delims=," %%c in ('typeperf "\Process(%process%)\%% Processor Time" -si 1 -sc 1 ^| find /V "\"') do (
if %%~c==-1 (
goto :end
) else (
echo %%~c%%
goto begin
)
)
:end
echo Process seems to have terminated.
回答by Ady Romantika
I agree, perfmon.exe allows you to add counters (right click on the right panel) for any process you want to monitor.
我同意, perfmon.exe 允许您为要监视的任何进程添加计数器(右键单击右侧面板)。
Performance Object: Process Check "Select instances from list" and select firefox.
性能对象:处理选中“从列表中选择实例”并选择 firefox。
回答by doflynn
WMI is Windows Management Instrumentation, and it's built into all recent versions of Windows. It allows you to programmatically track things like CPU usage, disk I/O, and memory usage.
WMI 是 Windows Management Instrumentation,它内置于所有最新版本的 Windows 中。它允许您以编程方式跟踪 CPU 使用率、磁盘 I/O 和内存使用率等内容。
Perfmon.exe is a GUI front-end to this interface, and can monitor a process, write information to a log, and allow you to analyze the log after the fact. It's not the world's most elegant program, but it does get the job done.
Perfmon.exe 是这个界面的 GUI 前端,可以监控进程,将信息写入日志,并允许您事后分析日志。它不是世界上最优雅的程序,但它确实完成了工作。
回答by dyasta
Process Lasso is designed more for process automation and priority class optimization, not graphs. That said, it doesoffer per-process CPU utilization history (drawn as a white line on the graph) but it does NOToffer per-process memory utilization history.
Process Lasso 更多地设计用于流程自动化和优先级优化,而不是图形。这就是说,它确实提供每个进程的CPU占用率的历史(画成白线图形上的),但它不提供每个进程的内存使用率的历史。
DISCLAIMER: I am the author of Process Lasso, but am not actually endorsing it here - as there are better solutions (perfmon being the best).
免责声明:我是 Process Lasso 的作者,但实际上并没有在这里支持它 - 因为有更好的解决方案(perfmon 是最好的)。
The best thing ever is Windows Vista+ Resource and Performance Monitor. It can track usage of CPU, Memory, Network, and Disk accesses by processes over time. It is a great overall system information utility that should have been created long ago. Unless I am mistaken, it can track per-process CPU and memory utilization over time (amongst the other things listed).
有史以来最好的东西是 Windows Vista+ 资源和性能监视器。它可以跟踪进程随时间推移对 CPU、内存、网络和磁盘访问的使用情况。它是一个很棒的整体系统信息实用程序,早就应该创建了。除非我弄错了,否则它可以随着时间的推移跟踪每个进程的 CPU 和内存利用率(以及列出的其他内容)。
回答by sean
Although I have not tried this out, ProcDumpseems like a better solution.
虽然我还没有尝试过,但ProcDump似乎是一个更好的解决方案。
Description from site:
来自网站的描述:
ProcDump is a command-line utility whose primary purpose is monitoring an application for CPU spikes and generating crash dumps during a spike that an administrator or developer can use to determine the cause of the spike. ProcDump also includes hung window monitoring (using the same definition of a window hang that Windows and Task Manager use), unhandled exception monitoring and can generate dumps based on the values of system performance counters. It also can serve as a general process dump utility that you can embed in other scripts.
ProcDump 是一个命令行实用程序,其主要目的是监视应用程序的 CPU 峰值并在峰值期间生成故障转储,管理员或开发人员可以使用它来确定峰值的原因。ProcDump 还包括挂起窗口监控(使用与 Windows 和任务管理器相同的窗口挂起定义)、未处理的异常监控并可以根据系统性能计数器的值生成转储。它还可以用作通用进程转储实用程序,您可以将其嵌入到其他脚本中。
回答by Kaarthikeyan
You can also try using a C#/Perl/Java script get the utilization data using WMI Commands, and below is the steps for it.
您也可以尝试使用 C#/Perl/Java 脚本使用 WMI 命令获取利用率数据,下面是它的步骤。
We need to execute 2 WMI Select Queries and apply CPU% utilization formula
我们需要执行 2 个 WMI Select Queries 并应用 CPU% 利用率公式
1. To retrieve the total number of logical process
1.检索逻辑进程总数
select NumberOfLogicalProcessors from Win32_ComputerSystem
2. To retrieve the values of PercentProcessorTime, TimeStamp_Sys100NS ( CPU utilization formula has be applied get the actual utilization percentage)and WorkingSetPrivate ( RAM ) minimum of 2 times with a sleep interval of 1 second
2. 要检索 PercentProcessorTime、TimeStamp_Sys100NS(已应用 CPU 利用率公式获得实际利用率百分比)和 WorkingSetPrivate ( RAM ) 的值,最少 2 次,睡眠间隔为 1 秒
select * from Win32_PerfRawData_PerfProc_Process where IDProcess=1234
3. Apply CPU% utilization formula
3. 应用 CPU% 利用率公式
CPU%= ((p2-p1)/(t2-t1)*100)/NumberOfLogicalProcessors
p2 indicated PercentProcessorTime retrieved for the second time, and p1 indicateds the PercentProcessorTime retrieved for the first time, t2 and t1 is for TimeStamp_Sys100NS.
p2表示第二次检索到的PercentProcessorTime,p1表示第一次检索到的PercentProcessorTime,t2和t1为TimeStamp_Sys100NS。
A sample Perl code for this can be found in the link http://www.craftedforeveryone.com/cpu-and-ram-utilization-of-an-application-using-perl-via-wmi/
可以在链接http://www.craftedforeveryone.com/cpu-and-ram-utilization-of-an-application-using-perl-via-wmi/ 中找到用于此的示例 Perl 代码
This logic applies for all programming language which supports WMI queries
此逻辑适用于所有支持 WMI 查询的编程语言
回答by Bryce
Under Windows 10, the Task Manager can show you cumulative CPU hours. Just head to the "App history" tab and "Delete usage history". Now leave things running for an hour or two:
在 Windows 10 下,任务管理器可以显示累积的 CPU 小时数。只需前往“应用历史记录”选项卡和“删除使用历史记录”即可。现在让事情运行一两个小时:
What this does NOT do is break down usage in browsers by tab. Quite often inactive tabs will do a tremendous amount of work, with each open tab using energy and slowing your PC.
这不会按选项卡分解浏览器中的使用情况。不活动的标签通常会做大量的工作,每个打开的标签都会消耗能量并降低你的电脑速度。