| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
probe begin |
| 4 |
{ |
| 5 |
printf ("%%DataSet:cpu 100 00ff00 bar\n"); |
| 6 |
printf ("%%DataSet:kbd 75 ff0000 discreet\n"); |
| 7 |
printf ("%%DataSet:pty 50 0000ff discreet\n"); |
| 8 |
printf ("cpu %%Title:CPU utilization\n"); |
| 9 |
printf ("cpu %%XAxisTitle:Time\n"); |
| 10 |
printf ("cpu %%YAxisTitle:Percent\n"); |
| 11 |
printf ("%%LineEnd:0\n"); |
| 12 |
} |
| 13 |
|
| 14 |
# CPU utilization |
| 15 |
probe begin { qnames["cpu"] ++; qsq_start ("cpu") } |
| 16 |
probe scheduler.cpu_on { if (!idle) {qs_wait ("cpu") qs_run ("cpu") }} |
| 17 |
probe scheduler.cpu_off { if (!idle) qs_done ("cpu") } |
| 18 |
|
| 19 |
global qnames |
| 20 |
|
| 21 |
function qsq_util_reset(q) { |
| 22 |
u=qsq_utilization (q, 100) |
| 23 |
qsq_start (q) |
| 24 |
return u |
| 25 |
} |
| 26 |
|
| 27 |
probe timer.ms(100) { # collect utilization percentages frequently |
| 28 |
foreach (q in qnames) |
| 29 |
printf("cpu %d %d%c", gettimeofday_ms(), qsq_util_reset(q), 0) |
| 30 |
} |
| 31 |
|
| 32 |
probe kernel.function("kbd_event") { |
| 33 |
if ($event_type == 1 && $value) |
| 34 |
printf("kbd %d %d\n0x%x%c", gettimeofday_ms(), $event_code, $event_code, 0) |
| 35 |
} |
| 36 |
|
| 37 |
probe kernel.function("pty_write") { |
| 38 |
count = @defined($c) ? $c : $count |
| 39 |
if (count > 0) { |
| 40 |
printf("pty %d ", gettimeofday_ms()) |
| 41 |
str = $buf |
| 42 |
for (i = 0; i < count; ++i) { |
| 43 |
if (i > 1) |
| 44 |
printf("\n") |
| 45 |
c = kernel_char(str + i) |
| 46 |
printf("%c", c) |
| 47 |
} |
| 48 |
printf("%c", 0) |
| 49 |
} |
| 50 |
} |