如何从 C++ 使用 Windows API 获取应用程序的 CPU 使用率或磁盘使用率?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1058526/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:43:59  来源:igfitidea点击:

How to get CPU usage or disk usage of application using Windows API from C++?

c++windowscpudisk

提问by

How to proceed to get CPU usage or disk usage of application using API in C++???

如何使用 C++ 中的 API 继续获取应用程序的 CPU 使用率或磁盘使用率???

I want to get the highest CPU usage or disk usage among the application running on windows. I have tried to find out API but there is no direct API for that. Can anyone please let me know how to proceed for this in C++.

我想在 Windows 上运行的应用程序中获得最高的 CPU 使用率或磁盘使用率。我试图找出 API,但没有直接的 API。任何人都可以让我知道如何在 C++ 中进行此操作。

回答by Remus Rusanu

You look at the Process category performance counters to get per process CPU/Memory/IO or at respective categories (Processor, Memory, Physical/Logical Disk) counters for overall system performance. The values can be accessed via dedicated APIsor from WMI.

您可以查看进程类别性能计数器以获取每个进程的 CPU/内存/IO 或各个类别(处理器、内存、物理/逻辑磁盘)计数器的整体系统性能。可以通过专用 API或从WMI访问这些值。

回答by Ana Betts

Windows 7 already has this built-in, as part of the Resource Monitor (realmon.exe). If you want to find this in code, you can either use the Perf Counter API or create a Realtime ETW consumer against the NT kernel provider.

Windows 7 已经内置了这个,作为资源监视器 (realmon.exe) 的一部分。如果您想在代码中找到它,您可以使用 Perf Counter API 或针对 NT 内核提供程序创建一个实时 ETW 使用者。