Per Process disk read/write statistics in Mac OS X

后端 未结 5 1688
我在风中等你
我在风中等你 2021-02-01 05:08

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 statist

5条回答
  •  误落风尘
    2021-02-01 05:46

    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 and for more info.

提交回复
热议问题