In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the online troubleshooting of the sharp weapon Btrace how to use, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.
Btrace is a secure tool that can dynamically track java programs.
His actions will not affect the original java process, do not have to shut down the running java process, and will not modify the logic and data in the java process.
Therefore, it has become a powerful tool for us to track production code online!
Btrace's scripting is also very simple: it's the same as writing Java code, so for us, the learning curve is almost flat.
Here are some uses of Btrace:
How to use Btrace
Basic usage: trace
Where btrace is the command in the btrace download package, pid is the process id of JVM, and btrace-script is the btrace script written.
Some concepts in Btrace
Probe Point: focus. That is, we need to focus on the "place" in the application, or the occurrence of some "events".
Trace Action: that's what we're going to do when probe point is triggered.
Action Methods: our trace action is written in the static method of a class, which is action method.
Some limitations in Btrace:
Btrace's original intention is to "track the code", not to modify it, so he wants to make sure that the script we inject is safe and "read-only" for the application. In other words, the code or data of the application cannot be modified. Therefore, there are some limitations in Btrace, mainly as follows:
Cannot create new object
Cannot throw exception
Cannot catch exception
Instance methods and static methods cannot be called. You can only call methods in the com.sun.btrace.BTraceUtils provided by Btrace and the methods you define in the script.
There can be no cycle
There can be no assertions
……
At first glance, it seems that there are many restrictions. However, com.sun.btrace.BTraceUtils provides many ways to "track" the code. Moreover, these restrictions are also necessary, because we are just going to that JVM to have a look.
A simple example of a Btrace script is actually Java code
Where:
The class name needs to be annotated with @ Btrace to indicate that it is a Btrace script
OnMethod represents a probe point, which means that the func method is triggered when the method of the class java.awt.Component (this is the build method of Component) is executed.
@ Self represents a reference to this instantiated Component
@ OnTimer represents the probe point triggered by the event (through time), triggered every 2 seconds
I believe that the program does not need to explain too much, as we all know, the terminal will print out the number of Component instantiated from the beginning of the trace.
Supported trace types
There are many trace types supported by Btrace, including the ability to trace:
Trace to the trigger of an instance method
Trace to the trigger of an interface method
Trace the parameters of the trigger method and return the value
The currently triggered thread stack can be printed out.
Sets which line of code in a method can also be tracked to the
User Guide of Btrace
Http://kenai.com/projects/btrace/pages/UserGuide
When to use Btrace
Although Btrace can play a role in troubleshooting problems quickly at critical times, I personally feel that it is better to use it as a last resort.
First of all, before our code goes online, we should fully review and fully communicate with the relevant parties to avoid unnecessary problems.
Secondly, we should form the good habit of memorizing log. If you encounter problems, it is the most convenient and the safest and most cost-effective way to troubleshoot if there are relevant logs.
*, we can use btrace and jdk's own tool to troubleshoot problems, such as jstack, jstat, etc., to quickly locate problems.
Thank you for reading this article carefully. I hope the article "how to use Btrace for online troubleshooting" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.