测量由我的程序引起的设备驱动程序 CPU/IO 利用率

发布于 2024-10-11 02:08:55 字数 213 浏览 8 评论 0原文

有时,代码可能会利用设备驱动程序,导致系统无响应。

最近我优化了一个WIN32/VC++代码,导致系统几乎没有响应。然而,CPU 使用率非常低。原因是 GDI 对象(钢笔、画笔等)的数千次创建和销毁。一旦我重构代码以仅创建一次所有对象,系统就会再次响应。

这引出了我的问题:是否有一种方法可以测量给定程序/函数/代码行的设备驱动程序(GPU/磁盘/等)的 CPU/IO 使用情况?

Sometimes code can utilize device drivers up to the point where the system is unresponsive.

Lately I've optimized a WIN32/VC++ code which made the system almost unresponsive. The CPU usage, however, was very low. The reason was 1000's of creations and destruction of GDI objects (pens, brushes, etc.). Once I refactored the code to create all objects only once - the system became responsive again.

This leads me to the question: Is there a way to measure CPU/IO usage of device drivers (GPU/disk/etc) for a given program / function / line of code?

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

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

发布评论

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

评论(3

ˇ宁静的妩媚 2024-10-18 02:08:55

您可以使用 SysInternals Utilities 中的各种工具(现已成为 Microsoft 产品,请参阅 http://technet. microsoft.com/en-us/sysinternals/bb545027),在开始之前给出一个基本概念。在您的情况下,进程资源管理器(procexp)和进程监视器(procmon)表现得不错。在进行分析深入分析之前,它们可以让您对缓慢类型有一个基本的了解。

然后您可以使用 xperf http://msdn.microsoft.com/en-us/performance/默认向下钻取。通过正确的设置,该工具可以让您找到导致速度缓慢的确切函数,而无需将分析代码注入到现有程序中。已经有一个 PDC 视频讨论了如何使用它 http://www.microsoftpdc.com/2009/CL16< /a> 我强烈推荐这个工具。根据我自己的经验,最好先使用 procexp/procmon 进行观察,然后使用 xperf 来瞄准您的嫌疑人,因为如果不以智能方式过滤,xperf 可能会生成大量信息。

在某些涉及锁定争用的困难情况下,Windows 调试工具(windbg)将非常方便,并且有专门的书籍讨论其用法。这些书通常讨论挂起检测,这里有很多技术也可用于检测缓慢情况。 (例如!逃跑)

You can use various tools from SysInternals Utilities (now a Microsoft product, see http://technet.microsoft.com/en-us/sysinternals/bb545027) to give a basic idea before jumping in. In your case process explorer (procexp) and process monitor (procmon) performs a decent job. They can be used to get you a basic idea about what type of slowness it is before doing profiling drill down.

Then you can use xperf http://msdn.microsoft.com/en-us/performance/default to drill down. With correct setup, this tool can bring you to the exact function that causes slowness without injecting profiling code into your existing program. There's already a PDC video talking about how to use it http://www.microsoftpdc.com/2009/CL16 and I highly recommend this tool. Per my own experience, it's always better to observe using procexp/procmon first, then targeting your suspects with xperf, because xperf can generate overwhelming load of information if not filtered in a smart way.

In certain hard cases that involving locking contentions, Debugging Tools for Windows (windbg) will be very handy, and there are dedicated books talking about its usage. These books typically talk about hang detection and there are quite a few techniques here can be used to detect slowness, too. (e.g. !runaway)

最后的乘客 2024-10-18 02:08:55

也许您可以使用 ETW 来实现此目的?不太确定它会帮助您了解哪条线导致了什么,但它应该可以让您对应用程序的运行情况有一个良好的整体了解。

Maybe you could use ETW for this? Not so sure it will help you see what line causes what, but it should give you a good overall picture of how your app is doing.

擦肩而过的背影 2024-10-18 02:08:55

要实时查找程序的CPU/内存/磁盘使用情况,可以使用windows自带的资源监视器和任务管理器程序。您可以通过打印系统时间来找到一段代码相对于其他代码块所花费的时间。请记住不要一次进行太多监控,因为这可能会影响您的计算。

如果您知道程序占用了多少 CPU 时间以及代码块占用了多少时间,那么您就可以大致估算出代码块占用了多少 CPU 时间。

To find the CPU/memory/disk usage of the program in real time, you can use the resource monitor and task manager programs that come with windows. You can find the amount of time that a block of code takes relative to the other blocks of code by printing out the systime. Remember not to do too much monitoring at once, because that can throw off your calculations.

If you know how much CPU time that the program takes and what percentage of time the block of code takes, then you can estimate approximately how much CPU time that a block of code takes.

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