Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 787
Raviprakash Avatar asked Apr 03 '13 11:04

Raviprakash


People also ask

How do I find the PID of a process Mac?

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.

How can I tell what programs are using my hard drive Mac?

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.

What is disk activity monitor?

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.

What is Fs_usage?

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.


2 Answers

Use iotop (as root), for example:

iotop -C 3 10 

But the best way (for me) is:

sudo fs_usage -f filesys 
like image 188
slerena Avatar answered Sep 19 '22 00:09

slerena


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.

like image 42
dgross Avatar answered Sep 17 '22 00:09

dgross