| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
%( CONFIG_64BIT == "y" %? |
| 4 |
global profile%[20000], pcount |
| 5 |
%: |
| 6 |
# On a 32-bit platform, the profile array must be smaller, otherwise |
| 7 |
# its allocation will fail on module startup. |
| 8 |
global profile%[5000], pcount |
| 9 |
%) |
| 10 |
probe timer.profile { |
| 11 |
pcount <<< 1 |
| 12 |
# NB: we resolve to a function name here (rather than recording only |
| 13 |
# the PC), because during a later pc->name lookup, the process context |
| 14 |
# may be different. |
| 15 |
if (!user_mode()) |
| 16 |
try { // modname() can throw |
| 17 |
fn = "k:".modname(addr()).":".symname(addr()) |
| 18 |
} catch { |
| 19 |
fn = "k:<unknown>:".symname(addr()) |
| 20 |
} |
| 21 |
else { |
| 22 |
try { // umodname() can throw |
| 23 |
fn = "u:".umodname(uaddr()).":".usymname(uaddr()) |
| 24 |
} catch { |
| 25 |
fn = "u:<unknown>:".usymname(uaddr()) |
| 26 |
} |
| 27 |
} |
| 28 |
profile[fn] <<< 1 |
| 29 |
} |
| 30 |
probe timer.ms(5000) { |
| 31 |
printf ("\n--- %d samples recorded:\n", @count(pcount)) |
| 32 |
foreach (f in profile- limit 20) { |
| 33 |
printf ("%-30s\t%6d\n", f, @count(profile[f])) |
| 34 |
} |
| 35 |
delete profile |
| 36 |
delete pcount |
| 37 |
} |