mirror of https://github.com/alibaba/arthas.git
add vmtool command tutorials
parent
732174ad36
commit
4c573990c3
@ -0,0 +1,57 @@
|
||||
{
|
||||
"title": "Arthas vmtool 命令",
|
||||
"description": "Arthas vmtool 命令",
|
||||
"difficulty": "精通者",
|
||||
"time": "10分钟",
|
||||
"details": {
|
||||
"steps": [
|
||||
{
|
||||
"title": "Start demo",
|
||||
"text": "start-demo.md"
|
||||
},
|
||||
{
|
||||
"title": "Start arthas-boot",
|
||||
"text": "arthas-boot.md"
|
||||
},
|
||||
{
|
||||
"title": "Arthas vmtool 命令",
|
||||
"text": "vmtool.md"
|
||||
},
|
||||
{
|
||||
"title": "Arthas vmtool 命令",
|
||||
"text": "vmtool-spring.md"
|
||||
},
|
||||
{
|
||||
"title": "Arthas vmtool 命令",
|
||||
"text": "vmtool-classloader.md"
|
||||
},
|
||||
{
|
||||
"title": "Arthas vmtool 命令",
|
||||
"text": "vmtool-gc.md"
|
||||
}
|
||||
],
|
||||
"intro": {
|
||||
"text": "intro.md"
|
||||
},
|
||||
"finish": {
|
||||
"text": "finish.md"
|
||||
},
|
||||
"assets": {
|
||||
"host01": []
|
||||
}
|
||||
},
|
||||
"environment": {
|
||||
"uilayout": "terminal",
|
||||
"showdashboard": true,
|
||||
"dashboards": [
|
||||
{
|
||||
"name": "Web Port 80",
|
||||
"port": 80
|
||||
}
|
||||
]
|
||||
},
|
||||
"backend": {
|
||||
"imageid": "openjdk:15",
|
||||
"environmentsprotocol": "http"
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
|
||||
### 指定 classloader name
|
||||
|
||||
```bash
|
||||
vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext
|
||||
```
|
||||
|
||||
|
||||
### 指定 classloader hash
|
||||
|
||||
可以通过`sc`命令查找到加载class的 classloader。
|
||||
|
||||
```bash
|
||||
$ sc -d org.springframework.context.ApplicationContext
|
||||
class-info org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
|
||||
code-source file:/private/tmp/demo-arthas-spring-boot.jar!/BOOT-INF/lib/spring-boot-1.5.13.RELEASE.jar!/
|
||||
name org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
|
||||
...
|
||||
class-loader +-org.springframework.boot.loader.LaunchedURLClassLoader@19469ea2
|
||||
+-sun.misc.Launcher$AppClassLoader@75b84c92
|
||||
+-sun.misc.Launcher$ExtClassLoader@4f023edb
|
||||
classLoaderHash 19469ea2
|
||||
```
|
||||
|
||||
然后用`-c`/`--classloader` 参数指定:
|
||||
|
||||
```bash
|
||||
vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext
|
||||
```
|
||||
|
@ -0,0 +1,6 @@
|
||||
|
||||
### 强制GC
|
||||
|
||||
```bash
|
||||
vmtool --action forceGc
|
||||
```
|
@ -0,0 +1,7 @@
|
||||
|
||||
The `vmtool Tutorial` demonstrates the usage of `vmtool`. If you have more tips or questions, please feel free to tell or ask in Issue.
|
||||
|
||||
* Issues: https://github.com/alibaba/arthas/issues
|
||||
* Documentation: https://arthas.aliyun.com/doc/en
|
||||
|
||||
If you are using Arthas, please let us know that. Your use is very important to us: [View](https://github.com/alibaba/arthas/issues/111)
|
@ -0,0 +1,57 @@
|
||||
{
|
||||
"title": "Arthas vmtool command",
|
||||
"description": "Arthas vmtool command",
|
||||
"difficulty": "master",
|
||||
"time": "10 minutes",
|
||||
"details": {
|
||||
"steps": [
|
||||
{
|
||||
"title": "Start demo",
|
||||
"text": "start-demo.md"
|
||||
},
|
||||
{
|
||||
"title": "Start arthas-boot",
|
||||
"text": "arthas-boot.md"
|
||||
},
|
||||
{
|
||||
"title": "Arthas vmtool command",
|
||||
"text": "vmtool.md"
|
||||
},
|
||||
{
|
||||
"title": "Arthas vmtool command",
|
||||
"text": "vmtool-spring.md"
|
||||
},
|
||||
{
|
||||
"title": "Arthas vmtool command",
|
||||
"text": "vmtool-classloader.md"
|
||||
},
|
||||
{
|
||||
"title": "Arthas vmtool command",
|
||||
"text": "vmtool-gc.md"
|
||||
}
|
||||
],
|
||||
"intro": {
|
||||
"text": "intro.md"
|
||||
},
|
||||
"finish": {
|
||||
"text": "finish.md"
|
||||
},
|
||||
"assets": {
|
||||
"host01": []
|
||||
}
|
||||
},
|
||||
"environment": {
|
||||
"uilayout": "terminal",
|
||||
"showdashboard": true,
|
||||
"dashboards": [
|
||||
{
|
||||
"name": "Web Port 80",
|
||||
"port": 80
|
||||
}
|
||||
]
|
||||
},
|
||||
"backend": {
|
||||
"imageid": "openjdk:15",
|
||||
"environmentsprotocol": "http"
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
|
||||
![Arthas](https://arthas.aliyun.com/doc/_images/arthas.png)
|
||||
|
||||
`Arthas` is a Java diagnostic tool open-sourced by Alibaba middleware team. Arthas helps developers in trouble-shooting issues in production environment for Java based applications without modifying code or restarting servers.
|
||||
|
||||
|
||||
This tutorial takes a simple application as an example to demonstrate the the usage of `vmtool`.
|
||||
|
||||
* Github: https://github.com/alibaba/arthas
|
||||
* Docs: https://arthas.aliyun.com/doc/en
|
@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
|
||||
|
||||
Download `demo-arthas-spring-boot.jar`, and start with `java -jar` command:
|
||||
|
||||
`wget https://github.com/hengyunabc/spring-boot-inside/raw/master/demo-arthas-spring-boot/demo-arthas-spring-boot.jar
|
||||
java -jar demo-arthas-spring-boot.jar`{{execute T1}}
|
||||
|
||||
`demo-arthas-spring-boot` is a simple Spring Boot demo, the source code here: [View](https://github.com/hengyunabc/spring-boot-inside/tree/master/demo-arthas-spring-boot)
|
||||
|
||||
After booting, access port 80: https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com
|
||||
|
||||
![Demo Web](/arthas/scenarios/common-resources/assets/demo-web.png)
|
@ -0,0 +1,28 @@
|
||||
### Specify classloader name
|
||||
|
||||
```bash
|
||||
vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext
|
||||
```
|
||||
|
||||
|
||||
### Specify classloader hash
|
||||
|
||||
The classloader that loads the class can be found through the `sc` command.
|
||||
|
||||
```bash
|
||||
$ sc -d org.springframework.context.ApplicationContext
|
||||
class-info org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
|
||||
code-source file:/private/tmp/demo-arthas-spring-boot.jar!/BOOT-INF/lib/spring-boot-1.5.13.RELEASE.jar!/
|
||||
name org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
|
||||
...
|
||||
class-loader +-org.springframework.boot.loader.LaunchedURLClassLoader@19469ea2
|
||||
+-sun.misc.Launcher$AppClassLoader@75b84c92
|
||||
+-sun.misc.Launcher$ExtClassLoader@4f023edb
|
||||
classLoaderHash 19469ea2
|
||||
```
|
||||
|
||||
Then use the `-c`/`--classloader` parameter to specify:
|
||||
|
||||
```bash
|
||||
vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext
|
||||
```
|
@ -0,0 +1,6 @@
|
||||
|
||||
### forceGc
|
||||
|
||||
```bash
|
||||
vmtool --action forceGc
|
||||
```
|
@ -0,0 +1,55 @@
|
||||
Next, use the `vmtool` command to find objects in spring.
|
||||
|
||||
### Find spring context
|
||||
|
||||
```bash
|
||||
$ vmtool --action getInstances --className org.springframework.context.ApplicationContext
|
||||
@ApplicationContext[][
|
||||
@AnnotationConfigEmbeddedWebApplicationContext[org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@12028586: startup date [Thu May 13 16:08:38 UTC 2021]; root of context hierarchy],
|
||||
]
|
||||
```
|
||||
|
||||
### Specify the number of expanded layers of returned results
|
||||
|
||||
> The return result of the `getInstances` action is bound to the `instances` variable, which is an array.
|
||||
|
||||
> The expansion level of the result can be specified by the `-x`/`--expand` parameter, the default value is 1.
|
||||
|
||||
```bash
|
||||
vmtool --action getInstances -c 19469ea2 --className org.springframework.context.ApplicationContext -x 2
|
||||
```
|
||||
|
||||
### Execute expression
|
||||
|
||||
> The return result of the `getInstances` action is bound to the `instances` variable, which is an array. The specified expression can be executed through the `--express` parameter.
|
||||
|
||||
Find the names of all spring beans:
|
||||
|
||||
```bash
|
||||
vmtool --action getInstances --className org.springframework.context.ApplicationContext --express'instances[0].getBeanDefinitionNames()'
|
||||
```
|
||||
|
||||
Call the `userController.findUserById(1)` function:
|
||||
|
||||
```
|
||||
$ vmtool --action getInstances --className org.springframework.context.ApplicationContext --express'instances[0].getBean("userController").findUserById(1)'
|
||||
@User[
|
||||
id=@Integer[1],
|
||||
name=@String[name1],
|
||||
]
|
||||
```
|
||||
|
||||
### Find all spring mapping objects
|
||||
|
||||
```bash
|
||||
$ vmtool --action getInstances --className org.springframework.web.servlet.HandlerMapping
|
||||
@HandlerMapping[][
|
||||
@SimpleUrlHandlerMapping[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@5d3819c8],
|
||||
@EmptyHandlerMapping[org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@11d509ba],
|
||||
@RequestMappingHandlerMapping[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@56a5f2e3],
|
||||
@WelcomePageHandlerMapping[org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WelcomePageHandlerMapping@4c0a4ed3],
|
||||
@EmptyHandlerMapping[org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport$EmptyHandlerMapping@51e1f8c3],
|
||||
@BeanNameUrlHandlerMapping[org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@68c0a39c],
|
||||
@SimpleUrlHandlerMapping[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@110b768d],
|
||||
]
|
||||
```
|
@ -0,0 +1,35 @@
|
||||
|
||||
|
||||
|
||||
Use the `vmtool` command to find the jvm object.
|
||||
|
||||
|
||||
### Find string objects in jvm
|
||||
|
||||
```bash
|
||||
$ vmtool --action getInstances --className java.lang.String
|
||||
@String[][
|
||||
@String[Sorry, deque too big],
|
||||
@String[head=%d tail=%d capacity=%d%n],
|
||||
@String[elements=%s%n],
|
||||
@String[sun/nio/ch/IOVecWrapper],
|
||||
@String[40252e37-8a73-4960-807e-3495addd5b08:1620922383791],
|
||||
@String[40252e37-8a73-4960-807e-3495addd5b08:1620922383791],
|
||||
@String[sun/nio/ch/AllocatedNativeObject],
|
||||
@String[sun/nio/ch/NativeObject],
|
||||
@String[sun/nio/ch/IOVecWrapper$Deallocator],
|
||||
@String[Java_sun_nio_ch_FileDispatcherImpl_writev0],
|
||||
]
|
||||
```
|
||||
|
||||
### limit parameter
|
||||
|
||||
> Through the `--limit` parameter, you can limit the number of return values to avoid pressure on the JVM when obtaining large data. The default value is 10.
|
||||
|
||||
So the above command is actually equivalent to:
|
||||
|
||||
```bash
|
||||
vmtool --action getInstances --className java.lang.String --limit 10
|
||||
```
|
||||
|
||||
If you set `--limit` to a negative number, all objects are traversed.
|
Loading…
Reference in New Issue