如何编写SystemTap脚本
下面代码示例演示了SystemTap 语法和控制结构。
[root@BL480-64 ~]#vi test1.stpglobal odds, evens probe begin { # no 和ne 是局部整型变量 for (i = 0; i < 10; i++) { if (i % 2) odds [no++] = i else evens [ne++] = i } delete odds[2] delete evens[3] exit() } probe end { foreach (x+ in odds) printf ("odds[%d] = %d", x, odds[x]) foreach (x in evens-) printf ("evens[%d] = %d", x, evens[x]) }
保存退出。
[root@BL480-64 ~]#stap test1.stp运行输出:odds[0] = 1 odds[1] = 3 odds[3] = 7 odds[4] = 9 evens[4] = 8 evens[2] = 4 evens[1] = 2 evens[0] = 0大家如果学习过perl、python脚本语言,会发现如此熟悉o(∩_∩)o…哈哈