Skip to content

Commit

Permalink
remove profiler collect action. fix loop NullPointerException #2961
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyunabc committed Nov 26, 2024
1 parent 375220c commit 534b822
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import one.profiler.Counter;

/**
*
* https://github.com/async-profiler/async-profiler/blob/master/docs/ProfilerOptions.md 具体参数说明,以及哪些参数可以传递给 async-profiler agent
* @author hengyunabc 2019-10-31
*
*/
Expand Down Expand Up @@ -524,18 +524,12 @@ public void setChunktime(String chunktime) {
@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";
}
}


Expand Down Expand Up @@ -581,11 +575,11 @@ private AsyncProfiler profilerInstance() {
}

/**
* 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,
Expand Down Expand Up @@ -747,21 +741,24 @@ public void process(final CommandProcess process) {
}
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);

// 延时执行stop
ArthasBootstrap.getInstance().getScheduledExecutorService().schedule(new Runnable() {
@Override
public void run() {
//在异步线程执行,profiler命令已经结束,不能输出到客户端
// 在异步线程执行,profiler命令已经结束,不能输出到客户端
try {
logger.info("stopping profiler ...");
ProfilerModel model = processStop(asyncProfiler, ProfilerAction.stop);
Expand All @@ -772,12 +769,9 @@ public void run() {
}
}
}, 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);
Expand Down
6 changes: 3 additions & 3 deletions site/docs/doc/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 格式结果
Expand Down Expand Up @@ -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` 选项

Expand Down
6 changes: 3 additions & 3 deletions site/docs/en/doc/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 534b822

Please sign in to comment.