IT技术博客大学习 共学习 共进步

systemtap全局变量自动打印的原因和解决方法

Erlang非业余研究 2011-03-27 23:50:01 浏览 2,742 次

    在运行stap的时候,经常会发现在脚本结束运行的时候打出了很多无预期的东西,仔细一看都是些全局变量的dump, 这个问题比较烦人.

    我来演示下:

$ cat > g.stp
global xyz
probe begin{
  xyz=2010
  exit();
}
CTRL+D

$ sudo stap g.stp
xyz=0x7da
#多余的显示,其实我们只想静悄悄的结束

    查看了代码和文档发现:

     A global declaration may be written at the outermost level anywhere, not

     within a block of code. Global variables which are written but never read will be displayed automatically at session shutdown. The translator

     will infer for each its value type, and if it is used as an array, its key types. Optionally, scalar globals may be initialized with a string or

     number literal. The following declaration marks variables as global.

    原来只写不读的通通要打印提醒你, 知道了原因就好办了.

    加多个delete把全局变量清空,就没啥好显示了:

$ diff -up g1.stp g.stp
--- g1.stp	2011-03-25 13:14:37.940594540 +0800
+++ g.stp	2011-03-25 13:12:59.470450112 +0800
@@ -1,5 +1,6 @@
 global xyz
 probe begin{
   xyz=2010
+delete xyz
  exit();
 }

建议继续学习

  1. Linux下如何知道文件被那个进程写 (阅读 6,322)
  2. 在Ubuntu上使用SystemTap (阅读 3,920)
  3. 突破systemtap脚本对资源使用的限制 (阅读 3,581)
  4. jQuery打印插件 (阅读 3,560)
  5. systemtap函数调用栈信息不齐的原因和解决方法 (阅读 3,122)
  6. 用于打印的页面设计 (阅读 2,520)
  7. systemtap观察page_cache的使用情况 (阅读 2,220)