这几天在看 systemtap的东西,这个东东语法比较简单,我感觉学习语言最快的方法就是写起来,所以先看几个例子程序,照着抄一下。
alias_suffixes.stp:
-
#!/usr/bin/stap
-
# alias_suffixes.stp
-
# Uses alias suffixes to track time intervals for a subset of kernel
-
# functions. Based on func_time_stats.stp.
-
-
global start, intervals #define two global
-
-
# We can apply a suffix to multiple probe points designated by one alias:
-
probe miscellany = syscall.open, syscall.close, syscall.read, syscall.write { }
-
-
probe miscellany {
-
start[name, tid()] = gettimeofday_us()
-
}
-
# The 'return' suffix is passed on to each of the underlying probe points:
probe miscellany.return {
t = gettimeofday_us(); old_t = start[name, tid()]
if (old_t) intervals[name] <<< t - old_t # ‘<<<’ 这个符号看后面的代码应该是 追加,
# 《systemtap begining》中的解释: 操作符<<<用于将t -old_t
# 返回的值存放在intervals数组中name相关的值中,即一个键值关联多个相关值。
# 感觉象二维数组
delete start[name, tid()]
}
probe begin {
printf("Collecting data... press Ctrl-C to stop.\n")
}
probe end {
foreach (name in intervals) {
printf("intervals for %s -- min:%dus avg:%dus max:%dus count:%d\n",
name, @min(intervals[name]), @avg(intervals[name]),
@max(intervals[name]), @count(intervals[name])) #这里分别调用了一组函数计算最大、最小、平均值和数量
print(@hist_log(intervals[name]))
}
}
-
上面是systemtap的第一个例子,应
该比较有代表性
.stap -v alias_suffixes.stp
执行效果如下
-
Pass 1: parsed user script and 105 library script(s) using 213988virt/31640res/3024shr/29100data kb, in 100usr/40sys/278real ms.
-
Pass 2: analyzed script: 12 probe(s), 3 function(s), 27 embed(s), 2 global(s) using 393356virt/66564res/4304shr/62640data kb, in 550usr/980sys/1964real ms.
-
Pass 3: using cached /root/.systemtap/cache/f1/stap_f19b5b1aa2bdf527c26182f05e56d4b0_19485.c
-
Pass 4: using cached /root/.systemtap/cache/f1/stap_f19b5b1aa2bdf527c26182f05e56d4b0_19485.ko
-
Pass 5: starting run.
-
Collecting data... press Ctrl-C to stop.
-
^Cintervals for write -- min:1us avg:14us max:13546us count:46401
-
value |-------------------------------------------------- count
-
0 | 0
-
1 | 185
-
2 |@@@@@ 2492
-
4 |@@@@@@@@@@@@@@@@@@ 8110
-
8 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 21974
-
16 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 12388
-
32 |@@ 1239
-
64 | 10
-
128 | 1
-
256 | 1
-
512 | 0
-
1024 | 0
-
2048 | 0
-
4096 | 0
-
8192 | 1
-
16384 | 0
-
32768 | 0
-
-
intervals for read -- min:1us avg:140us max:1960us count:44239
-
value |-------------------------------------------------- count
-
0 | 0
-
1 | 58
-
2 |@@@@ 2517
-
4 |@@@@@@@@@@@@@ 7463
-
8 |@@@ 1972
-
16 | 548
-
32 | 18
-
64 | 9
-
128 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 27711
-
256 |@@@@@@ 3865
-
512 | 75
-
1024 | 3
-
2048 | 0
-
4096 | 0
-
-
intervals for close -- min:2us avg:3us max:14us count:29
-
value |-------------------------------------------------- count
-
0 | 0
-
1 | 0
-
2 |@@@@@@@@@@@@@@@@@@@ 19
-
4 |@@@@@@@@@ 9
-
8 |@ 1
-
16 | 0
-
32 | 0
-
-
intervals for open -- min:18us avg:142us max:419us count:7
-
value |-------------------------------------------------- count
-
4 | 0
-
8 | 0
-
16 |@ 1
-
32 |@@@ 3
-
64 |@ 1
-
128 | 0
-
256 |@@ 2
-
512 | 0
-
1024 | 0
-
-
Pass 5: run completed in 0usr/250sys/12869real ms.
@hist_log函数 类似以进度条形式打印数据,
以open为例,总共执行了7回,有一回花费了1us,一回花费了64us,有3回花费了32us,2回256us
阅读(1282) | 评论(0) | 转发(0) |