跟踪/计算进程的CPU和IO使用的标准方法 [英] Standard way of Tracking/Calculating CPU and IO usage of process

查看:112
本文介绍了跟踪/计算进程的CPU和IO使用的标准方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找计算运行流程的CPU和I / O使用的标准方法。我正在研究以下选项。

I have been looking for standard way of calculating CPU and I/O usage of running a process. I was looking into following options.

运行Windows程序并检测它何时以C ++结尾

此代码如何计算经过的CPU周期数?

http://www.codeproject .com / KB / threads / Get_CPU_Usage.aspx

我无法让最后一个工作。我需要这些数字。

I am not able to get the last one working. I need these figures.

usr = userTime - last_userTime;
ker = kernelTime - last_kernelTime;
idl = idleTime - last_idleTime;

我主要寻找基于Windows GCC的解决方案。我正在使用Dev C ++ 4来测试这些。我也对unix(solaris / Linux with GCC)上的类似解决方案感兴趣。

I am primarily looking for Windows GCC based solutions. I am using Dev C++ 4 for testing these. I am also interested in similar solution on unix (solaris/Linux with GCC).

还有一种获取cpu的方法,当进程是处于运行状态(如图中的跟踪)以及限制进程的CPU使用率。
注意:我不是在寻找工具。我正在寻找标准的C代码。
如果你想分享其他语言如C ++,Python的任何标准,欢迎你。

Also is there a way for getting cpu, io used by a process when the process is in running state (Like tracking in a graph) along with limiting CPU usage of a process. Note: I am not looking for tools. I am looking for standard C code. If you want to share any standards from other languages like C++, Python you are welcome.

推荐答案

标准方式将使用Windows的性能计数器。它们有原始和熟形式,可以通过至少三种不同的方式访问:

The standard way would be to use Windows' performance counters. These come in both "raw" and "cooked" forms, and can be accessed in at least three different ways:


  1. direct:a special Windows中的密钥注册表

  2. Performance Data Helper( PDH )组件

  3. WMI

  1. direct: a special key in the Windows registry
  2. Performance Data Helper (PDH) component
  3. WMI

我应警告你,所有这些都有相当陡峭的初始学习曲线。一旦你已经达到可以合理地收集和使用来自一个柜台的数据的程度,那么通常很容易添加更多。

I should warn you that all of these have a fairly steep initial learning curve. Once you've gotten to the point that you can collect and use data from one counter reasonably well, adding more is usually pretty easy though.

在你的问题中,你也是提到一种完全不同的方式来收集CPU使用率数据。这里的想法是使用 GetProcessTimes 定期。例如,在启动子进程后,您可以设置一个计时器并每秒调用一次以获得子进程的持续CPU使用率。

In your question, you also mention a completely different way to collect CPU usage data. The idea here is to use GetProcessTimes on a regular basis. For example, after starting up the child process, you can set a timer and call it once a second to get the ongoing CPU usage of the child process.

如果你'要以这种方式获得CPU使用率,你可能想要使用 GetProcessMemoryInfo 以几乎相同的方式收集内存使用情况统计信息。

If you're going to get CPU usage that way, you'd probably want to use GetProcessMemoryInfo to collect memory usage statistics in pretty much the same way.

但是,对于I / O统计数据,我不太了解性能计数器的真正替代方法。

For I/O statistics, however, I don't know of much in the way of real alternatives to the performance counters.

这篇关于跟踪/计算进程的CPU和IO使用的标准方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