跟踪每个进程的 CPU 和内存使用情况

发布于 2024-07-05 09:42:11 字数 245 浏览 11 评论 0原文

我怀疑我的一个应用程序占用的 CPU 周期比我想要的要多。 问题是 - 它突然发生,仅仅查看任务管理器对我没有帮助,因为它只显示立即使用情况。

有没有一种方法(在 Windows 上)可以跟踪 CPU 和 CPU 的历史记录? 某些进程的内存使用情况。 例如,我将开始跟踪“firefox”,大约一个小时后将看到其 CPU 和内存的图表。 该小时内的内存使用情况。

我正在寻找一个现成的工具或一种编程方式来实现这一目标。

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.

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.

I'm looking for either a ready-made tool or a programmatic way to achieve this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

不离久伴 2024-07-12 09:42:11

Win+R,输入 perfmon 并按 Enter。 打开“性能”窗口后,单击 + 符号将新计数器添加到图表中。 计数器是 PC 工作方式的不同方面,并根据相似性分为称为“性能对象”的组。

对于您的问题,您可以选择“进程”、“内存”和“处理器”性能对象。 然后,您可以实时查看这些计数器。

您还可以指定实用程序来保存性能数据以供稍后检查。 为此,请选择左侧面板中的“性能日志和警报”。 (它就在系统监视器控制台下方,它为我们提供了上述计数器。如果不存在,请单击“文件”>“添加/删除管理单元”,单击“添加”并在“性能日志和警报”中选择“性能日志和警报”。列表”。)从“性能日志和警报”中,在“计数器日志”下创建新的监控配置。然后您可以添加计数器、指定采样率、日志格式(二进制或纯文本)和日志位置。

Press Win+R, type perfmon 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".

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.

对你再特殊 2024-07-12 09:42:11

Process Explorer 可以显示进程占用的总 CPU 时间,以及每个进程的历史图。

Process Explorer can show total CPU time taken by a process, as well as a history graph per process.

追风人 2024-07-12 09:42:11

使用 perfmon.exe,我尝试使用“进程”计数器下的“私有字节”计数器来跟踪内存使用情况,效果很好。

Using perfmon.exe, I have tried using the "Private Bytes" counter under "Process" counters for tracking memory usage and it works well.

温折酒 2024-07-12 09:42:11

我使用 taskinfo 作为 CPU/RAM/IO 速度的历史图。
http://www.iarsn.com/taskinfo.html

但是阵阵无响应,听起来更严重例如由于 HD/SS 驱动器故障而导致的中断时间。

I use taskinfo for history graph of CPU/RAM/IO speed.
http://www.iarsn.com/taskinfo.html

But bursts of unresponsiveness, sounds more like interrupt time due to a falty HD/SS drive.

野稚 2024-07-12 09:42:11

在 Windows 10 下,任务管理器可以显示累积的 CPU 小时数。 只需前往“应用程序历史记录”选项卡和“删除使用历史记录”即可。 现在让程序运行一两个小时:

Windows 10 累积 CPU 时间

这不会按选项卡细分浏览器中的使用情况。 通常,不活动的选项卡会执行大量工作,每个打开的选项卡都会消耗能量并降低您的电脑速度。

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 Cumulative CPU time

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.

国产ˉ祖宗 2024-07-12 09:42:11

下载进程监视器

  1. 启动进程监视器

  2. 根据需要设置过滤器

  3. 进入菜单选项 > 分析事件

  4. 单击“生成线程分析事件”,选择频率,然后单击“确定”。

  5. 要随时查看采集的历史数据,进入菜单“工具>” 流程活动摘要

Download process monitor

  1. Start Process Monitor

  2. Set a filter if required

  3. Enter menu Options > Profiling Events

  4. Click "Generate thread prof‌iling events", choose the frequency, and click OK.

  5. To see the collected historical data at any time, enter menu Tools > Process Activity Summary

一身骄傲 2024-07-12 09:42:11

