Btrace Practice Notes

Source: Internet
Author: User

Btrace Introduction:Btrace is a secure, dynamic tracking tool that is used on top of the Java platform.    It is typically used to dynamically track a running Java program. Instructions for use here.    Over here. Note The version issue when downloading, I originally downloaded the version of release-1.2.3, then the Java version on the server is 1.6.0_32. The error was reported at the time of operation. [Java] Java.lang.unsupportedclassversionerror[/java] This is because the JDK version of the compiled release-1.2.3 is higher than 1.6.0_32, but it runs on the lower version of the JVM, So I will report this error, and then I downloaded the release-1.2.2 version without this problem. btrace Installation:Btrace actually do not need to install, unzip directly, and then add the bin directory to the path, and set Btrace_home to extract the directory, and then you can perform the Btrace command test. Btrace Practice StepsFirst find the PID of the running Java program (which will be used later).
Ps-a|grep Java



Then create the script: for example Traceobject.java

?
Import Staticcom.sun.btrace.btraceutils.*;Importcom.sun.btrace.annotations.*; @BTrace Public classtraceobject{@TLSStatic LongbeginTime; @OnMethod (Clazz= "Com.task.CheckTask", Method= "GetItem") Public Static voidTracebegin () {beginTime=Timemillis ();} @OnMethod (Clazz= "Com.task.CheckTask", Method= "GetItem", location=@Location (Kind.return)) Public Static voidTraceLongitemId, @Return Object result) {println ("---------Start-------------");p rintln (strcat ("ItemId:", str (itemId))); println (strcat ("Result itemname:", str (Get (Field ("Com.info.ItemInfoDO", "Itemidstr", result)));p rintln (strcat (sizeof (Result)),"Bytes"));p rintln (strcat (strcat ("Execute time is:", str (Timemillis ()-begintime)), "MS"));p rintln ("Method Stack:"); Jstack ();p rintln ("---------End-------------");}}

The main function of this script is to monitor what the checktask of the GetItem method of the object of this class is, what the return value is, how many bytes the return value is (just the byte of the object, not the size of the object that points to the object). And the call heap for this method, and the run time of this method.

Briefly introduce the following notes: @OnMethod Specify the class name and method that need to be tracked dynamically, where the Location property indicates whether the monitor is monitored before the method is executed, or after it is executed, the default is to execute the method before the[email protected](Kind.return). @TLS TLS is used to specify the static properties of Btrace as thread-local properties. In addition the Itemid of the trace method is the GetItem method's entry, and result is the return value of GetItem.
Run

You can see the results. Of course, there are other uses of btrace. Refer to the example in User Guide. Profile: http://rdc.taobao.com/team/jm/archives/509 btrace usage ProfileHttps://kenai.com/projects/btrace/pages/UserGuide Userguide

Btrace Practice Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.