本文介绍了在没有TaskMgr的情况下测量/测量CPU使用率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在长时间运行的过程中评估CPU利用率。我怀疑每次我运行任务管理器查看数据时,进程的CPU使用率都会下降,因为任务管理器具有更高的优先级。如果我将进程的实时性赋予优先级,则任务管理器将完全锁定,因此无法使用它。我希望我的大部分CPU周期都专用于此过程,并且我想大致了解它的利用率。我不需要一秒钟的监视器,只需要几个快照就可以知道发生了什么。我该如何完成呢?

I'm trying to gauge the CPU utilization level during a long-running process. I suspect that everytime I run task-manager to view the data, the process' CPU utilization goes down because taskmanager has a higher priority. If I give my process RealTime priority, then task manager completely locks up and I cannot use it. I want most of my CPU cycles dedicated to this process, and I want to get a rough idea of how much it is utilizing. I don't need a second-by-second monitor, but just a few snapshots that let me know what's going on. How can I accomplish this?

推荐答案

通过C API编程,您可以使用Performance Counter API。 (CPU使用率只是另一个计数器)。您可以使用。或者,您可以使用 (Performance Data Helper API)-可能正是您想要的。我过去曾经使用过PDH api,它很容易使用。

Programatically with a C API, you can use the Performance Counter API. (CPU usage is just another counter). You can use the low-level registry API to query the performance counter for data. Or you can use the PDH API (Performance Data Helper API) - which is probably what you want. I've used both in the past and the PDH api is easy to use.

另一个帮助您枚举可用计数器名称的工具是perfmon。 (只需运行c:\windows\system32\perfmon.exe)。它也是任务管理器的有用替代方法。它还记录日志和图形。而且,您可以在多进程计算机上为每个逻辑处理器设置计数器。

Another tool to help you enumerate the names of available counters is perfmon. (Just run c:\windows\system32\perfmon.exe). It is also a useful alternative to Task Manager. It also does logging and graphs. And you can setup counters for each logical processor on a multi-proc machine.

这篇关于在没有TaskMgr的情况下测量/测量CPU使用率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 19:26
查看更多