Dynamic Tracking of Java code execution status tool-btrace

Source: Internet
Author: User

We strongly recommend the btrace tool. Once used, we have to say that it is too powerful. btrace can simply be used without modifying the current program, the runtime monitors the execution status of Java programs, such as monitoring the memory status and method calls. There are many detailed examples on the official website, the following is a simple example to describe its function.
For more information about Guide, see http://kenai.com/projects/btrace/pages/userguide.
For a running Java program, especially a program with a problem, you need to track its execution status, such as the input parameter, execution time, and returned object, if any exception is thrown, the traditional method is to modify the program and add a bunch of logs. An example is provided to show the situation where btrace is used, how to track the execution time of a method:
@ Btrace public class methodresponsetime {

@ TLS Private Static long starttime;

@ Onmethod (clazz = "Class Name", method = "method name ")
Public static void oncall (){
Println ("enter this method ");
Starttime = timemillis ();
}

@ Onmethod (clazz = "Class Name", method = "method name", location = @ location (kind. Return ))
Public static void onreturn (){
Println ("method end! ");
Println (strcat ("time taken ms", STR (timemillis ()-starttime )));
}

}


With btrace, You can dynamically monitor the execution time of a certain method in any currently running Java program. The method for executing the above Code is as follows (JDK 6 + ):
Btrace [pid] methodresponsetime. Class

For example, to obtain the call parameters, the caller's object instance, and the return value, see user guide.

Btrace imposes many restrictions to ensure the security of JVM operations, such as not throwing exceptions, modifying input parameter values, and modifying return values, it is basically a read-only tool for dynamically analyzing the code running status, but it is still very useful. Its implementation mechanism is attach.
API + ASM + instrumentation.

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.