使用 C++ 获取系统硬盘使用情况
我想知道在非托管 C++ 代码中这是否可能?
我正在编写一个程序来显示系统上当前的 CPU 使用率,但我观察到,在一些较新的台式机上,当正在进行一些长时间的硬盘驱动器操作时(例如,来自后台备份过程),CPU 使用率保持非常低(低于10%)但系统使用起来有点慢。所以我想在我的程序中添加系统范围内当前 HDD 使用情况,我只是不确定要使用什么 API。
I was wondering if such is possible in the unmanaged C++ code?
I'm writing a program that shows the current CPU usage on the system, but I observed that on some newer desktops when some lengthy hard drive operation is in process (say, like from a background backup process) the CPU usage stays very low (less than 10%) but the system is somewhat slow to use. So I was thinking to add to my program the current HDD usage on a system-wide scale, I'm just not sure what API to use for that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找“% Disk Time”性能计数器。这表示磁盘忙于处理请求的(平均)时间比例。如果接近 100%,则 CPU 可能会长时间等待 I/O 完成。
另一个选项是“当前磁盘队列长度”。这表明有多少请求处于待处理状态,这反过来又是对超额操作(已发出的操作 - 已完成的操作)的度量。如果队列中的挂起操作为零,则 CPU 不会等待磁盘;如果有很多,那么CPU就没有任何作用。
当然,如果存在低优先级 CPU 循环线程,那么当高优先级线程等待 I/O 时,这些线程仍将运行。 Windows 不会因为磁盘繁忙而浪费 CPU 时间。
You're looking for the "% Disk Time" performance counter. That indicates the (averaged) fraction of time that the disk is busy servicing requests. If it's close to 100%, then the CPU will probably be waiting a lot for I/O's to complete.
Another option is the "Current Disk Queue Length". That indicates how many requests are pending, which in turn is a measure of the excess operations (operations issued - operations completed). If there are zero pending operations in the queue, the CPU is not waiting for the disk; if there are tons, then the CPU has nothing to do.
Of course, if there are low-priority CPU-cound threads, then those will still run while the higher-priority threads are waiting for I/O. Windows won't waste CPU time just because the disk is busy.