技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> Linux --> systemtap全局变量自动打印的原因和解决方法

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

浏览:1709次  出处信息

    在运行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下如何知道文件被那个进程写    (阅读:4700)
  2. 在Ubuntu上使用SystemTap    (阅读:2882)
  3. jQuery打印插件    (阅读:2856)
  4. 突破systemtap脚本对资源使用的限制    (阅读:2316)
  5. systemtap函数调用栈信息不齐的原因和解决方法    (阅读:2122)
  6. 用于打印的页面设计    (阅读:1781)
  7. systemtap观察page_cache的使用情况    (阅读:1659)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1