Skip to content

Commit

Permalink
profiler command support --wall option(#2905)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoGuorui666 authored Oct 4, 2024
1 parent 925cf17 commit 59b87ca
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public class ProfilerCommand extends AnnotatedCommand {
*/
private Integer jstackdepth;

/**
* wall clock profiling interval
*/
private Long wall;

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

@Option(longName = "wall", flag = true)
@Description("wall clock profiling interval")
@DefaultValue("10000000")
public void setWall(Long 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 @@ -619,7 +631,9 @@ private String executeArgs(ProfilerAction action) {
if (this.end != null) {
sb.append("end=").append(this.end).append(COMMA);
}

if (this.wall != null) {
sb.append("wall=").append(this.wall).append(COMMA);
}
if (this.title != null) {
sb.append("title=").append(this.title).append(COMMA);
}
Expand Down
19 changes: 19 additions & 0 deletions site/docs/doc/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,22 @@ 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` 选项

通过 --wall 选项,可以同时进行 CPU 和 Wall Clock 的性能分析。

1. 这种联合分析有助于更全面地识别和理解应用程序的性能瓶颈。
2. 允许用户独立于 CPU 分析设置 Wall Clock 分析的采样间隔。比如,可以通过设置 -e cpu -i 10 --wall 200,将 CPU 采样间隔设为 10 毫秒,墙钟采样间隔设为 200 毫秒。
3. 联合进行 CPU 和 Wall Clock 分析时,输出格式必须设置为 jfr。这一格式支持记录线程的状态信息(如 STATE_RUNNABLE 或 STATE_SLEEPING),从而区分不同类型的采样事件。

可参考 [async-profiler Github pr#740](https://github.com/async-profiler/async-profiler/issues/740) 了解更多信息。

影响:

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

```bash
profiler start -e cpu -i 10 --wall 100 -f out.jfr
```
14 changes: 14 additions & 0 deletions site/docs/en/doc/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,17 @@ 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

The -- wall option allows for simultaneous performance analysis of both CPU and Wall Clock. This joint analysis helps to more comprehensively identify and understand performance bottlenecks in applications.
--The wall option allows users to set the sampling interval for Wall Clock analysis independently of CPU analysis. For example, by setting - e cpu-i 10-- wall 200, the CPU sampling interval can be set to 10 milliseconds, and the wall clock sampling interval can be set to 200 milliseconds.
When conducting joint CPU and Wall Clock analysis, the output format must be set to jfr. This format supports recording the state information of threads (such as State_SUNNABLE or State_SLEEPING) to distinguish between different types of sampling events.

influence
Linux platform: This new feature is only available on the Linux platform. The CPU analysis engine on macOS is already based on Wall clock mode, so there are no additional benefits.
Performance overhead: Enabling Wall clock analysis will increase performance overhead, so when analyzing both CPU and Wall clock simultaneously, it is recommended to increase the interval between Wall clocks.

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

0 comments on commit 59b87ca

Please sign in to comment.