FreeOZ论坛
标题:
SYSTEMTAP, Linux下的倚天剑or屠龙刀
[打印本页]
作者:
coredump
时间:
6-6-2008 18:48
标题:
SYSTEMTAP, Linux下的倚天剑or屠龙刀
熟悉Solaris的都知道Solaris 10中有个很牛逼的
DTrace技术
,惹着诸如MacOSX,FreeBSD之类的系统纷纷把
DTrace
引入到自家内核。不过就像Solaris的ZFS一样,由于许可证的问题,这些Solaris上的NB技术不可能移植到Linux上。不过Linux有一个能和DTrace媲美的技术,也是很好很强大的,一般人偶不告诉他
它的名字就叫: SYSTEMTAP.
那么SYSTEMTAP能干什么呢?如果你懂得DTrace能干什么,那么SYSTEMTAP也就能干什么,形象点说SYSTEMTAP/DTrace之类的东东就像医院里的CT一样,能在系统运行时完全透视解剖系统运行的参数。 没有这个宝贝之前,系统底层发生了问题调试起来简直能让人发疯。那是的程序员不可以和医生相比,最多类似法医,只能在死人(终止运行的程序)身上(没死的话得杀死
)才能发现个蛛丝马迹。
喜欢Linux/Unix的朋友不可错过对这个东东的研究啊,搞系统/数据库管理的TX也应该会很中意这个技术的。
references:
http://www.ibm.com/developerworks/cn/linux/l-systemtap/
http://sourceware.org/systemtap/
http://sourceware.org/systemtap/tutorial.pdf
http://sources.redhat.com/systemtap/wiki/RedHatSummit2007?action=AttachFile&do=get&target=RHSummit07-ETSystemTap.pdf
作者:
coredump
时间:
6-6-2008 18:54
这是个比top命令精确得多的SYSTEMTAP版topcpu脚本,每3秒钟把CPU占用率最高的PID列出来。数字代表3秒内该进程被上下文切换的次数
#!/usr/local/bin/stap -k
probe kernel.function("context_switch") {
switches ++ # count number of context switches
now = get_cycles()
times[pid()] += now-lasttime # accumulate cycles spent in process
execnames[pid()] = execname() # remember name of pid
lasttime = now
}
probe timer.ms(3000) { # every 3000 ms
printf ("\n%10s %30s %20s (%d switches)\n",
"pid", "execname", "cycles", switches);
foreach ([pid] in times-) # sort in decreasing order of cycle-count
printf ("%10d %30s %20d\n", pid, execnames[pid], times[pid]);
# clear data for next report
delete times
switches = 0
}
probe begin {
lasttime = get_cycles()
}
global lasttime, times, execnames, switches
复制代码
作者:
lilianaya
时间:
10-6-2008 18:22
NB 的东西啊。
欢迎光临 FreeOZ论坛 (https://www.freeoz.org/bbs/)
Powered by Discuz! X3.2