| 1 |
#! /usr/bin/env stap |
| 2 |
# Copyright (C) 2011-2016 Red Hat, Inc. |
| 3 |
# Written by William Cohen <[email protected]> |
| 4 |
# |
| 5 |
# This script give an idea what periodic things are running on |
| 6 |
# the system. Usage: |
| 7 |
# |
| 8 |
# stap --all-modules periodic.stp |
| 9 |
|
| 10 |
global last_expire, period, funct, data, proc_info, delayed_work_info |
| 11 |
|
| 12 |
probe kernel.trace("timer_expire_entry") |
| 13 |
{ |
| 14 |
old_expire = last_expire[$timer] |
| 15 |
new_expire = gettimeofday_us() |
| 16 |
if (old_expire) { |
| 17 |
elapsed = new_expire - old_expire |
| 18 |
period[$timer] <<< elapsed |
| 19 |
funct[$timer] = $timer->function |
| 20 |
data[$timer] = @defined($timer->data) ? $timer->data : 0 |
| 21 |
proc_info[$timer] = @defined($timer->data) ? 0 : @module_container_of($timer, "kernel", "struct process_timer", timer)->task |
| 22 |
delayed_work_info[$timer] = @defined($timer->data) ? 0 : & @module_container_of($timer, "kernel", "struct delayed_work", timer) |
| 23 |
} |
| 24 |
last_expire[$timer] = new_expire |
| 25 |
} |
| 26 |
|
| 27 |
function output() |
| 28 |
{ |
| 29 |
printf("%-7s %-50s %15s %25s %9s\n", "#type", "function", "avg period(us)", "period variance(us^2)", "count") |
| 30 |
# print out the various timers firing |
| 31 |
foreach([timer] in period-) { |
| 32 |
fname = symname(funct[timer]) |
| 33 |
if (fname == "process_timeout") { |
| 34 |
ptr = (data[timer] ? data[timer] : proc_info[timer]) |
| 35 |
fname = sprintf("%s(%d)", |
| 36 |
kernel_string_n(@cast(ptr, "struct task_struct", "kernel<linux/sched.h>")->comm, 16), |
| 37 |
@cast(ptr, "struct task_struct", "kernel<linux/sched.h>")->pid) |
| 38 |
type="process" |
| 39 |
} else if (fname == "delayed_work_timer_fn") { |
| 40 |
ptr = (data[timer] ? data[timer] : delayed_work_info[timer]) |
| 41 |
faddr = @defined(@cast(ptr, "struct delayed_work", "kernel<linux/workqueue.h>")->work->func) |
| 42 |
? @cast(ptr, "struct delayed_work", "kernel<linux/workqueue.h>")->work->func |
| 43 |
: @cast(ptr, "struct work_struct", "kernel<linux/workqueue.h>")->func |
| 44 |
fname = sprintf("%s", symname(faddr)) |
| 45 |
type="work_q" |
| 46 |
} else { |
| 47 |
fileline = symfileline(funct[timer]) |
| 48 |
if (strtol(fileline, 16)) // fileline is just the address |
| 49 |
fname = sprintf("%s", symdata(funct[timer])) |
| 50 |
else |
| 51 |
fname = sprintf("%s@%s", symname(funct[timer]), fileline) |
| 52 |
type="kernel" |
| 53 |
} |
| 54 |
printf("%-7s %-50.50s %15d %25d %9d\n", type, fname, |
| 55 |
@avg(period[timer]), @variance(period[timer], 2), @count(period[timer])) |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
probe begin |
| 60 |
{ |
| 61 |
printf("#monitoring timer periods (press control-c for output)\n") |
| 62 |
} |
| 63 |
|
| 64 |
probe end { output() } |
| 65 |
|
| 66 |
# allow optional period output from script |
| 67 |
%( $# > 0 %? |
| 68 |
probe timer.s($1) |
| 69 |
{ |
| 70 |
output(); |
| 71 |
delete last_expire |
| 72 |
delete period |
| 73 |
delete funct |
| 74 |
delete data |
| 75 |
delete proc_info |
| 76 |
delete delayed_work_info |
| 77 |
} |
| 78 |
%) |