remove profiler collect action. fix loop NullPointerException #2961

pull/2965/head
hengyunabc 2 months ago
parent 375220cb92
commit 534b822a0b

@ -38,7 +38,7 @@ import one.profiler.AsyncProfiler;
import one.profiler.Counter; import one.profiler.Counter;
/** /**
* * https://github.com/async-profiler/async-profiler/blob/master/docs/ProfilerOptions.md 具体参数说明,以及哪些参数可以传递给 async-profiler agent
* @author hengyunabc 2019-10-31 * @author hengyunabc 2019-10-31
* *
*/ */
@ -524,18 +524,12 @@ public class ProfilerCommand extends AnnotatedCommand {
@Description("run profiler in a loop (continuous profiling)") @Description("run profiler in a loop (continuous profiling)")
public void setLoop(String loop) { public void setLoop(String loop) {
this.loop = loop; this.loop = loop;
if (this.action.equals("collect")) {
this.action = "start";
}
} }
@Option(longName = "timeout") @Option(longName = "timeout")
@Description("automatically stop profiler at TIME (absolute or relative)") @Description("automatically stop profiler at TIME (absolute or relative)")
public void setTimeout(String timeout) { public void setTimeout(String timeout) {
this.timeout = timeout; this.timeout = timeout;
if (this.action.equals("collect")) {
this.action = "start";
}
} }
@ -581,11 +575,11 @@ public class ProfilerCommand extends AnnotatedCommand {
} }
/** /**
* https://github.com/async-profiler/async-profiler/blob/v2.9/profiler.sh#L154 * https://github.com/async-profiler/async-profiler/blob/v3.0/src/arguments.cpp#L131
*/ */
public enum ProfilerAction { public enum ProfilerAction {
// start, resume, stop, dump, check, status, meminfo, list, collect, // start, resume, stop, dump, check, status, meminfo, list,
start, resume, stop, dump, check, status, meminfo, list, collect, start, resume, stop, dump, check, status, meminfo, list,
version, version,
load, load,
@ -747,13 +741,16 @@ public class ProfilerCommand extends AnnotatedCommand {
} }
String result = execute(asyncProfiler, this.actionArg); String result = execute(asyncProfiler, this.actionArg);
appendExecuteResult(process, result); appendExecuteResult(process, result);
} else if (ProfilerAction.collect.equals(profilerAction)) { } else if (ProfilerAction.start.equals(profilerAction)) {
String executeArgs = executeArgs(ProfilerAction.collect); if (this.duration == null) {
String executeArgs = executeArgs(ProfilerAction.start);
String result = execute(asyncProfiler, executeArgs); String result = execute(asyncProfiler, executeArgs);
ProfilerModel profilerModel = createProfilerModel(result); appendExecuteResult(process, result);
} else { // 设置延时执行 stop
if (this.duration != null) {
final String outputFile = outputFile(); final String outputFile = outputFile();
String executeArgs = executeArgs(ProfilerAction.start);
String result = execute(asyncProfiler, executeArgs);
ProfilerModel profilerModel = createProfilerModel(result);
profilerModel.setOutputFile(outputFile); profilerModel.setOutputFile(outputFile);
profilerModel.setDuration(duration); profilerModel.setDuration(duration);
@ -761,7 +758,7 @@ public class ProfilerCommand extends AnnotatedCommand {
ArthasBootstrap.getInstance().getScheduledExecutorService().schedule(new Runnable() { ArthasBootstrap.getInstance().getScheduledExecutorService().schedule(new Runnable() {
@Override @Override
public void run() { public void run() {
//在异步线程执行profiler命令已经结束不能输出到客户端 // 在异步线程执行profiler命令已经结束不能输出到客户端
try { try {
logger.info("stopping profiler ..."); logger.info("stopping profiler ...");
ProfilerModel model = processStop(asyncProfiler, ProfilerAction.stop); ProfilerModel model = processStop(asyncProfiler, ProfilerAction.stop);
@ -772,12 +769,9 @@ public class ProfilerCommand extends AnnotatedCommand {
} }
} }
}, this.duration, TimeUnit.SECONDS); }, this.duration, TimeUnit.SECONDS);
}
process.appendResult(profilerModel); process.appendResult(profilerModel);
} else if (ProfilerAction.start.equals(profilerAction)) { }
String executeArgs = executeArgs(ProfilerAction.start);
String result = execute(asyncProfiler, executeArgs);
appendExecuteResult(process, result);
} else if (ProfilerAction.stop.equals(profilerAction)) { } else if (ProfilerAction.stop.equals(profilerAction)) {
ProfilerModel profilerModel = processStop(asyncProfiler, profilerAction); ProfilerModel profilerModel = processStop(asyncProfiler, profilerAction);
process.appendResult(profilerModel); process.appendResult(profilerModel);

@ -228,10 +228,10 @@ profiler stop --include 'java/*' --include 'com/demo/*' --exclude '*Unsafe.park*
## 指定执行时间 ## 指定执行时间
比如,希望 profiler 执行 300 秒自动结束,可以用 `-d`/`--duration` 参数为 collect action 指定时间: 比如,希望 profiler 执行 300 秒自动结束,可以用 `-d`/`--duration` 参数为 start action 指定时间:
```bash ```bash
profiler collect --duration 300 profiler start --duration 300
``` ```
## 生成 jfr 格式结果 ## 生成 jfr 格式结果
@ -383,7 +383,7 @@ profiler start --loop 1h -f /var/log/profile-%t.jfr
## `--timeout` 选项 ## `--timeout` 选项
这个选项指定 profiling 自动在多久后停止。该选项和 `--loop` 选项的格式一致,可以是时间点,也可以是一个时间间隔。这两个选项都是用于 `start` action 而不是 `collect` action 的。可参考 [async-profiler Github Discussions](https://github.com/async-profiler/async-profiler/discussions/789) 了解更多信息。 这个选项指定 profiling 自动在多久后停止。该选项和 `--loop` 选项的格式一致,可以是时间点,也可以是一个时间间隔。这两个选项都是用于 `start` action。可参考 [async-profiler docs](https://github.com/async-profiler/async-profiler/blob/master/docs/ProfilerOptions.md) 了解更多信息。
## `--wall` 选项 ## `--wall` 选项

@ -228,10 +228,10 @@ profiler stop --include'java/*' --include 'com/demo/*' --exclude'*Unsafe.park*'
## Specify execution time ## Specify execution time
For example, if you want the profiler to automatically end after 300 seconds, you can specify it with the `-d`/`--duration` parameter in collect action: For example, if you want the profiler to automatically end after 300 seconds, you can specify it with the `-d`/`--duration` parameter in start action:
```bash ```bash
profiler collect --duration 300 profiler start --duration 300
``` ```
## Generate jfr format result ## Generate jfr format result
@ -387,7 +387,7 @@ profiler start --loop 1h -f /var/log/profile-%t.jfr
This option specifies the time when profiling will automatically stop. The format is the same as in loop: it is either a wall clock time (12:34:56) or a relative time interval (2h). This option specifies the time when profiling will automatically stop. The format is the same as in loop: it is either a wall clock time (12:34:56) or a relative time interval (2h).
Both `--loop` and `--timeout` are used for `start` action but not for `collect` action, for further information refer to [async-profiler Github Discussions](https://github.com/async-profiler/async-profiler/discussions/789). Both `--loop` and `--timeout` are used for `start` action, for further information refer to [async-profiler docs](https://github.com/async-profiler/async-profiler/blob/master/docs/ProfilerOptions.md).
## `--wall` option ## `--wall` option

Loading…
Cancel
Save