是Arthas找到热点代码

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

ItemSpecification
timestamptimestamp
classJava class
methodmethod (constructor and regular methods)
totalcalling times
successsuccess count
failfailure count
rtaverage RT
fail-ratefailure ratio

Parameters

Parameter [c:] stands for cycles of statistics. Its value is an integer value in seconds.

NameSpecification
class-patternpattern for the class name
method-patternpattern for the method name
[E]turn on regex matching while the default is wildcard matching
[c:]cycle of statistics, the default value: 120s

     -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次以上,但尽可能少重复
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值