Home > Linux, 工具介绍 > systemtap全局变量自动打印的原因和解决方法

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

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: systemtap全局变量自动打印的原因和解决方法

在运行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();
 }

玩的开心.

Post Footer automatically generated by wp-posturl plugin for wordpress.

  1. No comments yet.
  1. No trackbacks yet.