| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
# usage: fntimes.stp FUNCTIONPROBE |
| 4 |
# e.g. fntimes.stp 'module("ext4").function("*")' |
| 5 |
|
| 6 |
global mincount = 100 # training: beneath this number of hits, only collect data |
| 7 |
global note_percent = 250 # percent beyond maximum-so-far to generate report for |
| 8 |
function time() { return gettimeofday_us() } # time measurement function |
| 9 |
|
| 10 |
global times |
| 11 |
|
| 12 |
function check(t) # t: elapsed time |
| 13 |
{ |
| 14 |
if (@count(times[ppfunc()]) >= mincount |
| 15 |
&& t >= @max(times[ppfunc()]) * note_percent / 100) { # also consider @avg() |
| 16 |
printf("function %s well over %s time (%d vs %d), duration variance %d s^2\n", |
| 17 |
ppfunc(), "maximum", t, @max(times[ppfunc()]), @variance(times[ppfunc()], 3)) |
| 18 |
# also consider: print_backtrace() |
| 19 |
} |
| 20 |
times[ppfunc()] <<< t # (increments @count, updates @max) |
| 21 |
} |
| 22 |
|
| 23 |
probe $1.return { check(time()-@entry(time())) } |