Btrace使用

来源:互联网 发布:红色网络教育家园导航 编辑:程序博客网 时间:2024/05/02 14:39

前阵子排查一个OOM 的问题,刚好和hsf有点关系,于是找毕玄帮忙查找问题,看看hsf 的代码,看到毕玄在用Btrace来跟踪方法的调用,觉得此法还是不错滴,以前都是人肉看现象推测,汗,再次记录下。

http://blog.bluedavy.com/?p=185  这个是毕玄记录的BTrace使用,可以参考下。

 

BTrace is a safe, dynamic tracing tool for Java. BTrace works by dynamically (bytecode) instrumenting classes of a running Java program. BTrace inserts tracing actions into the classes of a running Java program and hotswaps the traced program classes.

 

BTrace 可以在不改代码、不重启应用的情况下,动态的查看程序运行细节的工具,可以蛮方便食用的。

其官方网站在此:http://kenai.com/projects/btrace/,

具体的实施操作细则可以参考:

http://kenai.com/projects/btrace/pages/UserGuide

 

 

下面是摘抄的写一个BTrace类的主意事项:

 

a BTrace class

  • can not create new objects.
  • can not create new arrays.
  • can not throw exceptions.
  • can not catch exceptions.
  • can not make arbitrary instance or static method calls - only the public static methods of com.sun.btrace.BTraceUtils class or methods declared in the same program may be called from a BTrace program.
  • (pre 1.2) can not have instance fields and methods. Only static public void returning methods are allowed for a BTrace class. And all fields have to be static.
  • can not assign to static or instance fields of target program's classes and objects. But, BTrace class can assign to it's own static fields ("trace state" can be mutated).
  • can not have outer, inner, nested or local classes.
  • can not have synchronized blocks or synchronized methods.
  • can not have loops (for, while, do..while)
  • can not extend arbitrary class (super class has to be java.lang.Object)
  • can not implement interfaces.
  • can not contains assert statements.
  • can not use class literals.

 

 

原创粉丝点击