| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
function time () { return gettimeofday_ms() } |
| 4 |
global time_name = "ms" |
| 5 |
global boredom = 10 # in time units |
| 6 |
global name, back, backtime, bored |
| 7 |
|
| 8 |
/* Note: the order that the probes are listed should not matter. |
| 9 |
However, the following order for |
| 10 |
probe kernel.function("wait_for_completion").return and |
| 11 |
probe kernel.function("wait_for_completion").call |
| 12 |
avoids have the kretprobe stuff in the backtrace. |
| 13 |
for more information see: |
| 14 |
http://sourceware.org/bugzilla/show_bug.cgi?id=6436 |
| 15 |
*/ |
| 16 |
|
| 17 |
|
| 18 |
probe kernel.function("wait_for_completion").return |
| 19 |
{ |
| 20 |
if ([tid()] in bored) { |
| 21 |
patience = time() - backtime[tid()] |
| 22 |
printf ("thread %d (%s) bored for %d %s\n", |
| 23 |
tid(), name[tid()], patience, time_name) |
| 24 |
} |
| 25 |
|
| 26 |
delete bored[tid()] |
| 27 |
delete back[tid()] |
| 28 |
delete name[tid()] |
| 29 |
delete backtime[tid()] |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
probe kernel.function("wait_for_completion").call |
| 34 |
{ |
| 35 |
back[tid()]=backtrace() |
| 36 |
name[tid()]=execname() |
| 37 |
backtime[tid()]=time() |
| 38 |
delete bored[tid()] |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
probe timer.profile { |
| 43 |
foreach (tid+ in back) { |
| 44 |
if ([tid] in bored) continue |
| 45 |
|
| 46 |
patience = time() - backtime[tid] |
| 47 |
if (patience >= boredom) { |
| 48 |
printf ("thread %d (%s) impatient after %d %s\n", |
| 49 |
tid, name[tid], patience, time_name) |
| 50 |
print_syms (back[tid]) |
| 51 |
printf ("\n") |
| 52 |
bored[tid] = 1 # defer further reports to wakeup |
| 53 |
} |
| 54 |
} |
| 55 |
} |