Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加新选项 --wall #2905

Merged
merged 10 commits into from
Oct 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public class ProfilerCommand extends AnnotatedCommand {
*/
private Integer jstackdepth;

/**
* Enable wall clock profiling in addition to CPU profiling
*/
private boolean wall;

/**
* profile different threads separately
*/
Expand Down Expand Up @@ -335,6 +340,12 @@ public void setJfrsync(String jfrsync) {
this.jfrsync = jfrsync;
}

@Option(longName = "wall", flag = true)
@Description("Enable wall clock profiling in addition to CPU profiling")
public void setWall(boolean wall) {
this.wall = wall;
}

@Option(shortName = "t", longName = "threads", flag = true)
@Description("profile different threads separately")
public void setThreads(boolean threads) {
Expand Down Expand Up @@ -578,6 +589,9 @@ private String executeArgs(ProfilerAction action) {
if (this.threads) {
sb.append("threads").append(COMMA);
}
if (this.wall) {
sb.append("wall").append(COMMA);
}
if (this.sched) {
sb.append("sched").append(COMMA);
}
Expand Down
17 changes: 17 additions & 0 deletions site/docs/doc/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,20 @@ 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) 了解更多信息。

## `--wall` 选项

这个选项允许同时进行 CPU 和 Wall clock 的分析。
通过设置输出格式为 jfr,可以记录每个执行样本的线程状态(STATE_RUNNABLE 或 STATE_SLEEPING)。
可使用以下命令(可以独立设置 CPU 和 Wall clock 分析的间隔):

```bash
profiler start -e cpu -i 10ms --wall 200ms -f out.jfr
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个使用文档有问题,命令会执行失败。

Error during processing the command: com.taobao.middleware.cli.CLIException, message:Cannot inject value for option 'interval'

```

需要注意:

- Linux 平台: 这个新功能仅在 Linux 平台上有效。macOS 上的 CPU 分析引擎已经基于 Wall clock 模式,因此没有额外的收益。
- 性能开销: 启用 Wall clock 分析会增加性能开销,因此在同时分析 CPU 和 Wall clock 时,建议增加 Wall clock 的间隔。

可参考 [async-profiler pr#740](https://github.com/async-profiler/async-profiler/issues/740) 了解更多信息。
17 changes: 17 additions & 0 deletions site/docs/en/doc/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,20 @@ 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).

## `--wall` option

This option allows for simultaneous CPU and Wall clock profiling.
By setting the output format to jfr, you can record the thread state (STATE_RUNNABLE or STATE_SLEEPING) for each execution sample.
You can use the following command (with independent intervals for CPU and Wall clock profiling):

```bash
profiler start -e cpu -i 10ms --wall 200ms -f out.jfr
```

Please note:

- Linux Platform: This new feature is only effective on the Linux platform. The CPU profiling engine on macOS is already based on Wall clock mode, so there is no additional benefit.
- Performance Overhead: Enabling Wall clock profiling increases performance overhead. Therefore, when profiling both CPU and Wall clock, it is recommended to increase the Wall clock interval.

You can refer to [async-profiler pr#740](https://github.com/async-profiler/async-profiler/issues/740) for more information.