|
2#
楼主 |
发表于 6-6-2008 18:54:46
|
只看该作者
这是个比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
复制代码 |
评分
-
查看全部评分
|