[英]Per Process disk read/write statistics in Mac OS X
How do I get programatically per process disk i/o statistics in Mac OS X. In 'Activity Monitor' application or in 'top' command we can only get whole system disk i/o statistics. 如何在Mac OS X中以编程方式获取每个进程磁盘的i / o统计信息。在“Activity Monitor”应用程序或“top”命令中,我们只能获得整个系统磁盘的i / o统计信息。
For reference Similar question asked for PC. 供参考类似的问题要求PC。
Use iotop
(as root), for example: 使用
iotop
(以root身份),例如:
iotop -C 3 10
But the best way (for me) is: 但最好的方法(对我来说)是:
sudo fs_usage -f filesys
Since there isn't an answer here about how to do this programatically, here's some more info. 由于这里没有关于如何以编程方式执行此操作的答案,因此这里有更多信息。 You can get some info out of libproc if you can use C/C++/ObjectiveC++.
如果可以使用C / C ++ / ObjectiveC ++,可以从libproc中获取一些信息。 The function
proc_pid_rusage
gives you a bunch of resource info for a given process, but the ones related to your question are: 函数
proc_pid_rusage
为您提供了一组给定流程的资源信息,但与您的问题相关的信息是:
struct rusage_info_v3 {
...
uint64_t ri_diskio_bytesread;
uint64_t ri_diskio_byteswritten;
...
};
Sample code: 示例代码:
pid_t pid = 10000;
rusage_info_current rusage;
if (proc_pid_rusage(pid, RUSAGE_INFO_CURRENT, (void **)&rusage) == 0)
{
cout << rusage.ri_diskio_bytesread << endl;
cout << rusage.ri_diskio_byteswritten << endl;
}
See <libproc.h>
and <sys/resource.h>
for more info. 有关详细信息,请参阅
<libproc.h>
和<sys/resource.h>
。
Since OP specifically asked for disk I/O statistics I'd recommend 由于OP专门要求我推荐的磁盘I / O统计数据
sudo fs_usage -f diskio
which focuses only on read/write events, contrary to -f filesys
as mentioned in the accepted answer. 它只关注读/写事件,与接受的答案中提到的
-f filesys
相反。 (Don't know if the diskio
option wasn't available back then.) (当时不知道
diskio
选项是否可用。)
I found iStat Menus , which sits in the menu bar. 我找到了iStat Menus ,它位于菜单栏中。 Only shows the top 5 disk read/write users (and I'm not sure if it's the sum, but it doesn't sort).
仅显示前5个磁盘读/写用户(我不确定它是否是总和,但它不排序)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.