Merge pull request #1 from alibaba/master

merge
This commit is contained in:
bohr 2018-09-21 11:30:29 +08:00 committed by GitHub
commit 2d416eab3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 1124 additions and 48 deletions

View File

@ -0,0 +1,34 @@
---
name: Bug report (EN)
about: If you would like to report a issue to Arthas, please use this template.
---
- [ ] I have searched the [issues](https://github.com/alibaba/arthas/issues) of this repository and believe that this is not a duplicate.
### Environment
* Arthas version: xxx
* Operating System version: xxx
* Java version of target JVM: xxx
* Java version of JVM used to attach: xxx
### Steps to reproduce this issue
1. xxx
2. xxx
3. xxx
### Expected Result
What do you expected from the above steps
### Actual Result
What actually happens?
If there is an exception, please attach the exception trace:
```
Just put your stack trace here!
```

View File

@ -15,7 +15,7 @@
## 开发者相关
编绎要求jdk7以上。因为使用到了jdk7才有的`java.lang.management.BufferPoolMXBea`运行时要求是jdk6。
编绎要求jdk7以上。因为使用到了jdk7才有的`java.lang.management.BufferPoolMXBean`运行时要求是jdk6。
### 安装到本地

View File

@ -672,3 +672,8 @@ may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
This product contains a modified version of greys-anatomy, which is
available under a GNU General Public License 3 (GPLv3) license. For details,
see https://github.com/oldmanpushcart/greys-anatomy.

12
NOTICE Normal file
View File

@ -0,0 +1,12 @@
Arthas
Copyright 2018 Alibaba Group
This product includes software developed at
Alibaba Group (https://www.alibabagroup.com/en/global/home).
This product contains code form the greys-anatomy Project:
The greys-anatomy Project
=================
Please visit Github for more information:
* https://github.com/oldmanpushcart/greys-anatomy

View File

@ -59,11 +59,11 @@ Start Arthas:
English version is on the way, if you would like to contribute, please leave a message [here](https://github.com/alibaba/arthas/issues/51)
* [User manual](https://alibaba.github.io/arthas/)
* [Installation](https://alibaba.github.io/arthas/install-detail.html)
* [Quick start](https://alibaba.github.io/arthas/quick-start.html)
* [Advanced usage](https://alibaba.github.io/arthas/advanced-use.html)
* [Questions and answers](https://github.com/alibaba/arthas/labels/question-answered)
* [User manual](https://alibaba.github.io/arthas/en)
* [Installation](https://alibaba.github.io/arthas/en/install-detail.html)
* [Quick start](https://alibaba.github.io/arthas/en/quick-start.html)
* [Advanced usage](https://alibaba.github.io/arthas/en/advanced-use.html)
* [Questions and answers](https://github.com/alibaba/arthas/issues?utf8=%E2%9C%93&q=label%3Aquestion-answered+)
* [How to contribute](https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md)
@ -300,3 +300,11 @@ $ classloader
* https://alibaba.github.io/arthas/web-console
![web console](site/src/site/sphinx/_static/web-console-local.png)
### Credit
* [greys-anatomy](https://github.com/oldmanpushcart/greys-anatomy): The Arthas code base has derived from Greys, we thank for the excellent work done by Greys.
* [termd](https://github.com/termd/termd): Arthas's termnial implementation is based on termd, an open source library for writing terminal applications in Java.
* [crash](https://github.com/crashub/crash): Arthas's text based user interface rendering is based on codes extracted from [here](https://github.com/crashub/crash/tree/1.3.2/shell)
* [cli](https://github.com/eclipse-vertx/vert.x/tree/master/src/main/java/io/vertx/core/cli): Arthas's command line interface implementation is based on cli, open sourced by vert.x

View File

@ -54,7 +54,7 @@ curl -L https://alibaba.github.io/arthas/install.sh | sh
* [安装](https://alibaba.github.io/arthas/install-detail.html)
* [快速入门](https://alibaba.github.io/arthas/quick-start.html)
* [进阶使用](https://alibaba.github.io/arthas/advanced-use.html)
* [Questions and answers](https://github.com/alibaba/arthas/labels/question-answered)
* [Q&A](https://github.com/alibaba/arthas/issues?utf8=%E2%9C%93&q=label%3Aquestion-answered+)
* [参与贡献](https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md)
@ -295,3 +295,11 @@ $ classloader
![web console](site/src/site/sphinx/_static/web-console-local.png)
### Credit
* [greys-anatomy](https://github.com/oldmanpushcart/greys-anatomy): Arthas代码基于Greys二次开发而来非常感谢Greys之前所有的工作以及Greys原作者对Arthas提出的意见和建议
* [termd](https://github.com/termd/termd): Arthas的命令行实现基于termd开发是一款优秀的命令行程序开发框架感谢termd提供了优秀的框架。
* [crash](https://github.com/crashub/crash): Arthas的文本渲染功能基于crash中的文本渲染功能开发可以从[这里](https://github.com/crashub/crash/tree/1.3.2/shell)看到源码感谢crash在这方面所做的优秀工作。
* [cli](https://github.com/eclipse-vertx/vert.x/tree/master/src/main/java/io/vertx/core/cli): Arthas的命令行界面基于vert.x提供的cli库进行开发感谢vert.x在这方面做的优秀工作。

View File

@ -53,7 +53,7 @@ uptime 16020s busy
* STATE: 线程的状态
* CPU%: 线程消耗的cpu占比采样100ms将所有线程在这100ms内的cpu使用量求和再算出每个线程的cpu使用占比。
* TIME: 线程运行总时间,数据格式为`分:秒`
* INTERRUPTE: 线程当前的中断位状态
* INTERRUPTED: 线程当前的中断位状态
* DAEMON: 是否是daemon线程
### 截图展示

View File

@ -0,0 +1,129 @@
classloader
===========
Check the inheritance tree, urls and classes loading profiles of the class loaders.
It can be a great help for `ResourceNotFoundException` when you can use command `classloader`to specify a class loader to `getResources` and print all the urls of the valid resources.
### Options
|Name|Specification|
|---:|:---|
|[l]|count based on the class loader instance|
|[t]|print all the inheritance structure of the class loaders|
|[a]|list all the classes loaded by all the class loaders (use it with great caution since the output can be huge)|
|`[c:]`|get the hashcode of the class loader|
|`[c: r:]`|using class loader to search resource|
### Usage
* categorised by class loader
```s
$ classloader
name numberOfInstances loadedCountTotal
com.taobao.pandora.service.loader.ModuleClassLoader 29 11659
com.taobao.pandora.boot.loader.ReLaunchURLClassLoader 1 5308
BootstrapClassLoader 1 3711
com.taobao.arthas.agent.ArthasClassloader 2 2825
sun.reflect.DelegatingClassLoader 332 332
java.net.URLClassLoader 1 285
sun.misc.Launcher$AppClassLoader 1 77
sun.misc.Launcher$ExtClassLoader 1 46
com.alibaba.fastjson.util.ASMClassLoader 2 3
org.jvnet.hk2.internal.DelegatingClassLoader 2 2
sun.reflect.misc.MethodUtil 1 1
Affect(row-cnt:11) cost in 66 ms.
```
* Categorized by class loader instance
```sh
$ classloader -l
name loadedCount hash parent
BootstrapClassLoader 3711 null null
com.alibaba.fastjson.util.ASMClassLoader@3bbaa1b8 2 3bbaa1b8 monitor's ModuleClassLoader
com.alibaba.fastjson.util.ASMClassLoader@5e255d0b 1 5e255d0b eagleeye-core's ModuleClassLoader
com.taobao.arthas.agent.ArthasClassloader@4fa2d7e6 1795 4fa2d7e6 sun.misc.Launcher$ExtClassLoader@a38d7a3
com.taobao.arthas.agent.ArthasClassloader@522400c2 1033 522400c2 sun.misc.Launcher$ExtClassLoader@a38d7a3
com.taobao.pandora.boot.loader.ReLaunchURLClassLoader@1817d444 5308 1817d444 sun.misc.Launcher$AppClassLoader@14dad5dc
tbsession's ModuleClassLoader 285 609cd4d8 null
pandora-qos-service's ModuleClassLoader 267 2f8dad04 null
pandora-framework's ModuleClassLoader 78 4009e306 null
filesync-client's ModuleClassLoader 4 4b8ee4de null
rocketmq-client's ModuleClassLoader 431 247bddad null
eagleeye-core's ModuleClassLoader 451 1ba9117e null
alimonitor-jmonitor's ModuleClassLoader 134 22fcf7ab null
metaq-client's ModuleClassLoader 35 41a2befb null
hsf-mock's ModuleClassLoader 3 2002fc1d null
monitor's ModuleClassLoader 1427 131ef10 null
spas-sdk-service's ModuleClassLoader 7 10d307f1 null
vipserver-client's ModuleClassLoader 137 7a419da4 null
metrics's ModuleClassLoader 146 696da30b null
mtop-uncenter's ModuleClassLoader 922 79d8407f null
spas-sdk-client's ModuleClassLoader 235 4944252c null
live-profiler-pandora's ModuleClassLoader 1 6913c1fb null
notify-tr-client's ModuleClassLoader 472 fba92d3 null
ons-sdk's ModuleClassLoader 70 23348b5d null
tair-plugin's ModuleClassLoader 1053 7c9d8e2 null
tddl-client's ModuleClassLoader 2354 4988d8b8 null
config-client's ModuleClassLoader 93 429bffaa null
diamond-client's ModuleClassLoader 360 3d5c822d null
pandolet's ModuleClassLoader 99 41e1e210 null
hsf's ModuleClassLoader 1796 3232a28a null
acl.plugin's ModuleClassLoader 379 67080771 null
buc.sso.client.plugin's ModuleClassLoader 195 13b6aecc null
unitrouter's ModuleClassLoader 64 7e5afaa6 null
switch's ModuleClassLoader 104 24313fcc null
hsf-notify-client's ModuleClassLoader 57 4d0f2471 null
java.net.URLClassLoader@7ec7ffd3 285 7ec7ffd3 sun.misc.Launcher$ExtClassLoader@a38d7a3
javax.management.remote.rmi.NoCallStackClassLoader@53f65459 1 53f65459 null
javax.management.remote.rmi.NoCallStackClassLoader@2833cc44 1 2833cc44 null
org.jvnet.hk2.internal.DelegatingClassLoader@72cda8ee 1 72cda8ee monitor's ModuleClassLoader
org.jvnet.hk2.internal.DelegatingClassLoader@1f57f96d 1 1f57f96d monitor's ModuleClassLoader
sun.misc.Launcher$AppClassLoader@14dad5dc 77 14dad5dc sun.misc.Launcher$ExtClassLoader@a38d7a3
sun.misc.Launcher$ExtClassLoader@a38d7a3 46 a38d7a3 null
sun.reflect.misc.MethodUtil@1201f221 1 1201f221 sun.misc.Launcher$AppClassLoader@14dad5dc
```
* Check inheritance tree of the class loaders
```shell
$ classloader -t
+-BootstrapClassLoader
+-unitrouter's ModuleClassLoader
+-diamond-client's ModuleClassLoader
+-sun.misc.Launcher$ExtClassLoader@548a102f
| +-sun.misc.Launcher$AppClassLoader@14dad5dc
| +-com.taobao.arthas.agent.AgentLauncher$1@334e6bb8
| | +-sun.reflect.DelegatingClassLoader@328b3a05
| | +-sun.reflect.DelegatingClassLoader@73f44f24
```
* Check the real urls of `URLClassLoader`
```shell
$ classloader -c 5ffe9775
file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/commons-lang-2.6.jar
file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/log4j-1.2.16.jar
file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/logger.api-0.1.4.jar
file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/pandora.api-2.0.7-SNAPSHOT.jar
file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/pandora.container-2.0.7-SNAPSHOT.jar
file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/pandora.thirdcontainer-2.0.7-SNAPSHOT.jar
file:/Users/hello/soft/taobao-tomcat-7.0.64/deploy/taobao-hsf.sar/lib/picocontainer-2.14.3.jar
```
* Using class loader to search for resource
```shell
$ classloader -c 226b143b -r META-INF/MANIFEST.MF
jar:file:/Users/hello/.m2/repository/javax/enterprise/cdi-api/1.0/cdi-api-1.0.jar!/META-INF/MANIFEST.MF
jar:file:/Users/hello/.m2/repository/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar!/META-INF/MANIFEST.MF
```
* Using class loader to look for `*.class` file
```shell
$ classloader -c 1b6d3586 -r java/lang/String.class
jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar!/java/lang/String.class
```

View File

@ -0,0 +1,37 @@
Commands List
=============
* [dashboard](dashboard.md)
* [thread](thread.md)
* [jvm](jvm.md)
* [sysprop](sysprop.md)
* [getstatic](getstatic.md)
* [sc](sc.md)
* [sm](sm.md)
* [dump](dump.md)
* [jad](jad.md)
* [classloader](classloader.md)
* [redefine](redefine.md)
* [monitor](monitor.md)
* [watch](watch.md)
* [trace](trace.md)
* [stack](stack.md)
* [tt](tt.md)
* [options](options.md)
### Arthas Basic Commands
* help - check the assistant info for the command
* cls - clear out the current screen area
* session - check the current session profile
* [reset](reset.md) - clear the injected code from the classes (B.T.W when Arthas server closed, all the injected will also be cleared)
* version - the version of the working Arthas
* quit - exit the current Arthas client without affecting other clients
* shutdown - terminate the Arthas server and all clients
* [keymap](keymap.md) - shortcuts for Arthas and also you can define your own

View File

@ -52,7 +52,7 @@ project = u'Arthas'
copyright = u'2018, Alibaba Middleware Group, and contributors'
author = u'Alibaba Middleware Group, and contributors'
github_doc_root = 'https://github.com/alibaba/arthas/tree/master/site/src/site/sphinx/en'
github_doc_root = 'https://github.com/alibaba/arthas/tree/master/site/src/site/sphinx/en/'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the

View File

@ -0,0 +1,61 @@
dashboard
=========
This is the realtime dashboard for the system; press `Ctrl+C` to exit.
When running in *Ali-tomcat*, the dashboard will present the realtime statistics of the tomcat including [QPS](https://en.wikipedia.org/wiki/Queries_per_second), RT, error counts, thread profile and the like.
### A Demo
```
$ dashboard
ID NAME GROUP PRIORITY STATE %CPU TIME INTERRUPTED DAEMON
889 RMI TCP Connection(15)-30.10.166. RMI Runtime 9 RUNNABLE 48 0:5 false true
1077 Timer-for-arthas-dashboard-0 system 9 RUNNABLE 24 0:0 false true
1074 as-selector-daemon system 9 RUNNABLE 12 0:0 false true
284 JMX server connection timeout 284 RMI Runtime 9 TIMED_WAITI 8 0:3 false true
16 Timer-1 main 5 TIMED_WAITI 5 0:9 false true
47 Pandora pandora-qos-reporter Pool main 5 TIMED_WAITI 0 0:0 false true
48 JmonitorClient-CheckThread Pool [ main 5 TIMED_WAITI 0 0:0 false true
49 JmonitorClient-HeartBeat Pool [Th main 5 TIMED_WAITI 0 0:0 false true
50 JmonitorClient-ReaderThread Pool main 5 TIMED_WAITI 0 0:0 false true
957 RMI TCP Connection(16)-30.10.166. RMI Runtime 9 RUNNABLE 0 0:2 false true
51 JmonitorClient-WriterThread Pool main 5 TIMED_WAITI 0 0:0 false true
52 ContainerBackgroundProcessor[Stan main 5 TIMED_WAITI 0 0:0 false true
53 http-bio-8080-Acceptor-0 main 5 RUNNABLE 0 0:2 false true
54 http-bio-8080-AsyncTimeout main 5 TIMED_WAITI 0 0:0 false true
11 GC Daemon system 2 TIMED_WAITI 0 0:0 false true
Memory used total max usage GC
heap 59M 223M 1820M 3.26% gc.ps_scavenge.count 118
ps_eden_space 14M 114M 668M 2.11% gc.ps_scavenge.time(ms) 1890
ps_survivor_space 6M 6M 6M 96.08% gc.ps_marksweep.count 5
ps_old_gen 39M 103M 1365M 2.86% gc.ps_marksweep.time(ms) 1140
nonheap 234M 240M 0M 97.46%
code_cache 46M 47M 240M 19.49%
metaspace 167M 172M 0M 97.36%
Runtime Tomcat
os.name Mac OS X connector http-bio-8080
os.version 10.10.5 QPS 0.00
java.version 1.8.0_60 RT(ms) 1.13
java.home error/s 0.00
received/s 0B
systemload.average 3.44 sent/s 0B
processors 4 threadpool http-bio-8080
uptime 16020s busy 0
```
### Specification
* ID: thread ID in JVM (this is different from the nativeID in thread dump)
* NAME: thread name
* GROUP: group the thread is in
* STATE: the current state of the thread
* PRIORITY: within 1 ~ 10 (the higher the number, the higher the priority)
* CPU%: CPU usage ratio within 100ms
* TIME: total running time in minute:second format
* INTERRUPTED: the thread interrupted state
* DAEMON: is daemon thread or not
### Screenshots
![alt text](../_static/dashboard.png "dashboard")

View File

@ -0,0 +1,40 @@
dump
===
Dump the bytecode the loaded classes to a specified directory.
### Options
|Name|Specification|
|---:|:---|
|*class-pattern*|pattern for the class name|
|`[c:]`|hashcode of the class loader that loaded the class|
|[E]|turn on regx matching while the default is wildcards matching|
### Usage
```shell
$ dump -E org\.apache\.commons\.lang\.StringUtils
HASHCODE CLASSLOADER LOCATION
29505d69 +-tddl-client's ModuleClassLoader /Users/zhuyong/middleware/taobao-tomcat/output/build/bin/classdump/com.taobao.pandora
.service.loader.ModuleClassLoader-29505d69/org.apache.commons.lang.StringUtils.class
6e51ad67 +-java.net.URLClassLoader@6e51ad67 /Users/zhuyong/middleware/taobao-tomcat/output/build/bin/classdump/java.net.URLClassL
+-sun.misc.Launcher$AppClassLoader@6951a712 oader-6e51ad67/org.apache.commons.lang.StringUtils.class
+-sun.misc.Launcher$ExtClassLoader@6fafc4c2
2bdd9114 +-pandora-qos-service's ModuleClassLoader /Users/zhuyong/middleware/taobao-tomcat/output/build/bin/classdump/com.taobao.pandora
.service.loader.ModuleClassLoader-2bdd9114/org.apache.commons.lang.StringUtils.class
544dc9ba +-com.taobao.tomcat.container.context.loader.AliWebappClassLoader /Users/zhuyong/middleware/taobao-tomcat/output/build/bin/classdump/com.taobao.tomcat.
+-org.apache.catalina.loader.StandardClassLoader@2302e984 container.context.loader.AliWebappClassLoader-544dc9ba/org.apache.commons.lang.String
+-sun.misc.Launcher$AppClassLoader@6951a712 Utils.class
+-sun.misc.Launcher$ExtClassLoader@6fafc4c2
22880c2b +-java.net.URLClassLoader@22880c2b /Users/zhuyong/middleware/taobao-tomcat/output/build/bin/classdump/java.net.URLClassL
+-sun.misc.Launcher$AppClassLoader@6951a712 oader-22880c2b/org.apache.commons.lang.StringUtils.class
+-sun.misc.Launcher$ExtClassLoader@6fafc4c2
Affect(row-cnt:5) cost in 156 ms.
$ dump -E org\.apache\.commons\.lang\.StringUtils -c 22880c2b
HASHCODE CLASSLOADER LOCATION
22880c2b +-java.net.URLClassLoader@22880c2b /Users/zhuyong/middleware/taobao-tomcat/output/build/bin/classdump/java.net.URLClassLoader-22880c2b/org
+-sun.misc.Launcher$AppClassLoader@6951a712 .apache.commons.lang.StringUtils.class
+-sun.misc.Launcher$ExtClassLoader@6fafc4c2
Affect(row-cnt:1) cost in 67 ms.
```

View File

@ -0,0 +1,24 @@
getstatic
=========
Check the static fields of classes conveniently as `getstatic class_name field_name`
Tip: if the *field* is a composite object, you can even use [`OGNL`](https://en.wikipedia.org/wiki/OGNL) to traverse, filter and access the internal properties of it.
E.g. suppose `n` is a `Map` and the key is a `Enum` then if you want to get the key with a specific `Enum` value - `STOP` or `a`, you can achieve it as:
```
$ getstatic com.alibaba.arthas.Test n 'entrySet().iterator.{? #this.key.name()=="STOP"}'
field: n
@ArrayList[
@Node[STOP=bbb],
]
Affect(row-cnt:1) cost in 68 ms.
$ getstatic com.alibaba.arthas.Test m 'entrySet().iterator.{? #this.key=="a"}'
field: m
@ArrayList[
@Node[a=aaa],
]
```

View File

@ -1,36 +1,49 @@
Arthas Documentation
===
## Arthas阿尔萨斯 能为你做什么?
**[中文文档/Chinese Docs](https://alibaba.github.io/arthas/)**
![arthas](arthas.png)
`Arthas` 是Alibaba开源的Java诊断工具深受开发者喜爱。
`Arthas` is an Java Diagnostic tool open sourced by Alibaba.
当你遇到以下类似问题而束手无策时,`Arthas`可以帮助你解决:
Arthas can help developer trouble-shooting production issues for Java applications without modifying your code or restating your server.
0. 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception
0. 我改的代码为什么没有执行到?难道是我没 commit分支搞错了
0. 遇到问题无法在线上 debug难道只能通过加日志再重新发布吗
0. 线上遇到某个用户的数据处理有问题,但线上同样无法 debug线下无法重现
0. 是否有一个全局视角来查看系统的运行状况?
0. 有什么办法可以监控到JVM的实时运行状态
### Background
`Arthas`采用命令行交互模式,同时提供丰富的 `Tab` 自动补全功能,进一步方便进行问题的定位和诊断。
In production system, sometimes the networks is unreachable from local development environment. If you encounter some issues in production system, it is impossible to use IDE to debug the application remotely. More importantly, debugging in production is unacceptable, because it will suspend all the threads, which leads to business unavailability.
Some may think of reproducing the same issue on the test/staging environment, however, some tricky issue either can hardly be reproduced on a different environment, or even disappeared once restarted.
Thinking of adding some logs to your code? You have to go through test, staging, and then on to production. Time is money! That is a lot inefficient! Besides, the issue may not be reproducible once restart your JVM, as described above.
Arthas is born to solve these issues. You can trouble-shoot your production issue on-the-fly. No JVM restart, no additional code changes. Arthas works as an observer, which will never suspend your existing threads.
### Key features
* Check whether a class is loaded? And whether is class loaded from? (Useful for trouble-shooting jar file conflicts)
* Decompile a class to ensure the code is running as expected.
* View classloader statistics, e.g. how may classloaders are there? how many class is loaded per classloader? What is the classloader hierarchy? Is there possible classloader leaks?
* View the method invocation details, e.g. method parameter, return object, thrown exception, and etc.
* Check the stack trace of specified method invocation. This is useful when you would like to know who is calling your method?
* Trace the method invocation to find slow sub-invocations.
* Monitor method invcation statistics, e.g. qps, rt, success rate and etc.
* Monitoring your system metrics, thread states and cpu usage, gc statistics, and etc.
* Support command line interactive mode, with auto completed feature enabled.
* Support telnet and websocket, which enables both local and remote diagnostics with command line and browsers.
Contents
--------
* [安装](install-detail.md)
* [快速入门](quick-start.md)
* [进阶使用](advanced-use.md)
* [命令列表](commands.md)
* [用户案例](https://github.com/alibaba/arthas/issues?q=label%3Auser-case)
English version is on the way, if you would like to contribute, please leave a message [here](https://github.com/alibaba/arthas/issues/51)
* [Installation](install-detail.md)
* [Quick start](quick-start.md)
* [Advanced usage](advanced-use.md)
* [Commands](commands.md)
* [User cases](https://github.com/alibaba/arthas/issues?q=label%3Auser-case)
* [Release Notes](release-notes.md)
* [Questions and answers](https://github.com/alibaba/arthas/issues?q=label%3Aquestion-answered)
* [Fork me at GitHub](https://github.com/alibaba/arthas)
* [参与贡献](https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md)
* [CONTRIBUTING](https://github.com/alibaba/arthas/blob/master/CONTRIBUTING.md)

View File

@ -40,21 +40,23 @@ If in Windows, the color is not working as expect. You can try [conemu](https://
If you cannot boot Arthas, try to pass in all the critical options manually as the following steps:
### 1. locate the java for JVM:
- Linux/Unix/Mac: `ps aux | grep java`
- Windows: open the Process Monitor to search java
1. locate the java for JVM:
### 2. Concatenate the command
Let's suppose we are using `/opt/jdk1.8/bin/java`, then the command should be:
- Linux/Unix/Mac: `ps aux | grep java`
- Windows: open the Process Monitor to search java
```bash
/opt/jdk1.8/bin/java -Xbootclasspath/a:/opt/jdk1.8/lib/tools.jar \
-jar /tmp/arthas-packaging/arthas-core.jar \
-pid 15146 \
-target-ip 127.0.0.1 -telnet-port 3658 -http-port 8563 \
-core /tmp/arthas-packaging/arthas-core.jar \
-agent /tmp/arthas-packaging/arthas/arthas-agent.jar
```
2. Concatenate the command
Let's suppose we are using `/opt/jdk1.8/bin/java`, then the command should be:
```bash
/opt/jdk1.8/bin/java -Xbootclasspath/a:/opt/jdk1.8/lib/tools.jar \
-jar /tmp/arthas-packaging/arthas-core.jar \
-pid 15146 \
-target-ip 127.0.0.1 -telnet-port 3658 -http-port 8563 \
-core /tmp/arthas-packaging/arthas-core.jar \
-agent /tmp/arthas-packaging/arthas/arthas-agent.jar
```
* `-Xbootclasspath` add tools.jar
* `-jar /tmp/arthas-packaging/arthas-core.jar` specify main entry
@ -64,17 +66,17 @@ Let's suppose we are using `/opt/jdk1.8/bin/java`, then the command should be:
* `-core /tmp/arthas-packaging/arthas-core.jar -agent /tmp/arthas-packaging/arthas/arthas-agent.jar` specify core/agent jar package
But if you are using JDK 1.9 or abovethen you do not need to add `tools.jar` in option `-Xbootclasspath`.
But if you are using JDK 1.9 or abovethen you do not need to add `tools.jar` in option `-Xbootclasspath`.
F.Y.I the booting log will be printed to `~/logs/arthas/arthas.log`.
F.Y.I the booting log will be printed to `~/logs/arthas/arthas.log`.
### 3. Connect via telnet
3. Connect via telnet
When attached successfully, you can connect it with
When attached successfully, you can connect it with
```bash
telnet localhost 3658
```
```bash
telnet localhost 3658
```
## Offline Help Documentation

View File

@ -0,0 +1,158 @@
jad
===
De-compile specified loaded classes.
`jad` helps to *de-compile* the byte code in JVM to the source code to assist you to better understand the logic behind.
F.Y.I
* the de-compiled code will be grammatically highlighted for readability in Arthas Console;
* you have to understand there might be some trivial grammar errors but it won't affect the logic understanding.
### Options
|Name|Specification|
|---:|:---|
|*class-pattern*|pattern for the class name|
|`[c:]`|hashcode of the class loader that loaded the class|
|[E]|turn on regx matching while the default is wildcards matching|
### Usage
When several class loaders loaded the same class:
1. `jad` to get the hashcode of the class loader;
2. `jad -c <hashcode>` to get the de-compiled class loaded by the class loader.
```java
$ jad org.apache.log4j.Logger
Found more than one class for: org.apache.log4j.Logger, Please use jad -c hashcode org.apache.log4j.Logger
HASHCODE CLASSLOADER
69dcaba4 +-monitor's ModuleClassLoader
6e51ad67 +-java.net.URLClassLoader@6e51ad67
+-sun.misc.Launcher$AppClassLoader@6951a712
+-sun.misc.Launcher$ExtClassLoader@6fafc4c2
2bdd9114 +-pandora-qos-service's ModuleClassLoader
4c0df5f8 +-pandora-framework's ModuleClassLoader
Affect(row-cnt:0) cost in 38 ms.
$ jad org.apache.log4j.Logger -c 69dcaba4
ClassLoader:
+-monitor's ModuleClassLoader
Location:
/Users/zhuyong/Downloads/taobao-hsf.sar/plugins/monitor/lib/log4j-1.2.14.jar
package org.apache.log4j;
import org.apache.log4j.spi.*;
public class Logger extends Category
{
private static final String FQCN;
protected Logger(String name)
{
super(name);
}
public static Logger getLogger(String name)
{
return LogManager.getLogger(name);
}
public static Logger getLogger(Class clazz)
{
return LogManager.getLogger(clazz.getName());
}
public static Logger getRootLogger()
{
return LogManager.getRootLogger();
}
public static Logger getLogger(String name, LoggerFactory factory)
{
return LogManager.getLogger(name, factory);
}
public void trace(Object message)
{
if (repository.isDisabled(5000))
{
return;
}
if (Level.TRACE.isGreaterOrEqual(getEffectiveLevel()))
{
forcedLog(Logger.FQCN, Level.TRACE, message, null);
}
}
public void trace(Object message, Throwable t)
{
if (repository.isDisabled(5000))
{
return;
}
if (Level.TRACE.isGreaterOrEqual(getEffectiveLevel()))
{
forcedLog(Logger.FQCN, Level.TRACE, message, t);
}
}
public boolean isTraceEnabled()
{
if (repository.isDisabled(5000))
{
return false;
}
return Level.TRACE.isGreaterOrEqual(getEffectiveLevel());
}
static
{
Logger.FQCN = Logger.class.getName();
}
}
Affect(row-cnt:1) cost in 190 ms.
```
De-compile the specified method:
```sh
$ jad com.taobao.container.web.arthas.rest.MetricsController directMetrics
ClassLoader:
+-com.taobao.pandora.boot.loader.ReLaunchURLClassLoader@1817d444
+-sun.misc.Launcher$AppClassLoader@14dad5dc
+-sun.misc.Launcher$ExtClassLoader@a38d7a3
Location:
/Users/zhuyong/middleware/tomcat-web/tomcat-web-web/target/classes/
private Map<String, Object> directMetrics(String ip, String[] metrics) {
JSONObject obj;
HashMap<String, Object> result = new HashMap<String, Object>();
result.put("success", false);
String metricUrl = "http://" + ip + ":8006/metrics/specific";
String postBody = Arrays.stream(metrics).map(metric -> "metric=" + metric).collect(Collectors.joining("&"));
HttpClientUtils.Response resp = HttpClientUtils.sendPostRequest((String)metricUrl, (String)postBody);
if (resp.isSuccess() && (obj = JSON.parseObject(resp.getContent())).containsKey("success") && obj.getBoolean("success").booleanValue() && obj.containsKey("data")) {
JSONArray dataArray = obj.getJSONArray("data");
HashMap<String, Object> metricMap = new HashMap<String, Object>();
for (Object aDataArray : dataArray) {
JSONObject o = (JSONObject)aDataArray;
metricMap.put(o.getString("metric"), o.get("value"));
}
result.put("data", metricMap);
result.put("success", true);
return result;
}
return result;
}
Affect(row-cnt:1) cost in 1508 ms.
```

View File

@ -0,0 +1,97 @@
jvm
===
Check the JVM profile
### Usage
```
$ jvm
CATEGORY INFO
------------------------------------------------------------------------------------------------------------------------------------
RUNTIME MACHINE-NAME hellodeMacBook-Air.local
JVM-START-TIME 2015-12-23 10:54:18
MANAGEMENT-SPEC-VERSION 1.2
SPEC-NAME Java Virtual Machine Specification
SPEC-VENDOR Oracle Corporation
SPEC-VERSION 1.8
VM-NAME Java HotSpot(TM) 64-Bit Server VM
VM-VENDOR Oracle Corporation
VM-VERSION 25.60-b23
INPUT-ARGUMENTS -Xbootclasspath/a:/Users/hello/.jenv/versions/1.8/lib/tools.jar
-Djava.util.logging.config.file=/Users/hello/code/java/crash/packaging/target/
conf/logging.properties
CLASS-PATH /Users/hello/.jenv/versions/1.8/lib/tools.jar:/Users/hello/code/java/cras
h/packaging/target/bin/crash.cli-1.3.2-SNAPSHOT.jar::/Users/hello/code/java/cr
ash/packaging/target/lib/bcpkix-jdk15on-1.51.jar:/Users/hello/code/java/crash/
packaging/target/lib/bcprov-jdk15on-1.51.jar:/Users/hello/code/java/crash/pack
aging/target/lib/crash.connectors.ssh-1.3.2-SNAPSHOT-standalone.jar:/Users/hengyuna
bc/code/java/crash/packaging/target/lib/crash.connectors.telnet-1.3.2-SNAPSHOT-stan
dalone.jar:/Users/hello/code/java/crash/packaging/target/lib/crash.shell-1.3.2
-SNAPSHOT.jar:/Users/hello/code/java/crash/packaging/target/lib/groovy-all-1.8
.9.jar:/Users/hello/code/java/crash/packaging/target/lib/ivy-2.2.0.jar
BOOT-CLASS-PATH /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/resources.j
ar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar:/
Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/sunrsasign.j
ar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jsse.jar
:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jce.jar:/L
ibrary/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/charsets.jar:
/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jfr.jar:/Li
brary/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/classes:/Users/hen
gyunabc/.jenv/versions/1.8/lib/tools.jar
LIBRARY-PATH /Users/hello/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library
/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
CLASS-LOADING LOADED-CLASS-COUNT 4264
TOTAL-LOADED-CLASS-COUNT 4264
UNLOADED-CLASS-COUNT 0
IS-VERBOSE false
COMPILATION NAME HotSpot 64-Bit Tiered Compilers
TOTAL-COMPILE-TIME 5145(ms)
GARBAGE-COLLECTORS PS Scavenge 6/74(ms)
[count/time]
PS MarkSweep 1/64(ms)
[count/time]
MEMORY-MANAGERS CodeCacheManager Code Cache
Metaspace Manager Metaspace
Compressed Class Space
PS Scavenge PS Eden Space
PS Survivor Space
PS MarkSweep PS Eden Space
PS Survivor Space
PS Old Gen
MEMORY HEAP-MEMORY-USAGE 186646528/134217728/1908932608/31245568
[committed/init/max/used]
NO-HEAP-MEMORY-USAGE 35520512/2555904/-1/34584616
[committed/init/max/used]
PENDING-FINALIZE-COUNT 0
OPERATING-SYSTEM OS Mac OS X
ARCH x86_64
PROCESSORS-COUNT 4
LOAD-AVERAGE 2.328125
VERSION 10.10.5
THREAD COUNT 16
DAEMON-COUNT 10
LIVE-COUNT 18
STARTED-COUNT 19
Affect cost in 2 ms.
```
### thread-related
* COUNT: the count of active threads
* DAEMON-COUNT: the count of active daemon threads
* LIVE-COUNT: the maximum count of the live threads since JVM starts
* STARTED-COUNT: the total count of the created threads since JVM starts

View File

@ -0,0 +1,68 @@
sc
==
Check the profiles of the loaded classes.
Abbreviated from “Search-Class”; with the help of this command, you can search out all the loaded classes in JVM. Supported options are: `[d]`、`[E]`、`[f]` and `[x:]`.
Options
-------
### Specification
|Name|Specification|
|---:|:---|
|*class-pattern*|pattern for the class name|
|*method-pattern*|pattern for the method name|
|[d]|print the details of the current class including the source file, class declaration, the class loaders and the like.<br/>F.Y.I if a class is loaded by several class loaders, then the class will be printed several times|
|[E]|turn on regx matching while the default is wildcards matching|
|[f]|print the fields info of the current class, which should be used along with `-d`|
|[x:]|the depth to print the static fields, whose default is `0` - directly invoke the `toString()`|
Tip:
1. *class-patten* supports full qualified class name (e.g. com.taobao.test.AAA and com/taobao/test/AAA)
2. `sc` turned on the `sub-class` matching in default mode, if you do want to hide the `sub-class` please just turn it off via `options disable-sub-class true`.
### Usage
Check the static fields of a class using `sc -df class-name`
```shell
$ sc -df org.apache.commons.lang.StringUtils
class-info org.apache.commons.lang.StringUtils
code-source /Users/zhuyong/middleware/citrus-sample/petstore/web/target/petstore/WEB-INF/lib/commons-lang-2.4.jar
name org.apache.commons.lang.StringUtils
isInterface false
isAnnotation false
isEnum false
isAnonymousClass false
isArray false
isLocalClass false
isMemberClass false
isPrimitive false
isSynthetic false
simple-name StringUtils
modifier public
annotation
interfaces
super-class +-java.lang.Object
class-loader +-com.taobao.tomcat.container.context.loader.AliWebappClassLoader
+-org.apache.catalina.loader.StandardClassLoader@1d44eef3
+-sun.misc.Launcher$AppClassLoader@57a462c9
+-sun.misc.Launcher$ExtClassLoader@6951a712
fields modifier final,public,static
type java.lang.String
name EMPTY
value
modifier final,public,static
type int
name INDEX_NOT_FOUND
value -1
modifier final,private,static
type int
name PAD_LIMIT
value 8192
```

View File

@ -0,0 +1,89 @@
sm
==
Check the method profile of the loaded classes;
Abbreviated from “Search-Method”, with which you can search out all methods profiles of the loaded classes.
F.Y.I
`sm` only shows the methods declared in the current class; methods declared in ancestors will not be presented.
### Options
|Name|Specification|
|---:|:---|
|*class-pattern*|pattern for class name|
|*method-pattern*|pattern for method name|
|[d]|print the details of the method|
|[E]|turn the regex matching on while the default mode is wildcards matching|
### Usage
```
$ sm org.apache.catalina.connector.Connector
org.apache.catalina.connector.Connector-><init>
org.apache.catalina.connector.Connector->setProperty
org.apache.catalina.connector.Connector->getProperty
org.apache.catalina.connector.Connector->toString
org.apache.catalina.connector.Connector->resume
org.apache.catalina.connector.Connector->getScheme
org.apache.catalina.connector.Connector->getProtocol
org.apache.catalina.connector.Connector->getPort
org.apache.catalina.connector.Connector->setService
org.apache.catalina.connector.Connector->setPort
org.apache.catalina.connector.Connector->getService
org.apache.catalina.connector.Connector->getAttribute
org.apache.catalina.connector.Connector->setAttribute
org.apache.catalina.connector.Connector->getLocalPort
org.apache.catalina.connector.Connector->pause
org.apache.catalina.connector.Connector->setProtocol
org.apache.catalina.connector.Connector->initInternal
org.apache.catalina.connector.Connector->setSecure
org.apache.catalina.connector.Connector->getSecure
org.apache.catalina.connector.Connector->startInternal
org.apache.catalina.connector.Connector->stopInternal
org.apache.catalina.connector.Connector->setScheme
org.apache.catalina.connector.Connector->createRequest
org.apache.catalina.connector.Connector->getDomainInternal
org.apache.catalina.connector.Connector->getProtocolHandler
org.apache.catalina.connector.Connector->setURIEncoding
org.apache.catalina.connector.Connector->findSslHostConfigs
org.apache.catalina.connector.Connector->destroyInternal
org.apache.catalina.connector.Connector->getObjectNameKeyProperties
org.apache.catalina.connector.Connector->getAllowTrace
org.apache.catalina.connector.Connector->setAllowTrace
org.apache.catalina.connector.Connector->getAsyncTimeout
org.apache.catalina.connector.Connector->setAsyncTimeout
org.apache.catalina.connector.Connector->getEnableLookups
org.apache.catalina.connector.Connector->setEnableLookups
org.apache.catalina.connector.Connector->getMaxCookieCount
...
```
```sh
$ sm org.apache.catalina.connector.Connector -d
declaring-class org.apache.catalina.connector.Connector
constructor-name <init>
modifier public
annotation
parameters
exceptions
declaring-class org.apache.catalina.connector.Connector
constructor-name <init>
modifier public
annotation
parameters java.lang.String
exceptions
declaring-class org.apache.catalina.connector.Connector
method-name setProperty
modifier public
annotation
parameters java.lang.String
java.lang.String
return boolean
exceptions
......
```

View File

@ -0,0 +1,122 @@
sysprop
=======
Check the JVM system properties.
### Usage
```
USAGE:
sysprop [-h] [property-name] [property-value]
SUMMARY:
Display, and change all the system properties.
EXAMPLES:
sysprop
sysprop file.encoding
sysprop production.mode true
WIKI:
https://alibaba.github.io/arthas/sysprop
OPTIONS:
-h, --help this help
<property-name> property name
<property-value> property value
```
#### Check all properties
```
$ sysprop
KEY VALUE
-------------------------------------------------------------------------------------------------------------------------------------
java.runtime.name Java(TM) SE Runtime Environment
sun.boot.library.path /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib
java.vm.version 25.51-b03
user.country.format CN
gopherProxySet false
java.vm.vendor Oracle Corporation
java.vendor.url http://java.oracle.com/
path.separator :
java.vm.name Java HotSpot(TM) 64-Bit Server VM
file.encoding.pkg sun.io
user.country US
sun.java.launcher SUN_STANDARD
sun.os.patch.level unknown
java.vm.specification.name Java Virtual Machine Specification
user.dir /private/var/tmp
java.runtime.version 1.8.0_51-b16
java.awt.graphicsenv sun.awt.CGraphicsEnvironment
java.endorsed.dirs /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/endors
ed
os.arch x86_64
java.io.tmpdir /var/folders/2c/tbxwzs4s4sbcvh7frbcc7n000000gn/T/
line.separator
java.vm.specification.vendor Oracle Corporation
os.name Mac OS X
sun.jnu.encoding UTF-8
java.library.path /Users/wangtao/Library/Java/Extensions:/Library/Java/Extensions:/Network/Libra
ry/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
sun.nio.ch.bugLevel
java.specification.name Java Platform API Specification
java.class.version 52.0
sun.management.compiler HotSpot 64-Bit Tiered Compilers
os.version 10.12.6
user.home /Users/wangtao
user.timezone Asia/Shanghai
java.awt.printerjob sun.lwawt.macosx.CPrinterJob
file.encoding UTF-8
java.specification.version 1.8
user.name wangtao
java.class.path .
java.vm.specification.version 1.8
sun.arch.data.model 64
java.home /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre
sun.java.command Test
java.specification.vendor Oracle Corporation
user.language en
awt.toolkit sun.lwawt.macosx.LWCToolkit
java.vm.info mixed mode
java.version 1.8.0_51
java.ext.dirs /Users/wangtao/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.
8.0_51.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library
/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
sun.boot.class.path /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/resour
ces.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/li
b/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/l
ib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/H
ome/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Content
s/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Conte
nts/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jd
k/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.
jdk/Contents/Home/jre/classes
java.vendor Oracle Corporation
file.separator /
java.vendor.url.bug http://bugreport.sun.com/bugreport/
sun.cpu.endian little
sun.io.unicode.encoding UnicodeBig
sun.cpu.isalist
```
#### Check a single property
Tip: `tab` auto-completion supported
```
$ sysprop java.version
java.version=1.8.0_51
```
#### Modify a single property
```
$ sysprop user.country
user.country=US
$ sysprop user.country CN
Successfully changed the system property.
user.country=CN
```

View File

@ -0,0 +1,166 @@
thread
======
Check the basic profile and stack trace of the threads.
### Parameters
|Name|Specification|
|---:|:---|
|*id*|thread id in JVM|
|[n:]|the top n busiest with stack traces|
|[b]|locate the threads blocking others|
|[i `<value>`]|specify the interval to collect data to compute CPU ratios (ms)|
How to get the CPU ratios?
> Within an *specified* interval, the time cost by the thread compared to the total CPU time.
> Take a sample (using `java.lang.management.ThreadMXBean#getThreadCpuTime`) to get the CPU time cost for all the threads and after a *specified* interval (default *100 ms*, which can be specified by `-i`), take another sample and we have the CPU time cost and the ratios naturally.
> Attention: this kind of operation will take time, to decrease the extra cost, you'd better expand the interval to like `5000 ms` for less performance overhead.
F.Y.I
If you'd like to check the CPU ratios from the very start of the Java process, [show-busy-java-threads](https://github.com/oldratlee/useful-scripts/blob/master/docs/java.md#-show-busy-java-threads) can be a help.
### Usage
#### List the top n busiest with detailed stack trace
```shell
$ thread -n 3
"as-command-execute-daemon" Id=29 cpuUsage=75% RUNNABLE
at sun.management.ThreadImpl.dumpThreads0(Native Method)
at sun.management.ThreadImpl.getThreadInfo(ThreadImpl.java:440)
at com.taobao.arthas.core.command.monitor200.ThreadCommand$1.action(ThreadCommand.java:58)
at com.taobao.arthas.core.command.handler.AbstractCommandHandler.execute(AbstractCommandHandler.java:238)
at com.taobao.arthas.core.command.handler.DefaultCommandHandler.handleCommand(DefaultCommandHandler.java:67)
at com.taobao.arthas.core.server.ArthasServer$4.run(ArthasServer.java:276)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Number of locked synchronizers = 1
- java.util.concurrent.ThreadPoolExecutor$Worker@6cd0b6f8
"as-session-expire-daemon" Id=25 cpuUsage=24% TIMED_WAITING
at java.lang.Thread.sleep(Native Method)
at com.taobao.arthas.core.server.DefaultSessionManager$2.run(DefaultSessionManager.java:85)
"Reference Handler" Id=2 cpuUsage=0% WAITING on java.lang.ref.Reference$Lock@69ba0f27
at java.lang.Object.wait(Native Method)
- waiting on java.lang.ref.Reference$Lock@69ba0f27
at java.lang.Object.wait(Object.java:503)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
```
#### List all info when no options provided
```shell
$ thread
Threads Total: 16, NEW: 0, RUNNABLE: 7, BLOCKED: 0, WAITING: 5, TIMED_WAITING: 4, TERMINATED: 0
ID NAME GROUP PRIORITY STATE %CPU TIME INTERRUPTE DAEMON
30 as-command-execute-daemon system 9 RUNNABLE 72 0:0 false true
23 as-session-expire-daemon system 9 TIMED_WAIT 27 0:0 false true
22 Attach Listener system 9 RUNNABLE 0 0:0 false true
11 pool-2-thread-1 main 5 TIMED_WAIT 0 0:0 false false
12 Thread-2 main 5 RUNNABLE 0 0:0 false true
13 pool-3-thread-1 main 5 TIMED_WAIT 0 0:0 false false
25 as-selector-daemon system 9 RUNNABLE 0 0:0 false true
14 Thread-3 main 5 TIMED_WAIT 0 0:0 false false
26 pool-5-thread-1 system 5 WAITING 0 0:0 false false
15 Thread-4 main 5 RUNNABLE 0 0:0 false false
1 main main 5 WAITING 0 0:2 false false
2 Reference Handler system 10 WAITING 0 0:0 false true
3 Finalizer system 8 WAITING 0 0:0 false true
4 Signal Dispatcher system 9 RUNNABLE 0 0:0 false true
20 NonBlockingInputStreamThread main 5 WAITING 0 0:0 false true
21 Thread-8 main 5 RUNNABLE 0 0:0 false true
```
#### thread <thread_id> present the specified thread profile
```shell
$ thread 1
"main" Id=1 WAITING on java.util.concurrent.CountDownLatch$Sync@29fafb28
at sun.misc.Unsafe.park(Native Method)
- waiting on java.util.concurrent.CountDownLatch$Sync@29fafb28
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:997)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1304)
at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231)
```
#### thread -b locate the blocking threads
Using `-b`, we can effectively locate the threads holding locks blocking other threads resulting in a frozen system.
```sh
$ thread -b
"http-bio-8080-exec-4" Id=27 TIMED_WAITING
at java.lang.Thread.sleep(Native Method)
at test.arthas.TestThreadBlocking.doGet(TestThreadBlocking.java:22)
- locked java.lang.Object@725be470 <---- but blocks 4 other threads!
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at test.filter.TestDurexFilter.doFilter(TestDurexFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at com.taobao.tomcat.valves.ContextLoadFilterValve$FilterChainAdapter.doFilter(ContextLoadFilterValve.java:191)
at com.taobao.eagleeye.EagleEyeFilter.doFilter(EagleEyeFilter.java:81)
at com.taobao.tomcat.valves.ContextLoadFilterValve.invoke(ContextLoadFilterValve.java:150)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:429)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
- locked org.apache.tomcat.util.net.SocketWrapper@7127ee12
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Number of locked synchronizers = 1
- java.util.concurrent.ThreadPoolExecutor$Worker@31a6493e
```
> Attention: only `synchronized` blocked threads can be located for now, `JUL` not supported yet.
#### thread -i specify the collecting interval
```sh
$ thread -n 3 -i 1000
"as-command-execute-daemon" Id=4759 cpuUsage=23% RUNNABLE
at sun.management.ThreadImpl.dumpThreads0(Native Method)
at sun.management.ThreadImpl.getThreadInfo(ThreadImpl.java:440)
at com.taobao.arthas.core.command.monitor200.ThreadCommand.processTopBusyThreads(ThreadCommand.java:133)
at com.taobao.arthas.core.command.monitor200.ThreadCommand.process(ThreadCommand.java:79)
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:96)
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:27)
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:125)
at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:122)
at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:332)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:756)
Number of locked synchronizers = 1
- java.util.concurrent.ThreadPoolExecutor$Worker@546aeec1
...
```

View File

@ -1,6 +1,8 @@
Arthas 用户文档
===
**[English Docs](https://alibaba.github.io/arthas/en/)**
## Arthas阿尔萨斯 能为你做什么?
![arthas](arthas.png)
@ -22,6 +24,7 @@ Arthas 用户文档
Contents
--------
* [English Docs](https://alibaba.github.io/arthas/en/)
* [安装](install-detail.md)
* [快速入门](quick-start.md)
* [进阶使用](advanced-use.md)