8

I want to count the number of disk accesses during a complete run of my script.

My bash script runs 2 other executable files locally and 2 other executable files remotely. Something like this (those executable files may access other tools themselves):

#!/bin/bash

./executable1 DATA1 & ./executable2 DATA2 &

ssh remote_host './executable3 DATA3' & ssh remote_host './executable4 DATA4' &

wait;

Now I'm running my bash script with perf like this:

perf stat -e page-faults,page-faults:u ./myBashScript.sh

but always results are the same, no matter if I change the DATA* files, the orders, the number of commands,… Something like this:

128,470 page-faults
127,641 page-faults:u

Now my question is "How can I count the number of those disk accesses for the whole script?"

p.s:

  • As you know Linux tries to reduce number of disk access by using free space of ram as a cache disk and here by "counting number of disk accesses" I exactly mean how many times OS needs to bring data from hard disk to main memory ( = RAM hit/miss)
  • I just need to count number of disk accesses on local machine not the remote one.
genpfault
  • 555
Dark
  • 183

1 Answers1

3

page-faults in perf tool from linux tools (perf_events) are for both minor and major page faults. And minor page faults are not for disk access. And not every major page fault is for disk access (only is disk file was mmaped). And disk accesses from read/write will not generate any page faults.

Some generic page fault counting solutions are in https://stackoverflow.com/questions/23302763.

To count disk accesses globally use iostat tool http://man7.org/linux/man-pages/man1/iostat.1.html (tps, r/s, w/s) or vmstat tool http://man7.org/linux/man-pages/man8/vmstat.8.html (bo, bi, -d). Both are used with period in seconds like iostat 1 or vmstat 1 to print one set of activity every seconds until killed by ctrl-c; or like iostat 1 60 or vmstat 1 60 to print every second for 1 minute and exit.

Other solution is to use combination of perf tool and some specific events from i/o or disk subsystems. Gregg has some examples of advanced perf usage at http://www.brendangregg.com/perf.html and https://github.com/brendangregg/perf-tools.

His iosnoop tool http://www.brendangregg.com/blog/2014-07-16/iosnoop-for-linux.html and http://www.brendangregg.com/blog/2014-07-23/linux-iosnoop-latency-heat-maps.html (based on perf) can trace disk i/o with process pid, disk id, offset and io size, and it will also measure latency of disk access.

Check also "7.2. Heat Maps" of http://www.brendangregg.com/perf.html

I used perf_events to record the block request (disk I/O) issue and completion static tracepoints:

 # perf record -e block:block_rq_issue -e block:block_rq_complete -a sleep 120
osgx
  • 7,017