(RPM) Btrace use __java

Source: Internet
Author: User
Tags instance method
Btrace is a secure tool that can dynamically track Java programs. His actions do not affect existing Java processes, do not close running Java processes, and do not modify the logic and data in the Java process. Therefore, also become our online tracking Production code powerful tools!

Btrace just heard about it before, but it hasn't been used in concrete. Recently in the troubleshooting online problems, the use of Btrace, found Btrace really in the key point of the weapon.

Btrace is a secure tool that can dynamically track Java programs.

His actions do not affect existing Java processes, do not close running Java processes, and do not modify the logic and data in the Java process.

Therefore, also become our online tracking Production code powerful tools!

Btrace scripting is also very simple: the same as writing Java code, so for us, the learning curve is almost flat.

Let's share some of the Btrace usage:

How to use Btrace

Basic usage: Trace

Where Btrace is the command in the Btrace download package, the PID is the process ID of the JVM, and Btrace-script is the Btrace script written.

some concepts in the Btrace

Probe point: Focus. is to focus on the "place" in the application, or the occurrence of some "events".

Trace Action: The action we want to perform when probe point is triggered.

Action Methods: Our trace action is written in a static method of a class, which is the static method.

Some of the limitations in Btrace:

Btrace's intention was to "trace the code" rather than modify the code, so he wanted to make sure that the script we injected was secure and "read-only" for the application. That is, the application's code or data cannot be modified. Therefore, there are some limitations in Btrace, mainly:

Cannot create new object

You can't throw an exception.

Cannot catch exception

Instance methods and static methods cannot be invoked. You can only invoke methods in the com.sun.btrace.BTraceUtils provided by Btrace and the methods that you define in your script.

Can't have loops

There's no assertion.

......

At first glance, there seems to be a lot of restrictions. However, Com.sun.btrace.BTraceUtils offers a lot of ways to "track" the Code. Also, these restrictions are necessary because we're just going to the JVM to look at it.

A simple example of a Btrace script is actually Java code

which

Where the class name needs to be added @Btrace annotation to indicate that it is Btrace script

Onmethod represents a probe point, which means that the Func method is triggered when the method that executes to the Java.awt.Component class (this is the Component build method) is executed.

@Self represents the reference to this instantiated Component

@OnTimer indicates that the event (through time) triggers the probe point, which fires once every 2 seconds

Believe that the program does not have to do too much explanation, we all know that the terminal will print out from the start of the tracking, Component is instantiated number.

Supported Trace Types

There are a number of tracking types supported by Btrace, including those that can be tracked:

A trigger that tracks to an instance method

Trace to a trigger of an interface method

Trace to the parameter of the triggering method, return value

The currently triggered thread stack can be printed

Setting can also track which line of code in a method is executed to the

Btrace's User Guide

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

on the principle of Btrace

Details can be seen: http://victorzhzh.javaeye.com/blog/965789

when do you use Btrace?

Although Btrace can play a rapid role in the critical time, but I personally feel that this is not the last resort to use the good.

First of all, before we go online, we should be fully review and communicate with relevant parties to avoid unnecessary problems.

Secondly, we should develop a good habit of remembering log. Encountered problems, if the relevant log can be checked, is the most convenient, at the same time, but also the safest, the lowest cost of a method of troubleshooting.

Finally, we can combine btrace and JDK with the tool to troubleshoot problems, such as Jstack, Jstat, and so on, fast positioning problems.

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.