也许你可以用这个。 它应该适合您,并将报告指定进程的处理器时间。

@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.

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.
财迷小姐 2024-07-12 09:42:11

我同意,perfmon.exe 允许您为要监视的任何进程添加计数器(右键单击右侧面板)。

绩效对象:流程
选中“从列表中选择实例”并选择 Firefox。

I agree, perfmon.exe allows you to add counters (right click on the right panel) for any process you want to monitor.

Performance Object: Process
Check "Select instances from list" and select firefox.

清泪尽 2024-07-12 09:42:11

WMI 是 Windows Management Instrumentation,它内置于所有最新版本的 Windows 中。 它允许您以编程方式跟踪 CPU 使用情况、磁盘 I/O 和内存使用情况等。

Perfmon.exe 是该界面的 GUI 前端,可以监视进程、将信息写入日志,并允许您在事后分析日志。 它不是世界上最优雅的程序,但它确实可以完成工作。

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.

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.

木森分化 2024-07-12 09:42:11

Process Lasso 的设计更多是为了流程自动化和优先级优化,而不是图形。 也就是说,它确实提供每个进程的CPU利用率历史记录(在图表上绘制为白线),但它提供每个进程的内存利用率历史记录。

免责声明:我是 Process Lasso 的作者,但实际上并不在这里认可它 - 因为有更好的解决方案(perfmon 是最好的)。

有史以来最好的东西是 Windows Vista+ 资源和性能监视器。 它可以跟踪一段时间内进程对 CPU、内存、网络和磁盘访问的使用情况。 它是一个很棒的整体系统信息实用程序,早就应该创建了。 除非我弄错了,否则它可以跟踪一段时间内每个进程的 CPU 和内存利用率(以及列出的其他内容)。

Process Lasso is designed more for process automation and priority class optimization, not graphs. That said, it does offer per-process CPU utilization history (drawn as a white line on the graph) but it does NOT offer per-process memory utilization history.

DISCLAIMER: I am the author of Process Lasso, but am not actually endorsing it here - as there are better solutions (perfmon being the best).

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).

层林尽染 2024-07-12 09:42:11

您还可以尝试使用 C#/Perl/Java 脚本使用 WMI 命令获取利用率数据,以下是其步骤。

我们需要执行 2 个 WMI 选择查询并应用 CPU% 利用率公式

1。 检索逻辑进程总数

select NumberOfLogicalProcessors from Win32_ComputerSystem

2。 要检索 PercentProcessorTime、TimeStamp_Sys100NS(已应用 CPU 利用率公式获取实际利用率百分比)和 WorkSetPrivate (RAM) 的值,至少 2 次,睡眠间隔为 1 秒

select * from Win32_PerfRawData_PerfProc_Process where IDProcess=1234

3。 应用CPU%利用率公式

CPU%= ((p2-p1)/(t2-t1)*100)/NumberOfLogicalProcessors

p2表示第二次检索的PercentProcessorTime,p1表示第一次检索的PercentProcessorTime,t2和t1针对TimeStamp_Sys100NS。

可以在链接 http://www.craftedforeveryone.com/cpu-and-ram-utilization-of-an-application-using-perl-via-wmi/

此逻辑适用于所有编程语言支持WMI查询

You can also try using a C#/Perl/Java script get the utilization data using WMI Commands, and below is the steps for it.

We need to execute 2 WMI Select Queries and apply CPU% utilization formula

1. To retrieve the total number of logical process

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

select * from Win32_PerfRawData_PerfProc_Process where IDProcess=1234

3. Apply CPU% utilization formula

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.

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/

This logic applies for all programming language which supports WMI queries

恏ㄋ傷疤忘ㄋ疼 2024-07-12 09:42:11

虽然我还没有尝试过这个, ProcDump 似乎是一个更好的解决方案。

网站描述:

