timer event
会周期性执行handler
。举个例子:
# stap -e 'probe timer.s(1) { printf("Hello world!\n");}'
Hello world!
Hello world!
Hello world!
Hello world!
上面脚本每隔1
秒打印一次Hello world!
。
timer event
定义如下:
timer.ms(milliseconds)
timer.us(microseconds)
timer.ns(nanoseconds)
timer.hz(hertz)
timer.jiffies(jiffies)
另外,还有一种randomize
表示方式(参考自这里):
timer.jiffies(N).randomize(M)
The probe handler is run every N jiffies (a kernel-defined unit of time, typically between 1 and 60 ms). If the “randomize” component is given, a linearly distributed random value in the range [-M..+M] is added to N every time the handler is run. N is restricted to a reasonable range (1 to around a million), and M is restricted to be smaller than N.
Alternatively, intervals may be specified in units of time. There are two probe point variants similar to the jiffies timer:
timer.ms(N)
timer.ms(N).randomize(M)
Here, N and M are specified in milliseconds, but the full options for units are seconds (s/sec), milliseconds (ms/msec), microseconds (us/usec), nanoseconds (ns/nsec), and hertz (hz). Randomization is not supported for hertz timers.
最后结合一个例子看一下如何使用timer event
(选自这里):
global count_jiffies, count_ms
probe timer.jiffies(100) { count_jiffies ++ }
probe timer.ms(100) { count_ms ++ }
probe timer.ms(12345)
{
hz=(1000*count_jiffies) / count_ms
printf ("jiffies:ms ratio %d:%d => CONFIG_HZ=%d\n",
count_jiffies, count_ms, hz)
exit ()
}
首先要知道,每秒发生HZ
次jiffies
。
其次,每发生100
次jiffies
,count_jiffies
计数加1
,所以脚本退出时,一共发生100 * count_jiffies
次HZ
。一共经历了count_ms / 10
秒。
最后计算CONFIG_HZ
:(100 * count_jiffies) / (count_ms / 10)
= (1000 * count_jiffies) / count_ms
。