概述
Arathas是阿里开源的一个JVM监控工具,可以实时在线排查jvm的问题,官网:https://github.com/alibaba/arthas
现在遇到一个问题,想知道一个方法的每秒执行次数,java自带的那些命令都无法实现,所以找到了这个神器,我们来看看他是怎么用的。
monitor/watch/trace - related
Attention: commands here are taking advantage of byte-code-injection, which means we are injecting some aspects into the current classes for monitoring and statistics purpose. Therefore when use it for online troubleshooting in your production environment, you’d better explicitly specify classes/methods/criteria, and remember to remove the injected code by shutdown or reset.
- monitor - monitor method execution statistics
- watch - display the input/output parameter, return object, and thrown exception of specified method invocation
- trace - trace the execution time of specified method invocation
- stack - display the stack trace for the specified class and method
- tt - time tunnel, record the arguments and returned value for the methods and replay
我这里使用了monitor命令,这是它的使用说明:
monitor
Monitor method invocation.
Monitor invocation for the method matched with class-pattern and method-pattern.
monitor is not a command returning immediately.
A command returning immediately is a command immediately returns with the result after the command is input, while a non-immediate returning command will keep outputting the information from the target JVM process until user presses Ctrl+C.
On Arthas’s server side, the command is running as a background job, but the weaved code will not take further effect once the job is terminated, therefore, it will not impact the performance after the job quits. Furthermore, Arthas is designed to have no side effect to the business logic.
Items to monitor
Item | Specification |
---|---|
timestamp | timestamp |
class | Java class |
method | method (constructor and regular methods) |
total | calling times |
success | success count |
fail | failure count |
rt | average RT |
fail-rate | failure ratio |
Parameters
Parameter [c:] stands for cycles of statistics. Its value is an integer value in seconds.
Name | Specification |
---|---|
class-pattern | pattern for the class name |
method-pattern | pattern for the method name |
[E] | turn on regex matching while the default is wildcard matching |
[c:] | cycle of statistics, the default value: 120 s |
-c参数就是统计周期,默认是120s
E表示使用正则表达式,默认是通配符匹配
Usage
$ monitor -c 5 demo.MathGame primeFactors
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 94 ms.
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:38 demo.MathGame primeFactors 5 1 4 1.15 80.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:43 demo.MathGame primeFactors 5 3 2 42.29 40.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:48 demo.MathGame primeFactors 5 3 2 67.92 40.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:53 demo.MathGame primeFactors 5 2 3 0.25 60.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:06:58 demo.MathGame primeFactors 1 1 0 0.45 0.00%
timestamp class method total success fail avg-rt(ms) fail-rate
-----------------------------------------------------------------------------------------------
2018-12-03 19:07:03 demo.MathGame primeFactors 2 2 0 3182.72 0.00%
1.通配符(wildcard)就是万用牌的意思
* 表示匹配任意长度的任意字符
? 表示匹配一个任意字符
[…]则表示匹配括号中列出的字符中的任意一个
[!..]表示不匹配括号中列出的字符中的任意一个
2.正则表达式(regular expression)一种字符串匹配模式标准
2.1.集合符号[]
[abc] 字符集合(a、b或z)
[^abc] 负值字符集合 (任何字符, 除了abc)
2.2.常用元字符
^ 匹配字符串的开始
$ 匹配字符串的结束
b 匹配单词的开始或结束
2.3.常用限定符{}
{n} 重复n次
{n,} 重复n次或更多次
{n,m} 重复n到m次,
2.4.贪婪和懒惰{}?
{n,m}? 重复n到m次,但尽可能少重复
{n,}? 重复n次以上,但尽可能少重复
最后
以上就是端庄凉面为你收集整理的是Arthas找到热点代码monitor的全部内容,希望文章能够帮你解决是Arthas找到热点代码monitor所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复