systemtap on centos

とりあえず、systemtapを動作させてみることにする。

(221)->$cat top.stp
#!/usr/bin/env stap
#
# This script continuously lists the top 20 systemcalls on the system
#

global syscalls

function print_top () {
cnt=0
printf ("SYSCALL\t\t\t\tCOUNT\n")
foreach ([name] in syscalls-) {
printf("%-20s\t\t%5d\n",name, syscalls[name])
if (cnt++ == 20)
break
}
printf("--------------------------------------\n")
delete syscalls
}

probe kernel.function("sys_*") {
syscalls[probefunc()]++
}

# print top syscalls every 5 seconds
probe timer.ms(5000) {
print_top ()

http://d.hatena.ne.jp/stts/20090614
system tap を利用するには、kernel-debuginfoが必要らしい。
kernel-debuginfoとkernel-debuginfo-commonが必要。

どこに、書いてあるんだろうか…。
で、再度実行してみると、

(219)->$stap top.stp
Warning: /usr/bin/staprun is not executable (許可がありません)
Warning: /usr/bin/staprun exited with status: 127
Pass 5: run failed. Try again with another '--vp 00001' option.

rootになったらできた。なるほど、簡単だ。

P.S.
コメント欄にツッコミがはいったので、ちょっと訂正。
Systemtap tutorialによれば、

Log on as root, or even better, login as a user that is a member of stapdev
group or as a user authorized to sudo, before running systemtap.

とあるので、rootでもいいけど、stapdev(stapusrでも良いみたい)グループのメンバに属するユーザ、sudoによって権威化された
ユーザで実行した方がよいとのことでした。

Thx, Mr. Eigler.