1*387f9dfdSAndroid Build Coastguard WorkerDemonstrations of fileslower, the Linux eBPF/bcc version. 2*387f9dfdSAndroid Build Coastguard Worker 3*387f9dfdSAndroid Build Coastguard Worker 4*387f9dfdSAndroid Build Coastguard Workerfileslower shows file-based synchronous reads and writes slower than a 5*387f9dfdSAndroid Build Coastguard Workerthreshold. For example: 6*387f9dfdSAndroid Build Coastguard Worker 7*387f9dfdSAndroid Build Coastguard Worker# ./fileslower 8*387f9dfdSAndroid Build Coastguard WorkerTracing sync read/writes slower than 10 ms 9*387f9dfdSAndroid Build Coastguard WorkerTIME(s) COMM PID D BYTES LAT(ms) FILENAME 10*387f9dfdSAndroid Build Coastguard Worker0.000 randread.pl 4762 R 8192 12.70 data1 11*387f9dfdSAndroid Build Coastguard Worker8.850 randread.pl 4762 R 8192 11.26 data1 12*387f9dfdSAndroid Build Coastguard Worker12.852 randread.pl 4762 R 8192 10.43 data1 13*387f9dfdSAndroid Build Coastguard Worker 14*387f9dfdSAndroid Build Coastguard WorkerThis showed a few reads from a "randread.pl" program, each 8 Kbytes in size, 15*387f9dfdSAndroid Build Coastguard Workerand from a "data1" file. These all had over 10 ms latency. 16*387f9dfdSAndroid Build Coastguard Worker 17*387f9dfdSAndroid Build Coastguard WorkerThis "latency" is measured from when the read or write was issued at the VFS 18*387f9dfdSAndroid Build Coastguard Workerinterface, to when it completed. This spans everything: block device I/O (disk 19*387f9dfdSAndroid Build Coastguard WorkerI/O), file system CPU cycles, file system locks, run queue latency, etc. This 20*387f9dfdSAndroid Build Coastguard Workeris a better measure of the latency suffered by applications reading from the 21*387f9dfdSAndroid Build Coastguard Workerfile system than measuring this down at the block device interface. 22*387f9dfdSAndroid Build Coastguard Worker 23*387f9dfdSAndroid Build Coastguard WorkerNote that this only traces file reads and writes: other file system operations 24*387f9dfdSAndroid Build Coastguard Worker(eg, directory operations, open(), fflush()) are not traced. 25*387f9dfdSAndroid Build Coastguard Worker 26*387f9dfdSAndroid Build Coastguard Worker 27*387f9dfdSAndroid Build Coastguard WorkerThe threshold can be provided as an argument. Eg, I/O slower than 1 ms: 28*387f9dfdSAndroid Build Coastguard Worker 29*387f9dfdSAndroid Build Coastguard Worker# ./fileslower 1 30*387f9dfdSAndroid Build Coastguard WorkerTracing sync read/writes slower than 1 ms 31*387f9dfdSAndroid Build Coastguard WorkerTIME(s) COMM PID D BYTES LAT(ms) FILENAME 32*387f9dfdSAndroid Build Coastguard Worker0.000 randread.pl 6925 R 8192 1.06 data1 33*387f9dfdSAndroid Build Coastguard Worker0.082 randread.pl 6925 R 8192 2.42 data1 34*387f9dfdSAndroid Build Coastguard Worker0.116 randread.pl 6925 R 8192 1.78 data1 35*387f9dfdSAndroid Build Coastguard Worker0.153 randread.pl 6925 R 8192 2.31 data1 36*387f9dfdSAndroid Build Coastguard Worker0.330 randread.pl 6925 R 8192 1.14 data1 37*387f9dfdSAndroid Build Coastguard Worker0.345 randread.pl 6925 R 8192 1.52 data1 38*387f9dfdSAndroid Build Coastguard Worker0.359 randread.pl 6925 R 8192 1.04 data1 39*387f9dfdSAndroid Build Coastguard Worker0.532 randread.pl 6925 R 8192 2.56 data1 40*387f9dfdSAndroid Build Coastguard Worker0.609 supervise 1892 W 18 3.65 status.new 41*387f9dfdSAndroid Build Coastguard Worker0.610 randread.pl 6925 R 8192 1.37 data1 42*387f9dfdSAndroid Build Coastguard Worker0.614 randread.pl 6925 R 8192 3.04 data1 43*387f9dfdSAndroid Build Coastguard Worker0.729 randread.pl 6925 R 8192 2.90 data1 44*387f9dfdSAndroid Build Coastguard Worker0.755 randread.pl 6925 R 8192 1.12 data1 45*387f9dfdSAndroid Build Coastguard Worker0.762 randread.pl 6925 R 8192 2.62 data1 46*387f9dfdSAndroid Build Coastguard Worker0.771 randread.pl 6925 R 8192 1.07 data1 47*387f9dfdSAndroid Build Coastguard Worker0.816 randread.pl 6925 R 8192 10.50 data1 48*387f9dfdSAndroid Build Coastguard Worker0.983 randread.pl 6925 R 8192 1.73 data1 49*387f9dfdSAndroid Build Coastguard Worker0.989 randread.pl 6925 R 8192 2.12 data1 50*387f9dfdSAndroid Build Coastguard Worker0.992 randread.pl 6925 R 8192 2.17 data1 51*387f9dfdSAndroid Build Coastguard Worker1.001 randread.pl 6925 R 8192 1.93 data1 52*387f9dfdSAndroid Build Coastguard Worker1.007 randread.pl 6925 R 8192 2.03 data1 53*387f9dfdSAndroid Build Coastguard Worker1.210 randread.pl 6925 R 8192 1.82 data1 54*387f9dfdSAndroid Build Coastguard Worker1.213 randread.pl 6925 R 8192 2.58 data1 55*387f9dfdSAndroid Build Coastguard Worker1.219 randread.pl 6925 R 8192 2.20 data1 56*387f9dfdSAndroid Build Coastguard Worker1.430 randread.pl 6925 R 8192 1.01 data1 57*387f9dfdSAndroid Build Coastguard Worker1.448 randread.pl 6925 R 8192 2.22 data1 58*387f9dfdSAndroid Build Coastguard Worker[...] 59*387f9dfdSAndroid Build Coastguard Worker 60*387f9dfdSAndroid Build Coastguard WorkerThere's now much more output (this spans only 1.4 seconds, the previous output 61*387f9dfdSAndroid Build Coastguard Workerspanned 12 seconds), and the lower threshold is catching more I/O. 62*387f9dfdSAndroid Build Coastguard Worker 63*387f9dfdSAndroid Build Coastguard Worker 64*387f9dfdSAndroid Build Coastguard WorkerIn the following example, the file system caches were dropped before running 65*387f9dfdSAndroid Build Coastguard Workerfileslower, and then in another session a "man ls" was executed. The command 66*387f9dfdSAndroid Build Coastguard Workerand files read from disk can be seen: 67*387f9dfdSAndroid Build Coastguard Worker 68*387f9dfdSAndroid Build Coastguard Worker# echo 3 > /proc/sys/vm/drop_caches; ./fileslower 1 69*387f9dfdSAndroid Build Coastguard WorkerTracing sync read/writes slower than 1 ms 70*387f9dfdSAndroid Build Coastguard WorkerTIME(s) COMM PID D BYTES LAT(ms) FILENAME 71*387f9dfdSAndroid Build Coastguard Worker0.000 bash 9647 R 128 5.83 man 72*387f9dfdSAndroid Build Coastguard Worker0.050 man 9647 R 832 19.52 libmandb-2.6.7.1.so 73*387f9dfdSAndroid Build Coastguard Worker0.066 man 9647 R 832 15.79 libman-2.6.7.1.so 74*387f9dfdSAndroid Build Coastguard Worker0.123 man 9647 R 832 56.36 libpipeline.so.1.3.0 75*387f9dfdSAndroid Build Coastguard Worker0.135 man 9647 R 832 9.79 libgdbm.so.3.0.0 76*387f9dfdSAndroid Build Coastguard Worker0.323 man 9647 R 4096 59.52 locale.alias 77*387f9dfdSAndroid Build Coastguard Worker0.540 man 9648 R 8192 11.11 ls.1.gz 78*387f9dfdSAndroid Build Coastguard Worker0.558 man 9647 R 72 6.97 index.db 79*387f9dfdSAndroid Build Coastguard Worker0.563 man 9647 R 4096 5.12 index.db 80*387f9dfdSAndroid Build Coastguard Worker0.723 man 9658 R 128 12.06 less 81*387f9dfdSAndroid Build Coastguard Worker0.725 man 9656 R 128 14.52 nroff 82*387f9dfdSAndroid Build Coastguard Worker0.779 man 9655 R 128 68.86 tbl 83*387f9dfdSAndroid Build Coastguard Worker0.814 nroff 9660 R 128 14.55 locale 84*387f9dfdSAndroid Build Coastguard Worker0.830 pager 9658 R 4096 28.27 .lesshst 85*387f9dfdSAndroid Build Coastguard Worker0.866 man 9654 R 128 163.12 preconv 86*387f9dfdSAndroid Build Coastguard Worker0.980 nroff 9684 R 128 13.80 groff 87*387f9dfdSAndroid Build Coastguard Worker0.999 groff 9684 R 4096 14.29 DESC 88*387f9dfdSAndroid Build Coastguard Worker1.036 groff 9685 R 128 5.94 troff 89*387f9dfdSAndroid Build Coastguard Worker1.038 groff 9686 R 128 7.76 grotty 90*387f9dfdSAndroid Build Coastguard Worker1.065 troff 9685 R 4096 6.33 R 91*387f9dfdSAndroid Build Coastguard Worker1.082 troff 9685 R 4096 10.52 BI 92*387f9dfdSAndroid Build Coastguard Worker1.096 troff 9685 R 4096 8.70 troffrc 93*387f9dfdSAndroid Build Coastguard Worker1.176 troff 9685 R 4096 80.12 composite.tmac 94*387f9dfdSAndroid Build Coastguard Worker1.195 troff 9685 R 4096 19.20 fallbacks.tmac 95*387f9dfdSAndroid Build Coastguard Worker1.202 troff 9685 R 4096 6.79 tty.tmac 96*387f9dfdSAndroid Build Coastguard Worker1.221 troff 9685 R 4096 7.87 man.local 97*387f9dfdSAndroid Build Coastguard Worker2.977 supervise 1876 W 18 4.23 status.new 98*387f9dfdSAndroid Build Coastguard Worker 99*387f9dfdSAndroid Build Coastguard WorkerThis caught an individual I/O reaching 163.12 ms, for the "preconv" file. While 100*387f9dfdSAndroid Build Coastguard Workerthe file system cache was flushed, causing these to need to be read from disk, 101*387f9dfdSAndroid Build Coastguard Workerthe duration here may not be entirely disk I/O: it can include file system 102*387f9dfdSAndroid Build Coastguard Workerlocks, run queue latency, etc. These can be explored using other commands. 103*387f9dfdSAndroid Build Coastguard Worker 104*387f9dfdSAndroid Build Coastguard Worker 105*387f9dfdSAndroid Build Coastguard WorkerUSAGE message: 106*387f9dfdSAndroid Build Coastguard Worker 107*387f9dfdSAndroid Build Coastguard Worker# ./fileslower -h 108*387f9dfdSAndroid Build Coastguard Workerusage: fileslower.py [-h] [-p PID] [-a] [min_ms] 109*387f9dfdSAndroid Build Coastguard Worker 110*387f9dfdSAndroid Build Coastguard WorkerTrace slow synchronous file reads and writes 111*387f9dfdSAndroid Build Coastguard Worker 112*387f9dfdSAndroid Build Coastguard Workerpositional arguments: 113*387f9dfdSAndroid Build Coastguard Worker min_ms minimum I/O duration to trace, in ms (default 10) 114*387f9dfdSAndroid Build Coastguard Worker 115*387f9dfdSAndroid Build Coastguard Workeroptional arguments: 116*387f9dfdSAndroid Build Coastguard Worker -h, --help show this help message and exit 117*387f9dfdSAndroid Build Coastguard Worker -p PID, --pid PID trace this PID only 118*387f9dfdSAndroid Build Coastguard Worker -a, --all-files include non-regular file types 119*387f9dfdSAndroid Build Coastguard Worker 120*387f9dfdSAndroid Build Coastguard Workerexamples: 121*387f9dfdSAndroid Build Coastguard Worker ./fileslower # trace sync file I/O slower than 10 ms (default) 122*387f9dfdSAndroid Build Coastguard Worker ./fileslower 1 # trace sync file I/O slower than 1 ms 123*387f9dfdSAndroid Build Coastguard Worker ./fileslower -p 185 # trace PID 185 only 124