Brendan Gregg | 5bfadab | 2016-02-10 01:36:51 -0800 | [diff] [blame] | 1 | Demonstrations of dcstat, the Linux eBPF/bcc version. |
| 2 | |
| 3 | |
| 4 | dcstat shows directory entry cache (dcache) statistics. For example: |
| 5 | |
| 6 | # ./dcstat |
| 7 | TIME REFS/s SLOW/s MISS/s HIT% |
| 8 | 08:11:47: 2059 141 97 95.29 |
| 9 | 08:11:48: 79974 151 106 99.87 |
| 10 | 08:11:49: 192874 146 102 99.95 |
| 11 | 08:11:50: 2051 144 100 95.12 |
| 12 | 08:11:51: 73373 17239 17194 76.57 |
| 13 | 08:11:52: 54685 25431 25387 53.58 |
| 14 | 08:11:53: 18127 8182 8137 55.12 |
| 15 | 08:11:54: 22517 10345 10301 54.25 |
| 16 | 08:11:55: 7524 2881 2836 62.31 |
| 17 | 08:11:56: 2067 141 97 95.31 |
| 18 | 08:11:57: 2115 145 101 95.22 |
| 19 | |
| 20 | The output shows the total references per second ("REFS/s"), the number that |
| 21 | took 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 |
| 23 | second is used. |
| 24 | |
| 25 | At 08:11:49, there were 192 thousand references, which almost entirely hit |
| 26 | from the dcache, with a hit ration of 99.95%. A little later, starting at |
| 27 | 08:11:51, a workload began that walked many uncached files, reducing the hit |
| 28 | ratio to 53%, and more importantly, a miss rate of over 10 thousand per second. |
| 29 | |
| 30 | |
| 31 | Here's an interesting workload: |
| 32 | |
| 33 | # ./dcstat |
| 34 | TIME REFS/s SLOW/s MISS/s HIT% |
| 35 | 08:15:53: 250683 141 97 99.96 |
| 36 | 08:15:54: 266115 145 101 99.96 |
| 37 | 08:15:55: 268428 141 97 99.96 |
| 38 | 08:15:56: 260389 143 99 99.96 |
| 39 | |
| 40 | It's a 99.96% hit ratio, and these are all negative hits: accessing a file that |
| 41 | does 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 | |
| 58 | This is a simple workload generator than tries to open a missing file ("bad") |
| 59 | as quickly as possible. |
| 60 | |
| 61 | |
| 62 | Lets see what happens if the workload attempts to open a different filename |
| 63 | each 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 | |
| 84 | Here's dcstat: |
| 85 | |
| 86 | # ./dcstat |
| 87 | TIME REFS/s SLOW/s MISS/s HIT% |
| 88 | 08:18:52: 241131 237544 237505 1.51 |
| 89 | 08:18:53: 238210 236323 236278 0.82 |
| 90 | 08:18:54: 235259 233307 233261 0.85 |
| 91 | 08:18:55: 233144 231256 231214 0.83 |
| 92 | 08:18:56: 231981 230097 230053 0.83 |
| 93 | |
| 94 | |
| 95 | dcstat also supports an optional interval and optional count. For example, |
| 96 | printing 5 second summaries 3 times: |
| 97 | |
| 98 | # ./dcstat 5 3 |
| 99 | TIME REFS/s SLOW/s MISS/s HIT% |
| 100 | 08:20:03: 2085 143 99 95.23 |
| 101 | 08:20:08: 2077 143 98 95.24 |
| 102 | 08:20:14: 2071 144 100 95.15 |
| 103 | |
| 104 | |
| 105 | USAGE message: |
| 106 | |
| 107 | # ./dcstat -h |
| 108 | USAGE: ./dcstat [interval [count]] |