diff --git a/README.html b/README.html index edf96fce8..822a3c50c 100644 --- a/README.html +++ b/README.html @@ -91,7 +91,7 @@
通过select功能选择attach的进程。
正常情况下,每次执行as.sh/arthas-boot.jar需要选择,或者指定PID。这样会比较麻烦,因为每次启动应用,它的PID会变化。
比如,已经启动了arthas-demo.jar,使用jps命令查看:
$ jps
+58883 arthas-demo.jar
+58884 Jps通过select参数可以指定进程名字,非常方便。
$ ./as.sh --select arthas-demo
+Arthas script version: 3.3.6
+[INFO] JAVA_HOME: /tmp/java/8.0.222-zulu
+Arthas home: /Users/admin/.arthas/lib/3.3.6/arthas
+Calculating attach execution time...
+Attaching to 59161 using version /Users/admin/.arthas/lib/3.3.6/arthas...
+
+real 0m0.572s
+user 0m0.281s
+sys 0m0.039s
+Attach success.
+telnet connecting to arthas server... current timestamp is 1594280799
+Trying 127.0.0.1...
+Connected to localhost.
+Escape character is '^]'.
+ ,---. ,------. ,--------.,--. ,--. ,---. ,---.
+ / O \ | .--. ''--. .--'| '--' | / O \ ' .-'
+| .-. || '--'.' | | | .--. || .-. |`. `-.
+| | | || |\ \ | | | | | || | | |.-' |
+`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'
+
+wiki https://alibaba.github.io/arthas
+tutorials https://alibaba.github.io/arthas/arthas-tutorials
+version 3.3.6
+pid 58883在3.1.4版本后,增加了用户数据回报功能,方便统一做安全或者历史数据统计。
Select the process to be attached via the select option.
Normally, as.sh/arthas-boot.jar needs to a pid, bacause the pid will change.
For example, with arthas-demo.jar already started, use the jps command to see.
$ jps
+58883 arthas-demo.jar
+58884 JpsThe select option allows you to specify a process name, which is very convenient.
$ ./as.sh --select arthas-demo
+Arthas script version: 3.3.6
+[INFO] JAVA_HOME: /tmp/java/8.0.222-zulu
+Arthas home: /Users/admin/.arthas/lib/3.3.6/arthas
+Calculating attach execution time...
+Attaching to 59161 using version /Users/admin/.arthas/lib/3.3.6/arthas...
+
+real 0m0.572s
+user 0m0.281s
+sys 0m0.039s
+Attach success.
+telnet connecting to arthas server... current timestamp is 1594280799
+Trying 127.0.0.1...
+Connected to localhost.
+Escape character is '^]'.
+ ,---. ,------. ,--------.,--. ,--. ,---. ,---.
+ / O \ | .--. ''--. .--'| '--' | / O \ ' .-'
+| .-. || '--'.' | | | .--. || .-. |`. `-.
+| | | || |\ \ | | | | | || | | |.-' |
+`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'
+
+wiki https://alibaba.github.io/arthas
+tutorials https://alibaba.github.io/arthas/arthas-tutorials
+version 3.3.6
+pid 58883After the 3.1.4 version, arthas support user data report.
trace is handy to help discovering and locating the performance flaws in your system, but pls. note Arthas can only trace the first level method call each time.
After version 3.3.0, you can use the Dynamic Trace feature to add new matching classes/methods, see the following example.
Start arthas-demo in Quick Start.
$ trace demo.MathGame run
Press Q or Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 28 ms.
@@ -300,7 +302,7 @@ Affect(class-cnt:1 , method-cnt:1) cost in 28 ms.
If the method invoked many times, use -n options to specify trace times. For example, the command will exit when received a trace result.
$ trace demo.MathGame run -n 1
Press Q or Ctrl+C to abort.
@@ -368,12 +370,51 @@ Affect(class-cnt:1 , method-cnt:1) cost in 41 ms.
The trace command will only trace the subcalls in the method to the trace, and will not trace down multiple layers. Because traces are expensive, multi-layer traces can lead to a lot of classes and methods that ultimately have to be traced.
You can use the regular expression to match multiple classes and methods on the path to achieve a multi-layer trace effect to some extent.
Trace -E com.test.ClassA|org.test.ClassB method1|method2|method3++Supported since version 3.3.0.
+
Open terminal 1, trace the run method, and you can see the printout listenerId: 1 .
[arthas@59161]$ trace demo.MathGame run
+Press Q or Ctrl+C to abort.
+Affect(class count: 1 , method count: 1) cost in 112 ms, listenerId: 1
+`---ts=2020-07-09 16:48:11;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
+ `---[1.389634ms] demo.MathGame:run()
+ `---[0.123934ms] demo.MathGame:primeFactors() #24 [throws Exception]
+
+`---ts=2020-07-09 16:48:12;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
+ `---[3.716391ms] demo.MathGame:run()
+ +---[3.182813ms] demo.MathGame:primeFactors() #24
+ `---[0.167786ms] demo.MathGame:print() #25Now to drill down into the sub method primeFactors, you can open a new terminal 2 and use the telnet localhost 3658 connects to the arthas, then trace primeFactors with the specify listenerId.
[arthas@59161]$ trace demo.MathGame primeFactors --listenerId 1
+Press Q or Ctrl+C to abort.
+Affect(class count: 1 , method count: 1) cost in 34 ms, listenerId: 1At Terminal 2 prints the results, indicating that a method has been enhanced: Affect(class count: 1 , method count: 1), but no more results are printed.
At terminal 1, you can see that the trace result has increased by one layer:
+`---ts=2020-07-09 16:49:29;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
+ `---[0.492551ms] demo.MathGame:run()
+ `---[0.113929ms] demo.MathGame:primeFactors() #24 [throws Exception]
+ `---[0.061462ms] demo.MathGame:primeFactors()
+ `---[0.001018ms] throw:java.lang.IllegalArgumentException() #46
+
+`---ts=2020-07-09 16:49:30;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
+ `---[0.409446ms] demo.MathGame:run()
+ +---[0.232606ms] demo.MathGame:primeFactors() #24
+ | `---[0.1294ms] demo.MathGame:primeFactors()
+ `---[0.084025ms] demo.MathGame:print() #25Dynamic trace by specifying listenerId, you can go deeper and deeper. In addition, commands such as watch/tt/monitor also support similar functionality.
trace 能方便的帮助你定位和发现因 RT 高而导致的性能问题缺陷,但其每次只能跟踪一级方法的调用链路。
参考:Trace命令的实现原理
+3.3.0 版本后,可以使用动态Trace功能,不断增加新的匹配类,参考下面的示例。
3.3.0 版本后支持。
+打开终端1,trace run函数,可以看到打印出 listenerId: 1:
[arthas@59161]$ trace demo.MathGame run
+Press Q or Ctrl+C to abort.
+Affect(class count: 1 , method count: 1) cost in 112 ms, listenerId: 1
+`---ts=2020-07-09 16:48:11;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
+ `---[1.389634ms] demo.MathGame:run()
+ `---[0.123934ms] demo.MathGame:primeFactors() #24 [throws Exception]
+
+`---ts=2020-07-09 16:48:12;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
+ `---[3.716391ms] demo.MathGame:run()
+ +---[3.182813ms] demo.MathGame:primeFactors() #24
+ `---[0.167786ms] demo.MathGame:print() #25现在想要深入子函数primeFactors,可以打开一个新终端2,使用telnet localhost 3658连接上arthas,再trace primeFactors时,指定listenerId。
[arthas@59161]$ trace demo.MathGame primeFactors --listenerId 1
+Press Q or Ctrl+C to abort.
+Affect(class count: 1 , method count: 1) cost in 34 ms, listenerId: 1这时终端2打印的结果,说明已经增强了一个函数:Affect(class count: 1 , method count: 1),但不再打印更多的结果。
再查看终端1,可以发现trace的结果增加了一层,打印了primeFactors函数里的内容:
`---ts=2020-07-09 16:49:29;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
+ `---[0.492551ms] demo.MathGame:run()
+ `---[0.113929ms] demo.MathGame:primeFactors() #24 [throws Exception]
+ `---[0.061462ms] demo.MathGame:primeFactors()
+ `---[0.001018ms] throw:java.lang.IllegalArgumentException() #46
+
+`---ts=2020-07-09 16:49:30;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
+ `---[0.409446ms] demo.MathGame:run()
+ +---[0.232606ms] demo.MathGame:primeFactors() #24
+ | `---[0.1294ms] demo.MathGame:primeFactors()
+ `---[0.084025ms] demo.MathGame:print() #25通过指定listenerId的方式动态trace,可以不断深入。另外 watch/tt/monitor等命令也支持类似的功能。