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:

作者: coredump    时间: 6-6-2008 18:54
这是个比top命令精确得多的SYSTEMTAP版topcpu脚本,每3秒钟把CPU占用率最高的PID列出来。数字代表3秒内该进程被上下文切换的次数
  1. #!/usr/local/bin/stap -k
  2. probe kernel.function("context_switch") {
  3.   switches ++   # count number of context switches
  4.   now = get_cycles()
  5.   times[pid()] += now-lasttime  # accumulate cycles spent in process

  6.   execnames[pid()] = execname() # remember name of pid
  7.   lasttime = now
  8. }
  9. probe timer.ms(3000) { # every 3000 ms
  10.   printf ("\n%10s %30s %20s  (%d switches)\n",
  11.           "pid", "execname", "cycles", switches);

  12.   foreach ([pid] in times-) # sort in decreasing order of cycle-count
  13.     printf ("%10d %30s %20d\n", pid, execnames[pid], times[pid]);
  14.   # clear data for next report
  15.   delete times
  16.   switches = 0

  17. }
  18. probe begin {
  19.   lasttime = get_cycles()
  20. }
  21. global lasttime, times, execnames, switches
复制代码

作者: lilianaya    时间: 10-6-2008 18:22
NB 的东西啊。




欢迎光临 FreeOZ论坛 (https://www.freeoz.org/bbs/) Powered by Discuz! X3.2