upgrade async-profiler to 2.5 #2035

This commit is contained in:
hengyunabc
2021-12-02 17:26:50 +08:00
parent 8ffa389db3
commit d39538a408
13 changed files with 40 additions and 104 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -51,7 +51,7 @@ import one.profiler.Counter;
+ " profiler list # list all supported events\n"
+ " profiler actions # list all supported actions\n"
+ " profiler start --event alloc\n"
+ " profiler stop --format svg # output file format, support svg,html,jfr\n"
+ " profiler stop --format html # output file format, support html,jfr\n"
+ " profiler stop --file /tmp/result.html\n"
+ " profiler stop --threads \n"
+ " profiler start --include 'java/*' --include 'demo/*' --exclude '*Unsafe.park*'\n"
@@ -62,7 +62,7 @@ import one.profiler.Counter;
+ " profiler dumpCollapsed # Dump profile in 'collapsed stacktraces' format\n"
+ " profiler dumpTraces # Dump collected stack traces\n"
+ " profiler execute 'start,framebuf=5000000' # Execute an agent-compatible profiling command\n"
+ " profiler execute 'stop,file=/tmp/result.svg' # Execute an agent-compatible profiling command\n"
+ " profiler execute 'stop,file=/tmp/result.html' # Execute an agent-compatible profiling command\n"
+ Constants.WIKI + Constants.WIKI_HOME + "profiler")
//@formatter:on
public class ProfilerCommand extends AnnotatedCommand {
@@ -75,7 +75,7 @@ public class ProfilerCommand extends AnnotatedCommand {
private String file;
/**
* output file format, default value is svg.
* output file format, default value is html.
*/
private String format;
@@ -125,14 +125,13 @@ public class ProfilerCommand extends AnnotatedCommand {
static {
String profierSoPath = null;
if (OSUtils.isMac()) {
profierSoPath = "async-profiler/libasyncProfiler-mac-x64.so";
// FAT_BINARY support both x86_64/arm64
profierSoPath = "async-profiler/libasyncProfiler-mac.so";
}
if (OSUtils.isLinux()) {
profierSoPath = "async-profiler/libasyncProfiler-linux-x64.so";
if (OSUtils.isArm32()) {
profierSoPath = "async-profiler/libasyncProfiler-linux-arm.so";
} else if (OSUtils.isArm64()) {
profierSoPath = "async-profiler/libasyncProfiler-linux-aarch64.so";
if (OSUtils.isArm64()) {
profierSoPath = "async-profiler/libasyncProfiler-linux-arm64.so";
}
}
@@ -186,8 +185,8 @@ public class ProfilerCommand extends AnnotatedCommand {
}
@Option(longName = "format")
@Description("dump output file format(svg, html, jfr), default valut is svg")
@DefaultValue("svg")
@Description("dump output file format(html, jfr), default valut is html")
@DefaultValue("html")
public void setFormat(String format) {
this.format = format;
}
@@ -533,7 +532,7 @@ public class ProfilerCommand extends AnnotatedCommand {
CompletionUtils.complete(completion, events());
return;
} else if (token_2.equals("-f") || token_2.equals("--format")) {
CompletionUtils.complete(completion, Arrays.asList("svg", "html", "jfr"));
CompletionUtils.complete(completion, Arrays.asList("html", "jfr"));
return;
}
}
@@ -58,6 +58,9 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
*/
@Override
public void start(String event, long interval) throws IllegalStateException {
if (event == null) {
throw new NullPointerException();
}
start0(event, interval, true);
}
@@ -71,6 +74,9 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
*/
@Override
public void resume(String event, long interval) throws IllegalStateException {
if (event == null) {
throw new NullPointerException();
}
start0(event, interval, false);
}
@@ -116,7 +122,10 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
* @throws IOException If failed to create output file
*/
@Override
public String execute(String command) throws IllegalArgumentException, IOException {
public String execute(String command) throws IllegalArgumentException, IllegalStateException, IOException {
if (command == null) {
throw new NullPointerException();
}
return execute0(command);
}
@@ -129,7 +138,7 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
@Override
public String dumpCollapsed(Counter counter) {
try {
return execute0("collapsed,counter=" + counter.name().toLowerCase());
return execute0("collapsed," + counter.name().toLowerCase());
} catch (IOException e) {
throw new IllegalStateException(e);
}
@@ -144,7 +153,7 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
@Override
public String dumpTraces(int maxTraces) {
try {
return execute0("summary,traces=" + maxTraces);
return execute0(maxTraces == 0 ? "traces" : "traces=" + maxTraces);
} catch (IOException e) {
throw new IllegalStateException(e);
}
@@ -159,7 +168,7 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
@Override
public String dumpFlat(int maxMethods) {
try {
return execute0("summary,flat=" + maxMethods);
return execute0(maxMethods == 0 ? "flat" : "flat=" + maxMethods);
} catch (IOException e) {
throw new IllegalStateException(e);
}
@@ -186,7 +195,7 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
}
private void filterThread(Thread thread, boolean enable) {
if (thread == null) {
if (thread == null || thread == Thread.currentThread()) {
filterThread0(null, enable);
} else {
// Need to take lock to avoid race condition with a thread state change
@@ -201,6 +210,6 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
private native void start0(String event, long interval, boolean reset) throws IllegalStateException;
private native void stop0() throws IllegalStateException;
private native String execute0(String command) throws IllegalArgumentException, IOException;
private native String execute0(String command) throws IllegalArgumentException, IllegalStateException, IOException;
private native void filterThread0(Thread thread, boolean enable);
}
}
@@ -35,7 +35,7 @@ public interface AsyncProfilerMXBean {
long getSamples();
String getVersion();
String execute(String command) throws IllegalArgumentException, java.io.IOException;
String execute(String command) throws IllegalArgumentException, IllegalStateException, java.io.IOException;
String dumpCollapsed(Counter counter);
String dumpTraces(int maxTraces);
+3 -19
View File
@@ -48,25 +48,9 @@ Can view which `event` and sampling time.
### Stop profiler
#### Generate svg format results
```
$ profiler stop
profiler output file: /tmp/demo/arthas-output/20191125-135546.svg
OK
```
By default, the generated results are saved to the `arthas-output` directory under the application's `working directory`. The output result path can be specified by the `--file` parameter. such as:
```bash
$ profiler stop --file /tmp/output.svg
profiler output file: /tmp/output.svg
OK
```
#### Generating html format results
By default, the result file is `svg` format. If you want to generate the `html` format, you can specify it with the `--format` parameter:
By default, the result file is `html` format. You can also specify it with the `--format` parameter:
```bash
$ profiler stop --format html
@@ -161,7 +145,7 @@ profiler execute 'start,framebuf=5000000'
Stop sampling and save to the specified file:
```bash
profiler execute 'stop,file=/tmp/result.svg'
profiler execute 'stop,file=/tmp/result.html'
```
Specific format reference: [arguments.cpp](https://github.com/jvm-profiling-tools/async-profiler/blob/v1.8.1/src/arguments.cpp#L50)
@@ -184,7 +168,7 @@ Copyright 2019 Andrei Pangin
### Configure framebuf option
> If you encounter `[frame_buffer_overflow]` in the generated svg image, you need to increase the framebuf (the default value is 1'000'000), which can be configured explicitly, such as:
> If you encounter `[frame_buffer_overflow]` in the generated result, you need to increase the framebuf (the default value is 1'000'000), which can be configured explicitly, such as:
```bash
profiler start --framebuf 5000000
+3 -20
View File
@@ -48,26 +48,9 @@ $ profiler status
可以查看当前profiler在采样哪种`event`和采样时间。
### 停止profiler
#### 生成svg格式结果
```
$ profiler stop
profiler output file: /tmp/demo/arthas-output/20191125-135546.svg
OK
```
默认情况下,生成的结果保存到应用的`工作目录`下的`arthas-output`目录。可以通过 `--file`参数来指定输出结果路径。比如:
```bash
$ profiler stop --file /tmp/output.svg
profiler output file: /tmp/output.svg
OK
```
#### 生成html格式结果
默认情况下,结果文件是`svg`格式,如果想生成`html`格式,可以用`--format`参数指定:
默认情况下,结果文件是`html`格式,可以用`--format`参数指定:
```bash
$ profiler stop --format html
@@ -163,7 +146,7 @@ profiler execute 'start,framebuf=5000000'
停止采样,并保存到指定文件里:
```bash
profiler execute 'stop,file=/tmp/result.svg'
profiler execute 'stop,file=/tmp/result.html'
```
具体的格式参考: [arguments.cpp](https://github.com/jvm-profiling-tools/async-profiler/blob/v1.8.1/src/arguments.cpp#L50)
@@ -186,7 +169,7 @@ Copyright 2019 Andrei Pangin
### 配置 framebuf 参数
> 如果遇到生成的svg图片有 `[frame_buffer_overflow]`,则需要增大 framebuf(默认值是 1'000'000),可以显式配置,比如:
> 如果遇到生成的火焰图有 `[frame_buffer_overflow]`,则需要增大 framebuf(默认值是 1'000'000),可以显式配置,比如:
```bash
profiler start --framebuf 5000000
@@ -52,7 +52,7 @@ public class MethodConstants {
/**
* <pre>
* tunnel server向 tunnel client请求 http中转,比如访问 http://localhost:3658/arthas-output/xxx.svg
* tunnel server向 tunnel client请求 http中转,比如访问 http://localhost:3658/arthas-output/xxx.html
* </pre>
*/
public static final String HTTP_PROXY = "httpProxy";
@@ -71,29 +71,9 @@ $ profiler status
### 停止profiler
#### 生成svg格式结果
`profiler stop`{{execute T2}}
```
$ profiler stop
profiler output file: /tmp/demo/arthas-output/20191125-135546.svg
OK
```
默认情况下,生成的结果保存到应用的`工作目录`下的`arthas-output`目录。可以通过 `--file`参数来指定输出结果路径。比如:
`profiler stop --file /tmp/output.svg`{{execute T2}}
```bash
$ profiler stop --file /tmp/output.svg
profiler output file: /tmp/output.svg
OK
```
#### 生成html格式结果
默认情况下,结果文件是`svg`格式,如果想生成`html`格式可以用`--format`参数指定:
默认情况下,结果文件是`html`格式。也可以用`--format`参数指定:
`profiler stop --format html`{{execute T2}}
@@ -199,10 +179,10 @@ profiler execute 'start,framebuf=5000000'
停止采样,并保存到指定文件里:
`profiler execute 'stop,file=/tmp/result.svg'`{{execute T2}}
`profiler execute 'stop,file=/tmp/result.html'`{{execute T2}}
```bash
profiler execute 'stop,file=/tmp/result.svg'
profiler execute 'stop,file=/tmp/result.html'
```
具体的格式参考: [arguments.cpp](https://github.com/jvm-profiling-tools/async-profiler/blob/v1.8.1/src/arguments.cpp#L50)
@@ -71,29 +71,10 @@ Can view which `event` and sampling time.
### Stop profiler
#### Generate svg format results
`profiler stop`{{execute T2}}
```
$ profiler stop
profiler output file: /tmp/demo/arthas-output/20191125-135546.svg
OK
```
By default, the generated results are saved to the `arthas-output` directory under the application's `working directory`. The output result path can be specified by the `--file` parameter. such as:
`profiler stop --file /tmp/output.svg`{{execute T2}}
```bash
$ profiler stop --file /tmp/output.svg
profiler output file: /tmp/output.svg
OK
```
#### Generating html format results
By default, the result file is `svg` format. If you want to generate the `html` format, you can specify it with the `--format` parameter:
By default, the result file is `html` format. You can also specify it with the `--format` parameter:
`profiler stop --format html`{{execute T2}}
@@ -199,10 +180,10 @@ profiler execute 'start,framebuf=5000000'
Stop sampling and save to the specified file:
`profiler execute 'stop,file=/tmp/result.svg'`{{execute T2}}
`profiler execute 'stop,file=/tmp/result.html'`{{execute T2}}
```bash
profiler execute 'stop,file=/tmp/result.svg'
profiler execute 'stop,file=/tmp/result.html'
```
Specific format reference: [arguments.cpp](https://github.com/jvm-profiling-tools/async-profiler/blob/v1.8.1/src/arguments.cpp#L50)