发布日期:2016-06-22 16:47:38

BTrace可以安全地动态跟踪java应用程序执行。通过hotswap技术,向运行中的java应用程序插入跟踪代码(Trace actions )。

BTrace三个概念:

  1. Probe Point
  2. Trace Actions or Actions
  3. Action Methods

BTrace程序的限制:

  1. can not create new objects.
  2. can not create new arrays.
  3. can not throw exceptions.
  4. can not catch exceptions.
  5. 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.
  6. 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).
  7. can not have outer, inner, nested or local classes.
  8. can not have synchronized blocks or synchronized methods.
  9. can not have loops (for, while, do..while)
  10. can not extend arbitrary class (super class has to be java.lang.Object)
  11. can not implement interfaces.
  12. can not contains assert statements.
  13. can not use class literals.

BTrace定义的注解

  1. Method Annotations
    @com.sun.btrace.annotations.OnMethod
    @com.sun.btrace.annotations.OnTimer
    @com.sun.btrace.annotations.OnError
    @com.sun.btrace.annotations.OnExit
    @com.sun.btrace.annotations.OnEvent
    @com.sun.btrace.annotations.OnLowMemory
    @com.sun.btrace.annotations.OnProbe
  2. Argument Annotations
    @com.sun.btrace.annotations.Self
    @com.sun.btrace.annotations.Return
    @com.sun.btrace.annotations.ProbeClassName
    @com.sun.btrace.annotations.ProbeMethodName
    @com.sun.btrace.annotations.Duration
    @com.sun.btrace.annotations.TargetInstance
    @com.sun.btrace.annotations.TargetMethodOrField
    
    Kind.ENTRY, Kind.RETURN- the probed method arguments
    Kind.THROW - the thrown exception
    Kind.ARRAY_SET, Kind.ARRAY_GET - the array index
    Kind.CATCH - the caught exception
    Kind.FIELD_SET - the field value
    Kind.LINE - the line number
    Kind.NEW - the class name
    Kind.ERROR - the thrown exception
  3. Field Annotations
    @com.sun.btrace.annotations.Export
    @com.sun.btrace.annotations.Property
    @com.sun.btrace.annotations.TLS
  4. Class Annotations
    @com.sun.btrace.annotations.DTrace
    @com.sun.btrace.annotations.DTraceRef
    @com.sun.btrace.annotations.BTrace

     

参考文章:

  • 官方网站:https://kenai.com/projects/btrace/pages/UserGuide
  • 不错的一个博客: http://agapple.iteye.com/blog/1005918

发表评论