Skip to content

Commit

Permalink
Merge branch 'alibaba:master' into clean_up_code
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyir authored Oct 16, 2023
2 parents dd10ba6 + 8d9af06 commit 505a9d3
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ public class ProfilerCommand extends AnnotatedCommand {
*/
private String chunktime;

/**
* run profiler in a loop (continuous profiling)
*/
private String loop;

/**
* automatically stop profiler at TIME (absolute or relative)
*/
private String timeout;

private static String libPath;
private static AsyncProfiler profiler = null;

Expand Down Expand Up @@ -458,6 +468,25 @@ public void setChunktime(String chunktime) {
this.chunktime = chunktime;
}

@Option(longName = "loop")
@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";
}
}


private AsyncProfiler profilerInstance() {
if (profiler != null) {
return profiler;
Expand Down Expand Up @@ -504,7 +533,7 @@ private AsyncProfiler profilerInstance() {
*/
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,
version,

load,
Expand Down Expand Up @@ -613,6 +642,12 @@ private String executeArgs(ProfilerAction action) {
if (this.chunktime!= null) {
sb.append("chunktime=").append(this.chunktime).append(COMMA);
}
if (this.loop != null) {
sb.append("loop=").append(this.loop).append(COMMA);
}
if (this.timeout != null) {
sb.append("timeout=").append(this.timeout).append(COMMA);
}

return sb.toString();
}
Expand Down Expand Up @@ -646,12 +681,8 @@ public void process(final CommandProcess process) {
}
String result = execute(asyncProfiler, this.actionArg);
appendExecuteResult(process, result);
} else if (ProfilerAction.start.equals(profilerAction)) {
//jfr录制,必须在start的时候就指定文件路径
if (this.file == null && "jfr".equals(format)) {
this.file = outputFile();
}
String executeArgs = executeArgs(ProfilerAction.start);
} else if (ProfilerAction.collect.equals(profilerAction)) {
String executeArgs = executeArgs(ProfilerAction.collect);
String result = execute(asyncProfiler, executeArgs);
ProfilerModel profilerModel = createProfilerModel(result);

Expand All @@ -677,6 +708,10 @@ public void run() {
}, this.duration, TimeUnit.SECONDS);
}
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions site/docs/doc/contact-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@

### 钉钉群

- Arthas 开源交流钉钉群: 21965291 ,搜索群号即可加入。(如果满了无法加入,请加 3 群)
- Arthas 开源交流钉钉群: 21965291 ,搜索群号即可加入。(如果满了无法加入,请加 4 群)

![](/images/dingding_qr.jpg)

- Arthas 开源交流钉钉群 2: 30707824 ,搜索群号即可加入。(如果满了无法加入,请加 3 群)
- Arthas 开源交流钉钉群 2: 30707824 ,搜索群号即可加入。(如果满了无法加入,请加 4 群)

![](/images/dingding2_qr.jpg)

- Arthas 开源交流钉钉群 3: 17605006847 ,搜索群号即可加入。
- Arthas 开源交流钉钉群 3: 17605006847 ,搜索群号即可加入。(如果满了无法加入,请加 4 群)

![](/images/dingding3_qr.jpg)

- Arthas 开源交流钉钉群 4: 41920010710 ,搜索群号即可加入。

![](/images/dingding4_qr.png)

### QQ 群

Arthas 开源交流 QQ 群: 916328269 (如果满了无法加入,请加 3 群)
Expand Down
16 changes: 14 additions & 2 deletions site/docs/doc/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ profiler stop --include 'java/*' --include 'com/demo/*' --exclude '*Unsafe.park*
## 指定执行时间

比如,希望 profiler 执行 300 秒自动结束,可以用 `-d`/`--duration` 参数指定
比如,希望 profiler 执行 300 秒自动结束,可以用 `-d`/`--duration` 参数为 collect action 指定时间

```bash
profiler start --duration 300
profiler collect --duration 300
```

## 生成 jfr 格式结果
Expand Down Expand Up @@ -338,3 +338,15 @@ profiler --ttsp
```bash
profiler start -e cpu --jfrsync profile -f combined.jfr
```

## 周期性保存结果

使用 `--loop TIME` 可以持续运行 profiler 并周期性保存结果。选项格式可以是具体时间 hh:mm:ss 或以秒、分钟、小时或天计算的时间间隔。需要确保指定的输出文件名中包含时间戳,否则每次输出的结果都会覆盖上次保存的结果。以下命令持续执行 profiling 并将每个小时内的记录保存到一个 jfr 文件中。

```bash
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) 了解更多信息。
4 changes: 4 additions & 0 deletions site/docs/en/doc/contact-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Questions about how to use Arthas and opinions can be directly raised in issues

![](/images/dingding3_qr.jpg)

- Arthas open source discussion Group 4: 41920010710 , You can join by searching for group number。

![](/images/dingding4_qr.png)

### Instructions for Installing DingTalk

DingTalk can be downloaded from: [https://www.dingtalk.com/en](https://page.dingtalk.com/wow/dingtalk/act/en-download)
Expand Down
18 changes: 16 additions & 2 deletions site/docs/en/doc/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,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:
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:

```bash
profiler start --duration 300
profiler collect --duration 300
```

## Generate jfr format result
Expand Down Expand Up @@ -338,3 +338,17 @@ For example, command below use "profile" config of JFR:
```bash
profiler start -e cpu --jfrsync profile -f combined.jfr
```

## Run profiler in a loop

Use `--loop TIME` to run profiler in a loop (continuous profiling). The argument is either a clock time (hh:mm:ss) or a loop duration in seconds, minutes, hours, or days. Make sure the filename includes a timestamp pattern, or the output will be overwritten on each iteration. The command below will run profiling endlessly and save records of each hour to a jfr file.

```bash
profiler start --loop 1h -f /var/log/profile-%t.jfr
```

## `--timeout` option

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).

0 comments on commit 505a9d3

Please sign in to comment.