在 Windows 上以编程方式获取每个进程的磁盘 io 统计信息?

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

Programmatically getting per-process disk io statistics on Windows?

c++windowsperformancedisk

提问by dutchmega

I would like to display a list of processes (Windows, C++) and how much they are reading and writing from the disk in KB/sec.

我想显示进程列表(Windows、C++)以及它们以 KB/sec 为单位从磁盘读取和写入的数量。

The Resource Monitor of Windows 7 has the ability so I should be able to do the same.

Windows 7 的资源监视器有能力,所以我应该也能做到。

However I have unable to find a relevant API-call or find anything in the perfmon counters. Could anyone point me in the direction?

但是,我无法找到相关的 API 调用或在性能计数器中找到任何内容。谁能指出我的方向?

回答by Michael

You can call GetProcessIoCountersto get overall disk I/O data per process - you'll need to keep track of deltas and converting to time-based rate yourself.

您可以调用GetProcessIoCounters来获取每个进程的整体磁盘 I/O 数据 - 您需要跟踪增量并自己转换为基于时间的速率。

This API will tell you total number of I/O operations as well as total bytes.

这个 API 会告诉你 I/O 操作的总数以及总字节数。

回答by Alex Martelli

WMIcan do it, as long as you periodically snapshot it to get differential stats for some "recent" slice of time. This postpresents a peculiarly mixed solution, with VBScriptreading the info from WMI and Perlcontinually presenting the information in a Windows console. Despite the strange language mix, I think it stands as a good example of how to get at the kind of information you require (it should be quite possible to recode all of it in C++, of course).

WMI可以做到这一点,只要您定期对其进行快照以获取某些“最近”时间段的差异统计信息。 这篇文章提出了一种特殊的混合解决方案,VBScript从 WMI 读取信息,Perl不断在 Windows 控制台中显示信息。尽管有奇怪的语言组合,但我认为它是如何获取所需信息的一个很好的例子(当然,应该很可能用 C++ 重新编码所有这些信息)。