`
半点玻璃心
  • 浏览: 27310 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

btrace annotation简单翻译

 
阅读更多
最近研究btrace动态调试线上服务,无奈英文很差,于是乎想到把官方文档小小翻一下,正好学习英语,各位大神请轻拍。
    原文地址:https://kenai.com/projects/btrace/pages/UserGuide#btrace_anno。这篇文章可能一下子写不完,先挖个坑,每天填一点。
    每一段上面为原文,下面为译文。
   
Method Annotations

@com.sun.btrace.annotations.OnMethod annotation can be used to specify target class(es), target method(s) and "location(s)" within the method(s). An action method annotated by this annotation is called when the matching method(s) reaches specified the location. In OnMethod annotation, traced class name is specified by "clazz" property and traced method is specified by "method" property. "clazz" may be a fully qualified class name (likejava.awt.Component or a regular expression specified within two forward slashes. Refer to the samplesNewComponent.java and Classload.java. The regular expression can match zero or more classes in which case all matching classes are instrumented. For example /java\\.awt\\..+/ matches all classes in java.awt package. Also, method name can be a regular expression as well - matching zero or more methods. Refer to the sampleMultiClass.java. There is another way to abstractly specify traced class(es) and method(s). Traced classes and methods may be specified by annotation. For example, if the "clazz" attribute is specified as @javax.jws.WebServiceBTrace will instrument all classes that are annotated by the WebService annotation. Similarly, method level annotations may be used to specify methods abstractly. Refer to the sample WebServiceTracker.java. It is also possible to combine regular expressions with annotations - like @/com\\.acme\\..+/ matches any class that is annotated by any annotation that matches the given regular expression. It is possible to match multiple classes by specifying super type. i.e., match all classes that are subtypes of a given super type. +java.lang.Runnable matches all classes implementingjava.lang.Runnable interface. Refer to the sample SubtypeTracer.java.
@com.sun.btrace.annotations.OnMethod annotation 用于指定类、方法和方法内的“位置”。当一个与注解匹配的方法运行到指定的“位置”时,这个被注解的方法就会被调用。在OnMethod注解中,需要跟踪的类由"clazz" 定义,而方法则是“method”。"clazz"可以是一个全限定的类名,或者是一个用两个双斜线括起来的正则表达式。具体参照示例:NewComponent.java 和Classload.java.正则表达式能匹配0到多个类,所有匹配上的类都能跟踪到。例如 /java\\.awt\\..+/ 匹配所有java.awt 包下面的类. 同样的,方法名也可以用正则表达式描述。参照MultiClass.java示例. 还有其他的方式能精确的指定跟踪的类和方法--通过注解:例如,如果的你的"clazz" 属性指定为@javax.jws.WebService,BTrace 就会匹配所有用WebService注解修饰的类.类似的,"method"属性也可以这样配置来跟踪特定的某些方法.具体参照示例: WebServiceTracker.java. 用过注解跟踪的方式,同样可以使用正则表达式:比如 @/com\\.acme\\..+/. 也可通过通过制定超类或者接口来跟踪子类或者实现.比如 +java.lang.Runnable 可以跟踪到java.lang.Runnable 的所有实现类.参照示例: SubtypeTracer.java.
    
@com.sun.btrace.annotations.OnTimer annotation can be used to specify tracing actions that have to run periodically once every N milliseconds. Time period is specified as long "value" property of this annotation. Refer to the sampleHistogram.java
@com.sun.btrace.annotations.OnTimer 用于指定跟踪脚本每N毫秒就执行一次。N的值用value属性指定,为long型。参照:Histogram.java
@com.sun.btrace.annotations.OnError annotation can be used to specify actions that are run whenever any exception is thrown by tracing actions of some other probe. BTrace method annotated by this annotation is called when any exception is thrown by any of the other BTrace action methods in the same BTrace class.
@com.sun.btrace.annotations.OnError 用于指定当其他的btrace脚本运行时抛出异常后btrace应该执行的行为。也就是说如果btrace的脚本在运行过程中抛出了异常,那么被OnError修饰的方法就会执行。
@com.sun.btrace.annotations.OnExit annotation can be used to specify actions that are run when BTrace code calls "exit(int)" built-in function to finish the tracing "session". Refer to the sample ProbeExit.java.
@com.sun.btrace.annotations.OnExit 用于指定当btrace脚本退出是btrace应该执行的行为,也就是说,当btrace 脚本中调用了exit(int i)方法后,该注解修饰的方法就会执行。参照: ProbeExit.java
@com.sun.btrace.annotations.OnEvent annotation is used to associate tracing methods with "external" events send by BTrace client. BTrace methods annotated by this annotation are called when BTrace client sends an "event". Client may send an event based on some form of user request to send (like pressing Ctrl-C or a GUI menu). String value may used as the name of the event. This way certain tracing actions can be executed whenever an external event "fires". As of now, the command line BTrace client sends "events" whenever use presses Ctrl-C (SIGINT). On SIGINT, a console menu is shown to send an event or exit the client [which is the default for SIGINT]. Refer to the sampleHistoOnEvent.java
@com.sun.btrace.annotations.OnLowMemory annotation can be used to trace memory threshold exceed event. See sample MemAlerter.java
@com.sun.btrace.annotations.OnProbe annotation can be used to specify to avoid using implementation internal classes in BTrace scripts. @OnProbe probe specifications are mapped to one or more @OnMethod specifications by the BTrace VM agent. Currently, this mapping is done using a XML probe descriptor file [accessed by the BTrace agent]. Refer to the sample SocketTracker1.java and associated probe descriptor file java.net.socket.xml. When running this sample, this xml file needs to be copied in the directory where the target JVM runs (or fix probeDescPath option in btracer.bat to point to whereever the .xml file is).
Argument Annotations

@com.sun.btrace.annotations.Self annotation can be used to mark an argument to hold this (or self) value. Refer to the samples AWTEventTracer.java or AllCalls1.java
@com.sun.btrace.annotations.Self 标注一个变量用于保存 this (or self) 的值。参照 :AWTEventTracer.java or AllCalls1.java
@com.sun.btrace.annotations.Return annotation can be used to mark an argument to hold the return value. Refer to the sample Classload.java
@com.sun.btrace.annotations.Return . 标注一个变量用于保存方法的返回值,参照: Classload.java
@com.sun.btrace.annotations.ProbeClassName (since 1.1) annotation can be used to mark an argument to hold the probed class name value. Refer to the sample AllMethods.java
@com.sun.btrace.annotations.ProbeClassName (since 1.1) 标注一个变量用于保存探测器类名。参照: AllMethods.java
@com.sun.btrace.annotations.ProbeMethodName (since 1.1) 标注一个变量用于保存探测器方法名。参照: WebServiceTracker.java
since 1.2 it accepts boolean parameter fqn to get a fully qualified probed method name
@com.sun.btrace.annotations.Duration annotation can be used to mark an argument to hold the duration of the method call in nanoseconds. The argument must be a long. Use with Kind.RETURN or Kind.ERROR locations.
@com.sun.btrace.annotations.Duration 用于记录被跟踪方法的执行时长,单位为纳秒。被修饰的参数必须是long型,配合Kind.RETURN 或者 Kind.ERROR 使用.
@com.sun.btrace.annotations.TargetInstance (since 1.1) annotation can be used to mark an argument to hold the called instance value. Refer to the sample AllCalls2.java
@com.sun.btrace.annotations.TargetMethodOrField (since 1.1) can be used to mark an argument to hold the called method name. Refer to the samples AllCalls1.java or AllCalls2.java
since 1.2 it accepts boolean parameter fqn to get a fully qualified target method name
Unannotated arguments

The unannotated BTrace probe method arguments are used for the signature matching and therefore they must appear in the order they are defined in the traced method. However, they can be interleaved with any number of annotated arguments. If an argument of type *AnyType[]* is used it will "eat" all the rest of the arguments in they order. The exact meaning of the unannotated arguments depends on the Location used:
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
Field Annotations

@com.sun.btrace.annotations.Export annotation can be used with BTrace fields (static fields) to specify that the field has to be mapped to a jvmstat counter. Using this, a BTrace program can expose tracing counters to external jvmstat clients (such as jstat). Refer to the sample ThreadCounter.java
@com.sun.btrace.annotations.Property annotation can be used to flag a specific (static) field as a MBean attribute. If a BTrace class has atleast one static field with @Property attribute, then a MBean is created and registered with platform MBean server. JMX clients such as VisualVM, jconsole can be used to view such BTrace MBeans. After attaching BTrace to the target program, you can attach VisualVM or jconsole to the same program and view the newly created BTrace MBean. With VisualVM and jconsole, you can use MBeans tab to view the BTrace domain and check out it's attributes. Refer to the samples ThreadCounterBean.java and HistogramBean.java.
@com.sun.btrace.annotations.TLS annotation can be used with BTrace fields (static fields) to specify that the field is a thread local field. Please, be aware that you can not access such marked fields in other than @OnMethod handlers. Each Java thread gets a separate "copy" of the field. In order for this to work correctly the field type must be eitherimmutable (eg. primitives) or cloneable (implements Cloneable interface and overrides clone() method).These thread local fields may be used by BTrace programs to identify whether we reached multiple probe actions from the same thread or not. Refer to the samples OnThrow.java and WebServiceTracker.java
Class Annotations

@com.sun.btrace.annotations.DTrace annotation can be used to associate a simple one-liner D-script (inlined in BTrace Java class) with the BTrace program. Refer to the sample DTraceInline.java.
@com.sun.btrace.annotations.DTraceRef annotation can be used to associate a D-script (stored in a separate file) with the BTrace program. Refer to the sample DTraceRefDemo.java.
@com.sun.btrace.annotations.BTrace annotation must be used to designate a given Java class as a BTrace program. This annotation is enforced by the BTrace compiler as well as by the BTrace agent.
分享到:
评论

相关推荐

    jakarta.annotation-api-1.3.5-API文档-中文版.zip

    包含翻译后的API文档:jakarta.annotation-api-1.3.5-javadoc-API文档-中文(简体)版.zip; Maven坐标:jakarta.annotation:jakarta.annotation-api:1.3.5; 标签:annotation、api、jakarta、jar包、java、中文文档...

    javax.annotation-api-1.2-API文档-中文版.zip

    包含翻译后的API文档:javax.annotation-api-1.2-javadoc-API文档-中文(简体)版.zip; Maven坐标:javax.annotation:javax.annotation-api:1.2; 标签:annotation、javax、api、jar包、java、中文文档; 使用方法:...

    jakarta.annotation-api-1.3.5-API文档-中英对照版.zip

    包含翻译后的API文档:jakarta.annotation-api-1.3.5-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:jakarta.annotation:jakarta.annotation-api:1.3.5; 标签:annotation、api、jakarta、jar包、java...

    javax.annotation-api-1.3.2-API文档-中文版.zip

    包含翻译后的API文档:javax.annotation-api-1.3.2-javadoc-API文档-中文(简体)版.zip; Maven坐标:javax.annotation:javax.annotation-api:1.3.2; 标签:annotation、javax、api、jar包、java、API文档、中文版;...

    geronimo-annotation_1.0_spec-1.1.1-API文档-中文版.zip

    包含翻译后的API文档:geronimo-annotation_1.0_spec-1.1.1-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.apache.geronimo.specs:geronimo-annotation_1.0_spec:1.1.1; 标签:annotation_1、specs、apache、...

    Annotation手册

    7. **元Annotation**:元Annotation是用于定义其他Annotation的Annotation,例如`@Retention`定义Annotation的生命周期(编译时、类加载时或运行时),`@Target`指定Annotation可以应用到哪些程序元素,`@Documented...

    annotation-1.1.0.jar

    @androidx.annotation.NonNull 缺失的兼容、androidx.annotation兼容包

    mybatis-plus-annotation-3.2.0-API文档-中英对照版.zip

    包含翻译后的API文档:mybatis-plus-annotation-3.2.0-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:com.baomidou:mybatis-plus-annotation:3.2.0; 标签:baomidou、mybatis、plus、annotation、中英...

    annotation的jar包

    javax.annotation-3.0.jar javax.annotation-3.0.jar javax.annotation-3.0.jar

    Annotation详细介绍(大全)

    在代码中使用Annotation就像添加注解一样简单,例如`@MyDefaultAnnotationNoneParam`,将其添加到类、方法、变量等声明前,表示这个元素携带了特定的元信息。 3. **设置参数**: Annotation可以有参数,如`value...

    自定义的Annotation

    在iOS开发中,Annotation是苹果地图(MapKit)框架中的一个重要概念,用于在地图上添加可视化标记,以展示特定地理位置的信息。自定义的Annotation则允许开发者根据需求个性化地图上的标注,比如添加图片、自定义...

    annotation

    这个简单的注解定义了一个名为`MyAnnotation`的注解,它有一个默认值为空字符串的成员变量`value`。在实际使用时,我们可以给这个成员赋值,或者直接使用默认值。 接下来,`AnnatationTest.java`可能是用于测试注解...

    Annotation技术

    【Annotation技术】是Java语言中的一个重要特性,引入于JDK5,主要目的是为程序元素(如包、类、方法、变量等)添加元数据,即附加信息,这些信息可以被编译器、IDE工具或者运行时系统使用。Annotation不会直接改变...

    用Annotation简化Java程序的开发(PDF)

    ### 用Annotation简化Java程序的开发 #### 一、引言 随着软件开发技术的不断发展,特别是Java语言的广泛应用,开发者面临着如何有效地管理和配置代码的问题。传统的做法是使用XML文件来配置程序的各种设置,但这种...

    JAVA 标注annotation

    Java annotation 什么是java annotation?annotation 的7种标注类型。nnotation提供了一条与程序元素关联任何信息或者任何元数据(metadata)的途径。从某些方面看,annotation就像修饰符一样被使用,并应用于包、...

    jar包_javax.annotation.zip

    装配Bean则是指在IoC容器中配置和实例化Bean的过程,Bean是IoC容器管理的对象,它们可以是简单的Java对象,也可以是复杂的服务组件。 在Java EE环境中,Bean装配通常通过XML配置文件、注解或者编程方式来完成。而在...

    javax.annotation-api-1.2-API文档-中英对照版.zip

    包含翻译后的API文档:javax.annotation-api-1.2-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:javax.annotation:javax.annotation-api:1.2; 标签:annotation、javax、api、jar包、java、API文档、...

    javax.annotation.jar

    javax.annotation.jar

    Hibernate Annotation jar

    这里面包涵了需要用Hibernate Annotation时,所需要的所有jar包! 现在我们公司在做web项目的时候,已经不用*.hbm.xml这种映射文件了,都是用Annotation(注解)方式来完成实体与表之间的映射关系,这样看起来比用...

Global site tag (gtag.js) - Google Analytics