From da5f4a397d3dd4ee0d9f2c7f404aa140c4c2ecb5 Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Thu, 13 Aug 2020 17:40:43 +0800 Subject: [PATCH] update doc --- _sources/http-api.md.txt | 52 ++++++++++++++++++++++++++--- _sources/jad.md.txt | 2 ++ _sources/logger.md.txt | 2 ++ _sources/mc.md.txt | 2 ++ _sources/profiler.md.txt | 13 ++++++++ _sources/redefine.md.txt | 10 ++++++ _sources/sc.md.txt | 4 +++ _sources/sm.md.txt | 4 +++ arthas-tutorials.html | 12 +++++++ en/_sources/http-api.md.txt | 49 ++++++++++++++++++++++++--- en/_sources/jad.md.txt | 2 ++ en/_sources/logger.md.txt | 2 ++ en/_sources/mc.md.txt | 2 ++ en/_sources/profiler.md.txt | 13 ++++++++ en/_sources/redefine.md.txt | 10 ++++++ en/_sources/sc.md.txt | 4 +++ en/_sources/sm.md.txt | 4 +++ en/http-api.html | 46 ++++++++++++++++++++++---- en/jad.html | 1 + en/logger.html | 1 + en/mc.html | 1 + en/profiler.html | 38 +++++++++++++++++++++ en/redefine.html | 10 ++++++ en/sc.html | 9 +++++ en/searchindex.js | 2 +- en/sm.html | 9 +++++ http-api.html | 41 ++++++++++++++++++++--- jad.html | 1 + logger.html | 1 + mc.html | 1 + profiler.html | 66 +++++++++++++++++++++++++++++-------- redefine.html | 28 +++++++++++----- sc.html | 9 +++++ searchindex.js | 2 +- sm.html | 9 +++++ 35 files changed, 417 insertions(+), 45 deletions(-) diff --git a/_sources/http-api.md.txt b/_sources/http-api.md.txt index 778785e94..8119915cb 100644 --- a/_sources/http-api.md.txt +++ b/_sources/http-api.md.txt @@ -20,9 +20,9 @@ Http API接口地址为:`http://ip:port/api`,必须使用POST方式提交请 ```json { "action": "exec", - "requestId": "req112" - "sessionId": "94766d3c-8b39-42d3-8596-98aee3ccbefb" - "consumerId": "955dbd1325334a84972b0f3ac19de4f7_2" + "requestId": "req112", + "sessionId": "94766d3c-8b39-42d3-8596-98aee3ccbefb", + "consumerId": "955dbd1325334a84972b0f3ac19de4f7_2", "command": "version", "execTimeout": "10000" } @@ -537,7 +537,47 @@ curl -Ss -XPOST http://localhost:8563/api -d ''' `trace/watch/jad/tt`等命令需要对类进行增强,会接收到这个`enhancer`结果。可能出现`enhancer`结果成功,但没有命中方法的情况,客户端可以根据`enhancer`结果提示用户。 -### 其它 +### 案例 + +#### 获取Java应用的Classpath + +通过Http api查询Java应用的System properties,提取`java.class.path`的值。 + + +```bash +json_data=$(curl -Ss -XPOST http://localhost:8563/api -d ' +{ + "action":"exec", + "command":"sysprop" +}') +``` + +* 使用`sed`提取值: + +```bash +class_path=$(echo $json_data | tr -d '\n' | sed 's/.*"java.class.path":"\([^"]*\).*/\1/') +echo "classpath: $class_path" +``` + +* 使用`json_pp/awk`提取值 + +```bash +class_path=$(echo $json_data | tr -d '\n' | json_pp | grep java.class.path | awk -F'"' '{ print $4 }') +echo "classpath: $class_path" +``` + +输出内容: + +``` +classpath: demo-arthas-spring-boot.jar +``` + +注意: + +* `echo $json_data | tr -d '\n'` : 删除换行符(`line.separator`的值),避免影响`sed`/`json_pp`命令处理。 +* `awk -F'"' '{ print $4 }'` : 使用双引号作为分隔符号 + + #### watch命令输出map对象 @@ -629,4 +669,6 @@ Http api 执行结果: } ``` -可以看到watch结果的value变成map对象,程序可以通过key读取结果。 \ No newline at end of file +可以看到watch结果的value变成map对象,程序可以通过key读取结果。 + + diff --git a/_sources/jad.md.txt b/_sources/jad.md.txt index c78ff184c..2a47c52bd 100644 --- a/_sources/jad.md.txt +++ b/_sources/jad.md.txt @@ -1,6 +1,8 @@ jad === +[`jad`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials?language=cn&id=command-jad) + > 反编译指定已加载类的源码 `jad` 命令将 JVM 中实际运行的 class 的 byte code 反编译成 java 代码,便于你理解业务逻辑; diff --git a/_sources/logger.md.txt b/_sources/logger.md.txt index 1d8f18208..38337a46c 100644 --- a/_sources/logger.md.txt +++ b/_sources/logger.md.txt @@ -1,6 +1,8 @@ logger === +[`logger`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials?language=cn&id=command-logger) + > 查看logger信息,更新logger level ### 使用参考 diff --git a/_sources/mc.md.txt b/_sources/mc.md.txt index af3a3f493..76e69ed7b 100644 --- a/_sources/mc.md.txt +++ b/_sources/mc.md.txt @@ -1,6 +1,8 @@ mc === +[`mc-redefine`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials?language=cn&id=command-mc-redefine) + > Memory Compiler/内存编译器,编译`.java`文件生成`.class`。 ```bash diff --git a/_sources/profiler.md.txt b/_sources/profiler.md.txt index 7d6368e58..04d084d0e 100644 --- a/_sources/profiler.md.txt +++ b/_sources/profiler.md.txt @@ -1,12 +1,25 @@ profiler === +[`profiler`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials.html?language=cn&id=command-profiler) + > 使用[async-profiler](https://github.com/jvm-profiling-tools/async-profiler)生成火焰图 `profiler` 命令支持生成应用热点的火焰图。本质上是通过不断的采样,然后把收集到的采样结果生成火焰图。 `profiler` 命令基本运行结构是 `profiler action [actionArg]` +### 参数说明 + +|参数名称|参数说明| +|---:|:---| +|*action*|要执行的操作| +|*actionArg*|属性名模式| +|[i:]|采样间隔(单位:ns)(默认值:10'000'000,即10 ms)| +|[f:]|将输出转储到指定路径| +|[d:]|运行评测指定秒| +|[e:]|要跟踪哪个事件(cpu, alloc, lock, cache-misses等),默认是cpu| + ### 启动profiler diff --git a/_sources/redefine.md.txt b/_sources/redefine.md.txt index 4bcbf6428..97d3d5b9a 100644 --- a/_sources/redefine.md.txt +++ b/_sources/redefine.md.txt @@ -1,10 +1,20 @@ redefine === +[`mc-redefine`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials?language=cn&id=command-mc-redefine) + > 加载外部的`.class`文件,redefine jvm已加载的类。 参考:[Instrumentation#redefineClasses](https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html#redefineClasses-java.lang.instrument.ClassDefinition...-) +### 常见问题 + +* redefine的class不能修改、添加、删除类的field和method,包括方法参数、方法名称及返回值 + +* 如果mc失败,可以在本地开发环境编译好class文件,上传到目标系统,使用redefine热加载class + +* 目前redefine 和watch/trace/jad/tt等命令冲突,以后重新实现redefine功能会解决此问题 + > 注意, redefine后的原来的类不能恢复,redefine有可能失败(比如增加了新的field),参考jdk本身的文档。 > `reset`命令对`redefine`的类无效。如果想重置,需要`redefine`原始的字节码。 diff --git a/_sources/sc.md.txt b/_sources/sc.md.txt index b56622cb0..4c2a472f7 100644 --- a/_sources/sc.md.txt +++ b/_sources/sc.md.txt @@ -1,6 +1,8 @@ sc === +[`sc`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials?language=cn&id=command-sc) + > 查看JVM已加载的类信息 “Search-Class” 的简写,这个命令能搜索出所有已经加载到 JVM 中的 Class 信息,这个命令支持的参数有 `[d]`、`[E]`、`[f]` 和 `[x:]`。 @@ -18,6 +20,8 @@ sc |[E]|开启正则表达式匹配,默认为通配符匹配| |[f]|输出当前类的成员变量信息(需要配合参数-d一起使用)| |[x:]|指定输出静态变量时属性的遍历深度,默认为 0,即直接使用 `toString` 输出| +|`[c:]`|指定class的 ClassLoader 的 hashcode| +|`[n:]`|具有详细信息的匹配类的最大数量(默认为100)| > class-pattern支持全限定名,如com.taobao.test.AAA,也支持com/taobao/test/AAA这样的格式,这样,我们从异常堆栈里面把类名拷贝过来的时候,不需要在手动把`/`替换为`.`啦。 diff --git a/_sources/sm.md.txt b/_sources/sm.md.txt index f23357862..430bd9e6b 100644 --- a/_sources/sm.md.txt +++ b/_sources/sm.md.txt @@ -1,6 +1,8 @@ sm === +[`sm`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials?language=cn&id=command-sm) + > 查看已加载类的方法信息 “Search-Method” 的简写,这个命令能搜索出所有已经加载了 Class 信息的方法信息。 @@ -15,6 +17,8 @@ sm |*method-pattern*|方法名表达式匹配| |[d]|展示每个方法的详细信息| |[E]|开启正则表达式匹配,默认为通配符匹配| +|`[c:]`|指定class的 ClassLoader 的 hashcode| +|`[n:]`|具有详细信息的匹配类的最大数量(默认为100)| ### 使用参考 diff --git a/arthas-tutorials.html b/arthas-tutorials.html index c410620a3..d17e6b92b 100644 --- a/arthas-tutorials.html +++ b/arthas-tutorials.html @@ -689,6 +689,18 @@ cn: "command-tt-cn", } }, + { + id: "command-profiler", + type: "COMMAND-ENHANCED", + names: { + en: "profiler", + cn: "profiler", + }, + ids: { + en: "command-profiler-en", + cn: "command-profiler-cn", + } + }, { id: "case-web-console", type: "USERCASE", diff --git a/en/_sources/http-api.md.txt b/en/_sources/http-api.md.txt index 247aa6137..e052ae5bb 100644 --- a/en/_sources/http-api.md.txt +++ b/en/_sources/http-api.md.txt @@ -26,9 +26,9 @@ http api. ```json { "action": "exec", - "requestId": "req112" - "sessionId": "94766d3c-8b39-42d3-8596-98aee3ccbefb" - "consumerId": "955dbd1325334a84972b0f3ac19de4f7_2" + "requestId": "req112", + "sessionId": "94766d3c-8b39-42d3-8596-98aee3ccbefb", + "consumerId": "955dbd1325334a84972b0f3ac19de4f7_2", "command": "version", "execTimeout": "10000" } @@ -614,7 +614,48 @@ receive this `enhancer` result. It may happen that the result of `enhancer` is successful, but there is no hit method. The client can prompt the user according to the result of `enhancer`. -### Others +### Cases + +#### Get classpath of Java application + +Get system properties of the Java application through Http api and +extract the value of `java.class.path`. + +```bash +json_data=$(curl -Ss -XPOST http://localhost:8563/api -d ' +{ + "action":"exec", + "command":"sysprop" +}') +``` + +* Extract value with `sed`: + +```bash +class_path=$(echo $json_data | tr -d '\n' | sed 's/.*"java.class.path":"\([^"]*\).*/\1/') +echo "classpath: $class_path" +``` + +* Extract value with `json_pp/awk`: + +```bash +class_path=$(echo $json_data | tr -d '\n' | json_pp | grep java.class.path | awk -F'"' '{ print $4 }') +echo "classpath: $class_path" +``` + +Output: + +``` +classpath: demo-arthas-spring-boot.jar +``` + +NOTE: + +* `echo $json_data | tr -d '\n'` : Delete line breaks (the value of + `line.separator`) to avoid affecting the processing of `sed`/`json_pp` + commands. +* `awk -F'"' '{ print $4 }'` : Use double quote as delimiter + #### Make watch command output a map object diff --git a/en/_sources/jad.md.txt b/en/_sources/jad.md.txt index f94194739..da7ef5909 100644 --- a/en/_sources/jad.md.txt +++ b/en/_sources/jad.md.txt @@ -1,6 +1,8 @@ jad === +[`jad` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=command-jad) + > Decompile the specified classes. `jad` helps to decompile the byte code running in JVM to the source code to assist you to understand the logic behind better. diff --git a/en/_sources/logger.md.txt b/en/_sources/logger.md.txt index 960cf297f..bedc9320c 100644 --- a/en/_sources/logger.md.txt +++ b/en/_sources/logger.md.txt @@ -1,6 +1,8 @@ logger === +[`logger` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=command-logger) + > Print the logger information, update the logger level ### Usage diff --git a/en/_sources/mc.md.txt b/en/_sources/mc.md.txt index 3cac0b960..cc618ef70 100644 --- a/en/_sources/mc.md.txt +++ b/en/_sources/mc.md.txt @@ -1,6 +1,8 @@ mc === +[`mc-redefine` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=command-mc-redefine) + > Memory compiler, compiles `.java` files into `.class` files in memory. ```bash diff --git a/en/_sources/profiler.md.txt b/en/_sources/profiler.md.txt index c1db463ca..77989fe42 100644 --- a/en/_sources/profiler.md.txt +++ b/en/_sources/profiler.md.txt @@ -1,12 +1,25 @@ profiler === +[`profiler` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials.html?language=en&id=command-profiler) + > Generate a flame graph using [async-profiler](https://github.com/jvm-profiling-tools/async-profiler) The `profiler` command supports generate flame graph for application hotspots. The basic usage of the `profiler` command is `profiler action [actionArg]` +### Supported Options + +|Name|Specification| +|---:|:---| +|*action*|Action to execute| +|*actionArg*|Attribute name pattern| +|[i:]|sampling interval in ns (default: 10'000'000, i.e. 10 ms)| +|[f:]|dump output to specified directory| +|[d:]|run profiling for specified seconds| +|[e:]|which event to trace (cpu, alloc, lock, cache-misses etc.), default value is cpu| + ### Start profiler ``` diff --git a/en/_sources/redefine.md.txt b/en/_sources/redefine.md.txt index b3f2c55a3..580f8cec1 100644 --- a/en/_sources/redefine.md.txt +++ b/en/_sources/redefine.md.txt @@ -1,10 +1,20 @@ redefine ======== +[`mc-redefine` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=command-mc-redefine) + > Load the external `*.class` files to re-define the loaded classes in JVM. Reference: [Instrumentation#redefineClasses](https://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html#redefineClasses-java.lang.instrument.ClassDefinition...-) +### Frequently asked questions + +* The class of `redefine` cannot modify, add or delete the field and method of the class, including method parameters, method names and return values. + +* If `mc` fails, you can compile the class file in the local development environment, upload it to the target system, and use `redefine` to hot load the class. + +* At present, `redefine` conflicts with `watch / trace / jad / tt` commands. Reimplementing `redefine` function in the future will solve this problem. + > Notes: Re-defined classes cannot be restored. There are chances that redefining may fail due to some reasons, for example: there's new field introduced in the new version of the class, pls. refer to JDK's documentation for the limitations. > The `reset` command is not valid for classes that have been processed by `redefine`. If you want to reset, you need `redefine` the original bytecode. diff --git a/en/_sources/sc.md.txt b/en/_sources/sc.md.txt index 8ec154b5c..2f9ec2f2f 100644 --- a/en/_sources/sc.md.txt +++ b/en/_sources/sc.md.txt @@ -1,6 +1,8 @@ sc == +[`sc` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=command-sc) + > Search classes loaded by JVM. `sc` stands for search class. This command can search all possible classes loaded by JVM and show their information. The supported options are: `[d]`、`[E]`、`[f]` and `[x:]`. @@ -15,6 +17,8 @@ sc |`[E]`|turn on regex match, the default behavior is wildcards match| |`[f]`|print the fields info of the current class, MUST be used with `-d` together| |`[x:]`|specify the depth of recursive traverse the static fields, the default value is '0' - equivalent to use `toString` to output| +|`[c:]`|The hash code of the special class's classLoader| +|`[n:]`|Maximum number of matching classes with details (100 by default)| > *class-patten* supports full qualified class name, e.g. com.taobao.test.AAA and com/taobao/test/AAA. It also supports the format of 'com/taobao/test/AAA', so that it is convenient to directly copy class name from the exception stack trace without replacing '/' to '.'.

> `sc` turns on matching sub-class match by default, that is, `sc` will also search the sub classes of the target class too. If exact-match is desired, pls. use `options disable-sub-class true`. diff --git a/en/_sources/sm.md.txt b/en/_sources/sm.md.txt index 02dbbd6cd..2b3121703 100644 --- a/en/_sources/sm.md.txt +++ b/en/_sources/sm.md.txt @@ -1,6 +1,8 @@ sm == +[`sm` online tutorial](https://arthas.aliyun.com/doc/arthas-tutorials?language=en&id=command-sm) + > Search method from the loaded classes. `sm` stands for search method. This command can search and show method information from all loaded classes. `sm` can only view the methods declared on the target class, that is, methods from its parent classes are invisible. @@ -14,6 +16,8 @@ sm |*method-pattern*|pattern for method name| |`[d]`|print the details of the method| |`[E]`|turn on regex matching while the default mode is wildcard matching| +|`[c:]`|The hash code of the special class's classLoader| +|`[n:]`|Maximum number of matching classes with details (100 by default)| ### Usage diff --git a/en/http-api.html b/en/http-api.html index 6253bd229..a16489d2c 100644 --- a/en/http-api.html +++ b/en/http-api.html @@ -126,7 +126,8 @@
  • enhancer
  • -
  • Others