简体   繁体   English

Mac OS X中的每个进程磁盘读/写统计信息

[英]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>

Activity Monitor shows per process I/O statistics in the "disk" tab (perhaps its new since this question was asked). 活动监视器在“磁盘”选项卡中显示每个进程的I / O统计信息(可能是自提出此问题以来的新信息)。 在此输入图像描述 See "Bytes Written" and "Bytes Read" columns. 请参见“字节写入”和“字节读取”列。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM