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.
Run the command lsof -i : (make sure to insert your port number) to find out what is running on this port. Copy the Process ID (PID) from the Terminal output.
In some cases, a warning message may identify the app that is using the disk. You can also press and hold the Command key and press Tab to see which apps are open and switch to a different app.
The disk activity chart allows one to display the monitoring data for the last minute, last 2 minutes or last 5 minutes. The disk space usage gauges, which are located on the top-side of the window, provide the ability to display the current value, average value or the maximum value.
The fs_usage utility presents an ongoing display of system call usage information pertaining to filesystem activity. It requires root privi- leges due to the kernel tracing facility it uses to operate.
Use iotop
(as root), for example:
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++. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With