Is there a command on Mac can show the disk IO input and output stats?

I can use vmstat on ubuntu linux to show IO input and output stats. Whether there is a build-in command in MacOS do the same output?

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 266800 1408168 25417796    0    0     3    76   35   46  1  1 98  0  0
 0  0      0 266708 1408168 25417796    0    0     0  1032 1693 4065  1  1 98  0  0
 0  0      0 267156 1408168 25417808    0    0     0     0 1819 4443  2  1 97  0  0
 0  0      0 266872 1408168 25417828    0    0     0    12 1298 3724  1  1 98  0  0

I can use iostat to check disk IO stats but it doesn't show input and output. It shows a total number of bytes on the disk.

I don't want to install 3rd party library to do that. Is there a command I can use on Mac?


Solution 1:

The closest thing to getting IO r/w info is iotop command, which comes with all Mac OS (see disk_r and disk_w).

$ sudo iotop
2019 Jul 15 22:39:17,  load: 1.19,  disk_r:      0 KB,  disk_w:    628 KB

  UID    PID   PPID CMD              DEVICE  MAJ MIN D            BYTES
    0      1      0 launchd          ??        1   2 W           643072
    0      0      0                  ??        1   2             649216

If you are running on Mac OSX 10.10 (El Capitan) or later, then you need to first disable the SIP (System Integration Protection) for dtrace in order to run iotop because iotop uses dtrace. For older OSX, you can ignore the following steps.

To disable SIP for dtrace (and iotop) for Mac OSX 10.10 and above:

  1. Turn on or Restart your Mac
  2. As the Mac is turning on, hold down Command-R to boot into Recovery Mode
  3. Open terminal and type csrutil disable (this is a temporary step)
  4. type csrutil enable --without dtrace. (It re-enables SIP except for dtrace)
  5. Reboot your Mac

Now you can run iotop and dtrace.

  • If you want to restore SIP to its original state, and to prevent dtrace from running, reboot into Recovery Mode and in terminal, type csrutil enable and reboot.