| 1 |
#! /usr/bin/env stap |
| 2 |
# |
| 3 |
# filemap kernel tracepoints: |
| 4 |
# mm_filemap_add_to_page_cache, |
| 5 |
# mm_filemap_delete_from_page_cache |
| 6 |
|
| 7 |
global traced_pid, command |
| 8 |
global allocation, free |
| 9 |
|
| 10 |
global old_set_hits |
| 11 |
global file_fault, file_cow, file_uunmap, file_kunmap |
| 12 |
global file_page_cache_add, file_page_cache_delete |
| 13 |
|
| 14 |
function log_event:long () |
| 15 |
{ |
| 16 |
return (!traced_pid || traced_pid == pid()) |
| 17 |
} |
| 18 |
|
| 19 |
probe kernel.{trace("mm_page_alloc")!, trace("mm_page_allocation")} { |
| 20 |
if (!log_event()) next |
| 21 |
allocation[pid()] <<< 1 |
| 22 |
command[pid()] = execname() |
| 23 |
} |
| 24 |
|
| 25 |
probe kernel.{trace("mm_page_free")!, trace("mm_page_free_direct")} { |
| 26 |
if (!log_event()) next |
| 27 |
free[pid()] <<< 1 |
| 28 |
} |
| 29 |
|
| 30 |
probe kernel.trace("mm_filemap_add_to_page_cache")? { |
| 31 |
if (!log_event()) next |
| 32 |
file_page_cache_add[pid()] <<< 1 |
| 33 |
} |
| 34 |
|
| 35 |
probe kernel.trace("mm_filemap_delete_from_page_cache")? { |
| 36 |
if (!log_event()) next |
| 37 |
file_page_cache_delete[pid()] <<< 1 |
| 38 |
} |
| 39 |
|
| 40 |
probe never { |
| 41 |
# Do a few initializations to let stap know what the global |
| 42 |
# variable types are. Note that since we're in a "never" |
| 43 |
# probe, these initializations will never actually happen. |
| 44 |
traced_pid = 0 |
| 45 |
old_set_hits <<< 1 |
| 46 |
file_fault[0] <<< 1 |
| 47 |
file_cow[0] <<< 1 |
| 48 |
file_uunmap[0] <<< 1 |
| 49 |
file_kunmap[0] <<< 1 |
| 50 |
file_page_cache_add[0] <<< 1 |
| 51 |
file_page_cache_delete[0] <<< 1 |
| 52 |
} |
| 53 |
|
| 54 |
probe begin { |
| 55 |
printf("Starting data collection\n") |
| 56 |
if (target()) |
| 57 |
printf("mode Specific Pid, traced pid: %d\n\n", target()) |
| 58 |
else |
| 59 |
printf("mode - All Pids\n\n") |
| 60 |
} |
| 61 |
|
| 62 |
function print_old_format:long () |
| 63 |
{ |
| 64 |
printf("Command Pid Alloc Free F_fault F_cow F_kunmap F_uunmap\n") |
| 65 |
printf("------- --- ----- ---- ------- ----- -------- --------\n") |
| 66 |
|
| 67 |
foreach (pid+ in allocation) { |
| 68 |
printf("%-16s %10d %9d %9d %8d %8d %8d %8d\n", |
| 69 |
command[pid], pid, |
| 70 |
@count(allocation[pid]), @count(free[pid]), |
| 71 |
@count(file_fault[pid]), @count(file_cow[pid]), |
| 72 |
@count(file_kunmap[pid]), @count(file_uunmap[pid])) |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
function print_new_format:long () |
| 77 |
{ |
| 78 |
printf("Command Pid Alloc Free CacheAdd CacheDel\n") |
| 79 |
printf("------- --- ----- ---- -------- --------\n") |
| 80 |
|
| 81 |
foreach (pid+ in allocation) { |
| 82 |
printf("%-16s %10d %9d %9d %8d %8d\n", |
| 83 |
command[pid], pid, |
| 84 |
@count(allocation[pid]), @count(free[pid]), |
| 85 |
@count(file_page_cache_add[pid]), |
| 86 |
@count(file_page_cache_delete[pid])) |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
probe end { |
| 91 |
printf("Terminating data collection\n") |
| 92 |
|
| 93 |
# We'll have hits from the filemap tracepoints |
| 94 |
# (mm_filemap_add_to_page_cache, |
| 95 |
# mm_filemap_delete_from_page_cache). Print out the set that got |
| 96 |
# hits. |
| 97 |
if (@count(old_set_hits)) |
| 98 |
print_old_format() |
| 99 |
else |
| 100 |
print_new_format() |
| 101 |
} |