Skip to content

Commit

Permalink
profiler command add dump action (alibaba#2622)
Browse files Browse the repository at this point in the history
  • Loading branch information
Winson-Huang authored Aug 21, 2023
1 parent f375238 commit ba63c3a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,16 @@ private AsyncProfiler profilerInstance() {
}

/**
* https://github.com/jvm-profiling-tools/async-profiler/blob/v2.5/src/arguments.cpp#L50
*
* https://github.com/async-profiler/async-profiler/blob/v2.9/profiler.sh#L154
*/
public enum ProfilerAction {
execute, start, stop, resume, list, version, status, load,
// start, resume, stop, dump, check, status, meminfo, list, collect,
start, resume, stop, dump, status, list,
version,

load,
execute,
dumpCollapsed, dumpFlat, dumpTraces, getSamples,

actions
}

Expand Down Expand Up @@ -513,7 +515,7 @@ public void run() {
//在异步线程执行,profiler命令已经结束,不能输出到客户端
try {
logger.info("stopping profiler ...");
ProfilerModel model = processStop(asyncProfiler);
ProfilerModel model = processStop(asyncProfiler, ProfilerAction.stop);
logger.info("profiler output file: " + model.getOutputFile());
logger.info("stop profiler successfully.");
} catch (Throwable e) {
Expand All @@ -524,7 +526,10 @@ public void run() {
}
process.appendResult(profilerModel);
} else if (ProfilerAction.stop.equals(profilerAction)) {
ProfilerModel profilerModel = processStop(asyncProfiler);
ProfilerModel profilerModel = processStop(asyncProfiler, profilerAction);
process.appendResult(profilerModel);
} else if (ProfilerAction.dump.equals(profilerAction)) {
ProfilerModel profilerModel = processStop(asyncProfiler, profilerAction);
process.appendResult(profilerModel);
} else if (ProfilerAction.resume.equals(profilerAction)) {
String executeArgs = executeArgs(ProfilerAction.resume);
Expand Down Expand Up @@ -576,9 +581,9 @@ public void run() {
}
}

private ProfilerModel processStop(AsyncProfiler asyncProfiler) throws IOException {
private ProfilerModel processStop(AsyncProfiler asyncProfiler, ProfilerAction profilerAction) throws IOException {
String outputFile = outputFile();
String executeArgs = executeArgs(ProfilerAction.stop);
String executeArgs = executeArgs(profilerAction);
String result = execute(asyncProfiler, executeArgs);

ProfilerModel profilerModel = createProfilerModel(result);
Expand Down
9 changes: 9 additions & 0 deletions site/docs/doc/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ Started [cpu] profiling

通过执行`profiler getSamples`可以查看 samples 的数量来验证。

## Dump 分析结果

```bash
$ profiler dump
OK
```

`dump` action 将性能分析的结果保存到默认文件或指定的文件中,但 profiling 过程不会停止。例如,如果使用 `start` action 启动 profiling,5 秒后执行 `dump` action,2 秒后再次执行 `dump` action,将会得到 2 个结果文件,第一个文件包括 0\~5 秒的分析结果,第二个文件包括 0\~7 秒的分析结果。

## 使用`execute`来执行复杂的命令

比如开始采样:
Expand Down
9 changes: 9 additions & 0 deletions site/docs/en/doc/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ The difference between `start` and `resume` is: `start` will clean existing resu

You can verify the number of samples by executing `profiler getSamples`.

## Dump action

```bash
$ profiler dump
OK
```

The `dump` action saves profiling result to default file or specified file, but profiling will continue. That means if you start profiling and dump after 5 seconds, then dump after 2 seconds again, you will get 2 result files, the first one contains profiling result of 0\~5 seconds and the second one contains that of 0\~7 seconds.

## Use `execute` action to execute complex commands

For example, start sampling:
Expand Down

0 comments on commit ba63c3a

Please sign in to comment.