1Demonstrations of dcstat, the Linux eBPF/bcc version. 2 3 4dcstat shows directory entry cache (dcache) statistics. For example: 5 6# ./dcstat 7TIME REFS/s SLOW/s MISS/s HIT% 808:11:47: 2059 141 97 95.29 908:11:48: 79974 151 106 99.87 1008:11:49: 192874 146 102 99.95 1108:11:50: 2051 144 100 95.12 1208:11:51: 73373 17239 17194 76.57 1308:11:52: 54685 25431 25387 53.58 1408:11:53: 18127 8182 8137 55.12 1508:11:54: 22517 10345 10301 54.25 1608:11:55: 7524 2881 2836 62.31 1708:11:56: 2067 141 97 95.31 1808:11:57: 2115 145 101 95.22 19 20The output shows the total references per second ("REFS/s"), the number that 21took a slower code path to be processed ("SLOW/s"), the number of dcache misses 22("MISS/s"), and the hit ratio as a percentage. By default, an interval of 1 23second is used. 24 25At 08:11:49, there were 192 thousand references, which almost entirely hit 26from the dcache, with a hit ration of 99.95%. A little later, starting at 2708:11:51, a workload began that walked many uncached files, reducing the hit 28ratio to 53%, and more importantly, a miss rate of over 10 thousand per second. 29 30 31Here's an interesting workload: 32 33# ./dcstat 34TIME REFS/s SLOW/s MISS/s HIT% 3508:15:53: 250683 141 97 99.96 3608:15:54: 266115 145 101 99.96 3708:15:55: 268428 141 97 99.96 3808:15:56: 260389 143 99 99.96 39 40It's a 99.96% hit ratio, and these are all negative hits: accessing a file that 41does not exist. Here's the C program that generated the workload: 42 43# cat -n badopen.c 44 1 #include <sys/types.h> 45 2 #include <sys/stat.h> 46 3 #include <fcntl.h> 47 4 48 5 int 49 6 main(int argc, char *argv[]) 50 7 { 51 8 int fd; 52 9 while (1) { 53 10 fd = open("bad", O_RDONLY); 54 11 } 55 12 return 0; 56 13 } 57 58This is a simple workload generator than tries to open a missing file ("bad") 59as quickly as possible. 60 61 62Lets see what happens if the workload attempts to open a different filename 63each time (which is also a missing file), using the following C code: 64 65# cat -n badopen2.c 66 1 #include <sys/types.h> 67 2 #include <sys/stat.h> 68 3 #include <fcntl.h> 69 4 #include <stdio.h> 70 5 71 6 int 72 7 main(int argc, char *argv[]) 73 8 { 74 9 int fd, i = 0; 75 10 char buf[128] = {}; 76 11 77 12 while (1) { 78 13 sprintf(buf, "bad%d", i++); 79 14 fd = open(buf, O_RDONLY); 80 15 } 81 16 return 0; 82 17 } 83 84Here's dcstat: 85 86# ./dcstat 87TIME REFS/s SLOW/s MISS/s HIT% 8808:18:52: 241131 237544 237505 1.51 8908:18:53: 238210 236323 236278 0.82 9008:18:54: 235259 233307 233261 0.85 9108:18:55: 233144 231256 231214 0.83 9208:18:56: 231981 230097 230053 0.83 93 94 95dcstat also supports an optional interval and optional count. For example, 96printing 5 second summaries 3 times: 97 98# ./dcstat 5 3 99TIME REFS/s SLOW/s MISS/s HIT% 10008:20:03: 2085 143 99 95.23 10108:20:08: 2077 143 98 95.24 10208:20:14: 2071 144 100 95.15 103 104 105USAGE message: 106 107# ./dcstat -h 108USAGE: ./dcstat [interval [count]] 109