| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
probe perf.sw.cpu_clock!, timer.profile { |
| 4 |
// NB: To avoid contention on SMP machines, no global scalars/arrays used, |
| 5 |
// only contention-free statistics aggregates. |
| 6 |
tid=tid(); e=execname() |
| 7 |
if (!user_mode()) |
| 8 |
kticks[e,tid] <<< 1 |
| 9 |
else |
| 10 |
uticks[e,tid] <<< 1 |
| 11 |
ticks <<< 1 |
| 12 |
tids[e,tid] <<< 1 |
| 13 |
} |
| 14 |
|
| 15 |
global uticks%, kticks%, ticks |
| 16 |
|
| 17 |
global tids% |
| 18 |
|
| 19 |
probe timer.s(5), end { |
| 20 |
allticks = @count(ticks) |
| 21 |
printf ("%16s %5s %7s %7s (of %d ticks)\n", |
| 22 |
"comm", "tid", "%user", "%kernel", allticks) |
| 23 |
foreach ([e,tid] in tids- limit 20) { |
| 24 |
// SystemTap only performs integer arithmetic. |
| 25 |
// To avoid losing precision the decimal point is shifted |
| 26 |
// to the right four places (*100000). Think of this as |
| 27 |
// the original result value x.xxyy becoming xxxyy.0. |
| 28 |
// The integer percentage xxx is obtained |
| 29 |
// by dividing by 100 and the fractional percentage |
| 30 |
// is obtained with a modulo 100 operation. |
| 31 |
uscaled = @count(uticks[e,tid])*10000/allticks |
| 32 |
kscaled = @count(kticks[e,tid])*10000/allticks |
| 33 |
printf ("%16s %5d %3d.%02d%% %3d.%02d%%\n", |
| 34 |
e, tid, uscaled/100, uscaled%100, kscaled/100, kscaled%100) |
| 35 |
} |
| 36 |
printf("\n") |
| 37 |
|
| 38 |
delete uticks |
| 39 |
delete kticks |
| 40 |
delete ticks |
| 41 |
delete tids |
| 42 |
} |