Skip to content

Commit

Permalink
profiler command support alloc/lock/chunksize/chunktime option (#2647)
Browse files Browse the repository at this point in the history
  • Loading branch information
Winson-Huang authored Sep 7, 2023
1 parent f6351cb commit 3fcb654
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ public class ProfilerCommand extends AnnotatedCommand {
*/
private String event;

/**
* profile allocations with BYTES interval
* according to async-profiler README, alloc may contains non-numeric charactors
*/
private String alloc;

/**
* profile contended locks longer than DURATION ns
* according to async-profiler README, alloc may contains non-numeric charactors
*/
private String lock;

/**
* output file name for dumping
*/
Expand Down Expand Up @@ -166,6 +178,16 @@ public class ProfilerCommand extends AnnotatedCommand {
*/
private boolean total;

/**
* approximate size of JFR chunk in bytes (default: 100 MB)
*/
private String chunksize;

/**
* duration of JFR chunk in seconds (default: 1 hour)
*/
private String chunktime;

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

Expand Down Expand Up @@ -252,6 +274,18 @@ public void setEvent(String event) {
this.event = event;
}

@Option(longName = "alloc")
@Description("allocation profiling interval in bytes")
public void setAlloc(String alloc) {
this.alloc = alloc;
}

@Option(longName = "lock")
@Description("lock profiling threshold in nanoseconds")
public void setLock(String lock) {
this.lock = lock;
}

@Option(shortName = "t", longName = "threads", flag = true)
@Description("profile different threads separately")
public void setThreads(boolean threads) {
Expand Down Expand Up @@ -344,6 +378,18 @@ public void setTotal(boolean total) {
this.total = total;
}

@Option(longName = "chunksize")
@Description("approximate size limits for a single JFR chunk in bytes (default: 100 MB) or other units")
public void setChunksize(String chunksize) {
this.chunksize = chunksize;
}

@Option(longName = "chunktime")
@Description("approximate time limits for a single JFR chunk in second (default: 1 hour) or other units")
public void setChunktime(String chunktime) {
this.chunktime = chunktime;
}

private AsyncProfiler profilerInstance() {
if (profiler != null) {
return profiler;
Expand Down Expand Up @@ -411,6 +457,12 @@ private String executeArgs(ProfilerAction action) {
if (this.event != null) {
sb.append("event=").append(this.event).append(COMMA);
}
if (this.alloc!= null) {
sb.append("alloc=").append(this.alloc).append(COMMA);
}
if (this.lock!= null) {
sb.append("lock=").append(this.lock).append(COMMA);
}
if (this.file != null) {
sb.append("file=").append(this.file).append(COMMA);
}
Expand Down Expand Up @@ -467,6 +519,12 @@ private String executeArgs(ProfilerAction action) {
if (this.total) {
sb.append("total").append(COMMA);
}
if (this.chunksize != null) {
sb.append("chunksize=").append(this.chunksize).append(COMMA);
}
if (this.chunktime!= null) {
sb.append("chunktime=").append(this.chunktime).append(COMMA);
}

return sb.toString();
}
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 @@ -262,3 +262,22 @@ profiler stop -s -g -a -l --title <flametitle> --minwidth 15 --reverse
## 生成的火焰图里的 unknown

- https://github.com/jvm-profiling-tools/async-profiler/discussions/409

## 配置 locks/allocations 模式的阈值

当使用 lock 或 alloc event 进行 profiling 时,可以使用 `--lock``--alloc` 配置阈值,比如下列命令:

```bash
profiler start -e lock --lock 10ms
profiler start -e alloc --alloc 2m
```

会记录竞争时间超过 10ms 的锁(如果不指定时间单位,则使用 ns 为单位),或者以 2MB 的单位记录对内存的分配。

## 配置 JFR 块

当使用 JFR 作为输出格式时,可以使用 `--chunksize``--chunktime` 配置单个 JFR 块的大致容量(以 byte 为单位,默认 100 MB)和时间限制(默认值为 1 小时),比如:

```bash
profiler start -f profile.jfr --chunksize 100m --chunktime 1h
```
19 changes: 19 additions & 0 deletions site/docs/en/doc/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,22 @@ profiler stop -s -g -a -l --title <flametitle> --minwidth 15 --reverse
## The 'unknown' in profiler result

- https://github.com/jvm-profiling-tools/async-profiler/discussions/409

## Config locks/allocations profiling threshold

When profiling in locks or allocations event, you can use `--lock` or `--alloc` to config thresholds, for example:

```bash
profiler start -e lock --lock 10ms
profiler start -e alloc --alloc 2m
```

will profile contended locks longer than 10ms (default unit is ns if no unit is specified), or profile allocations with 2m BYTES interval.

## Config JFR chunks

When using JFR as output format, you can use `--chunksize` or `--chunktime` to config approximate size (in bytes, default value is 100MB) and time limits (default value is 1 hour) for a single JFR chunk. For example:

```bash
profiler start -f profile.jfr --chunksize 100m --chunktime 1h
```

0 comments on commit 3fcb654

Please sign in to comment.