| 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 |
|
| 11 |
probe timer.profile |
| 12 |
# or perf.type(0).config(0).sample(NNNN) for apprx. every NNNN tsc ticks |
| 13 |
{ |
| 14 |
# add filtering as required: |
| 15 |
# if (execname() != "program") next |
| 16 |
# if (uid() != 4345) next |
| 17 |
# if (! user_mode()) next |
| 18 |
if (target() && pid() != target()) next # be sensitive to -x PID or -c CMD |
| 19 |
|
| 20 |
# NB: we count total hits also, because the report only shows top few |
| 21 |
pcount <<< 1 |
| 22 |
|
| 23 |
bt = user_mode() ? sprint_ubacktrace() : sprint_backtrace() |
| 24 |
profile[cpu(),bt] <<< 1 |
| 25 |
} |
| 26 |
|
| 27 |
probe end,error,timer.ms(5000) { |
| 28 |
printf ("\n--- %d samples recorded:\n", @count(pcount)) |
| 29 |
|
| 30 |
foreach ([c,b] in profile- limit 20) { |
| 31 |
printf ("%d hits on cpu %d\n%s\n\n", @count(profile[c,b]), c, b) |
| 32 |
} |
| 33 |
|
| 34 |
delete profile |
| 35 |
delete pcount |
| 36 |
} |