ProcDump 是一个命令行实用程序,其主要目的是监视应用程序的 CPU 峰值并在峰值期间生成故障转储,管理员或开发人员可以使用它来确定峰值的原因。 ProcDump 还包括挂起窗口监视(使用与 Windows 和任务管理器使用的窗口挂起相同的定义)、未处理的异常监视,并且可以根据系统性能计数器的值生成转储。 它还可以用作通用进程转储实用程序,您可以将其嵌入其他脚本中。

Although I have not tried this out, ProcDump seems like a better solution.

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.

浅忆 2024-07-12 09:42:11

需要获取某些特定 Windows 服务器的状态和 CPU/内存使用情况。 我使用了以下脚本:

这是 Windows 搜索服务的示例。

  $cpu = Get-WmiObject win32_processor
  $search = get-service "WSearch"
  if ($search.Status -eq 'Running')
  {
  $searchmem = Get-WmiObject Win32_Service -Filter "Name = 'WSearch'"
  $searchid = $searchmem.ProcessID
  $searchcpu1 = Get-WmiObject Win32_PerfRawData_PerfProc_Process | Where {$_.IDProcess -eq $searchid}
  Start-Sleep -Seconds 1
  $searchcpu2 = Get-WmiObject Win32_PerfRawData_PerfProc_Process | Where {$_.IDProcess -eq $searchid}
  $searchp2p1 = $searchcpu2.PercentProcessorTime - $searchcpu1.PercentProcessorTime
  $searcht2t1 = $searchcpu2.Timestamp_Sys100NS - $searchcpu1.Timestamp_Sys100NS
  $searchcpu = [Math]::Round(($searchp2p1 / $searcht2t1 * 100) /$cpu.NumberOfLogicalProcessors, 1)
  $searchmem = [Math]::Round($searchcpu1.WorkingSetPrivate / 1mb,1)
  Write-Host 'Service is' $search.Status', Memory consumed: '$searchmem' MB, CPU Usage: '$searchcpu' %'
  }

  else
  {
  Write-Host Service is $search.Status -BackgroundColor Red
  }

There was a requirement to get status and cpu / memory usage of some specific windows servers. I used below script:

This is an example of Windows Search Service.

  $cpu = Get-WmiObject win32_processor
  $search = get-service "WSearch"
  if ($search.Status -eq 'Running')
  {
  $searchmem = Get-WmiObject Win32_Service -Filter "Name = 'WSearch'"
  $searchid = $searchmem.ProcessID
  $searchcpu1 = Get-WmiObject Win32_PerfRawData_PerfProc_Process | Where {$_.IDProcess -eq $searchid}
  Start-Sleep -Seconds 1
  $searchcpu2 = Get-WmiObject Win32_PerfRawData_PerfProc_Process | Where {$_.IDProcess -eq $searchid}
  $searchp2p1 = $searchcpu2.PercentProcessorTime - $searchcpu1.PercentProcessorTime
  $searcht2t1 = $searchcpu2.Timestamp_Sys100NS - $searchcpu1.Timestamp_Sys100NS
  $searchcpu = [Math]::Round(($searchp2p1 / $searcht2t1 * 100) /$cpu.NumberOfLogicalProcessors, 1)
  $searchmem = [Math]::Round($searchcpu1.WorkingSetPrivate / 1mb,1)
  Write-Host 'Service is' $search.Status', Memory consumed: '$searchmem' MB, CPU Usage: '$searchcpu' %'
  }

  else
  {
  Write-Host Service is $search.Status -BackgroundColor Red
  }
不回头走下去 2024-07-12 09:42:11

嗯,我看到 Process Explorer 可以做到这一点,尽管它的图表都不太方便。 仍在寻找替代/更好的方法来做到这一点。

Hmm, I see that Process Explorer can do it, although its graphs are not too convenient. Still looking for alternative / better ways to do it.

千寻… 2024-07-12 09:42:11

Perfmon.exe 内置于 Windows 中。

Perfmon.exe is built into windows.

你的呼吸 2024-07-12 09:42:11

您可能想看看Process Lasso

You might want to have a look at Process Lasso.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文