| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
/* Monitors hits and misses to the page cache and reports a count |
| 4 |
every 5 seconds. Based on a bpftrace tool by David Valin. */ |
| 5 |
|
| 6 |
// XXX: Rewrite after adding statistical aggregates, new printf to stapbpf. |
| 7 |
|
| 8 |
global active |
| 9 |
global hits, misses, total_hits, total_misses |
| 10 |
|
| 11 |
probe begin { |
| 12 |
printf("%12s%12s%12s\n", "Hits", "Misses", "% Hits") |
| 13 |
} |
| 14 |
|
| 15 |
probe kernel.function("__filemap_get_folio")!, |
| 16 |
kernel.function("pagecache_get_page") { |
| 17 |
active[tid()] = 1 |
| 18 |
} |
| 19 |
|
| 20 |
probe kernel.function("__Filemap_get_folio")!, |
| 21 |
kernel.function("pagecache_get_page").return { |
| 22 |
active[tid()] = 0 |
| 23 |
} |
| 24 |
|
| 25 |
probe kernel.function("filemap_get_entry").return!, |
| 26 |
kernel.function("find_get_entry").return { |
| 27 |
if (active[tid()]) { |
| 28 |
if ($return != 0) hits++ else misses++ |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
probe timer.s(5) { |
| 33 |
h = hits; m = misses |
| 34 |
hits = 0; misses = 0 |
| 35 |
if (h + m > 0) { |
| 36 |
percent_hits = h*10000 / (h + m) |
| 37 |
printf("%12d%12d", h, m) |
| 38 |
printf("%8d.%02d%%\n", percent_hits/100, percent_hits%100) |
| 39 |
} else { |
| 40 |
printf("%12d%12d", 0, 0) |
| 41 |
printf("%8d.%02d%%\n", 0, 0) |
| 42 |
} |
| 43 |
|
| 44 |
total_hits += h |
| 45 |
total_misses += m |
| 46 |
} |
| 47 |
|
| 48 |
probe end { |
| 49 |
printf("\nSummary\n") |
| 50 |
printf("===\n") |
| 51 |
printf("total hits: %12d\n", total_hits) |
| 52 |
printf("total misses: %10d\n", total_misses) |
| 53 |
if (total_hits+total_misses > 0) { |
| 54 |
total_hit_percentage = total_hits*10000/(total_hits+total_misses) |
| 55 |
printf("hit percentage: %4d.%02d%%\n", |
| 56 |
total_hit_percentage/100, total_hit_percentage%100) |
| 57 |
} |
| 58 |
} |