Per Process disk read/write statistics in Mac OS X

萝らか妹 提交于 2019-12-20 09:23:25

问题


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.
For reference Similar question asked for PC.


回答1:


Use iotop (as root), for example:

iotop -C 3 10

But the best way (for me) is:

sudo fs_usage -f filesys



回答2:


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++. The function proc_pid_rusage gives you a bunch of resource info for a given process, but the ones related to your question are:

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.




回答3:


Activity Monitor shows per process I/O statistics in the "disk" tab (perhaps its new since this question was asked). See "Bytes Written" and "Bytes Read" columns.




回答4:


Since OP specifically asked for disk I/O statistics I'd recommend

sudo fs_usage -f diskio

which focuses only on read/write events, contrary to -f filesys as mentioned in the accepted answer. (Don't know if the diskio option wasn't available back then.)




回答5:


I found iStat Menus, which sits in the menu bar. Only shows the top 5 disk read/write users (and I'm not sure if it's the sum, but it doesn't sort).



来源:https://stackoverflow.com/questions/15786618/per-process-disk-read-write-statistics-in-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!