| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
global fault_entry_time, fault_address, fault_access |
| 4 |
global time_offset |
| 5 |
|
| 6 |
probe begin { time_offset = gettimeofday_us() } |
| 7 |
|
| 8 |
probe vm.pagefault { |
| 9 |
t = gettimeofday_us() |
| 10 |
fault_entry_time[tid()] = t |
| 11 |
fault_address[tid()] = address |
| 12 |
fault_access[tid()] = write_access ? "w" : "r" |
| 13 |
} |
| 14 |
|
| 15 |
probe vm.pagefault.return { |
| 16 |
t=gettimeofday_us() |
| 17 |
if (!(tid() in fault_entry_time)) next |
| 18 |
e = t - fault_entry_time[tid()] |
| 19 |
if (vm_fault_contains(fault_type,VM_FAULT_MINOR)) { |
| 20 |
ftype="minor" |
| 21 |
} else if (vm_fault_contains(fault_type,VM_FAULT_MAJOR)) { |
| 22 |
ftype="major" |
| 23 |
} else { |
| 24 |
next #only want to deal with minor and major page faults |
| 25 |
} |
| 26 |
|
| 27 |
printf("%d:%d:%id:%s:%s:%d\n", |
| 28 |
t - time_offset, tid(), fault_address[tid()], fault_access[tid()], ftype, e) |
| 29 |
#free up memory |
| 30 |
delete fault_entry_time[tid()] |
| 31 |
delete fault_address[tid()] |
| 32 |
delete fault_access[tid()] |
| 33 |
} |