diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/ProfilerCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/ProfilerCommand.java index 90e2c1460..04bc43a22 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/ProfilerCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/ProfilerCommand.java @@ -38,7 +38,7 @@ import one.profiler.AsyncProfiler; import one.profiler.Counter; /** - * + * https://github.com/async-profiler/async-profiler/blob/master/docs/ProfilerOptions.md 具体参数说明,以及哪些参数可以传递给 async-profiler agent * @author hengyunabc 2019-10-31 * */ @@ -524,18 +524,12 @@ public class ProfilerCommand extends AnnotatedCommand { @Description("run profiler in a loop (continuous profiling)") public void setLoop(String loop) { this.loop = loop; - if (this.action.equals("collect")) { - this.action = "start"; - } } @Option(longName = "timeout") @Description("automatically stop profiler at TIME (absolute or relative)") public void setTimeout(String 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 { - // start, resume, stop, dump, check, status, meminfo, list, collect, - 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, version, load, @@ -747,13 +741,16 @@ public class ProfilerCommand extends AnnotatedCommand { } String result = execute(asyncProfiler, this.actionArg); appendExecuteResult(process, result); - } else if (ProfilerAction.collect.equals(profilerAction)) { - String executeArgs = executeArgs(ProfilerAction.collect); - String result = execute(asyncProfiler, executeArgs); - ProfilerModel profilerModel = createProfilerModel(result); - - if (this.duration != null) { + } else if (ProfilerAction.start.equals(profilerAction)) { + if (this.duration == null) { + String executeArgs = executeArgs(ProfilerAction.start); + String result = execute(asyncProfiler, executeArgs); + appendExecuteResult(process, result); + } else { // 设置延时执行 stop final String outputFile = outputFile(); + String executeArgs = executeArgs(ProfilerAction.start); + String result = execute(asyncProfiler, executeArgs); + ProfilerModel profilerModel = createProfilerModel(result); profilerModel.setOutputFile(outputFile); profilerModel.setDuration(duration); @@ -761,7 +758,7 @@ public class ProfilerCommand extends AnnotatedCommand { ArthasBootstrap.getInstance().getScheduledExecutorService().schedule(new Runnable() { @Override public void run() { - //在异步线程执行,profiler命令已经结束,不能输出到客户端 + // 在异步线程执行,profiler命令已经结束,不能输出到客户端 try { logger.info("stopping profiler ..."); ProfilerModel model = processStop(asyncProfiler, ProfilerAction.stop); @@ -772,12 +769,9 @@ public class ProfilerCommand extends AnnotatedCommand { } } }, 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)) { ProfilerModel profilerModel = processStop(asyncProfiler, profilerAction); process.appendResult(profilerModel); diff --git a/site/docs/doc/profiler.md b/site/docs/doc/profiler.md index 430937f0f..8e3bee33f 100644 --- a/site/docs/doc/profiler.md +++ b/site/docs/doc/profiler.md @@ -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 -profiler collect --duration 300 +profiler start --duration 300 ``` ## 生成 jfr 格式结果 @@ -383,7 +383,7 @@ profiler start --loop 1h -f /var/log/profile-%t.jfr ## `--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` 选项 diff --git a/site/docs/en/doc/profiler.md b/site/docs/en/doc/profiler.md index d01ad979d..924278b25 100644 --- a/site/docs/en/doc/profiler.md +++ b/site/docs/en/doc/profiler.md @@ -228,10 +228,10 @@ profiler stop --include'java/*' --include 'com/demo/*' --exclude'*Unsafe.park*' ## 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 -profiler collect --duration 300 +profiler start --duration 300 ``` ## 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). -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