async-profiler 查看 jvm 支持的分析事件列表

问题描述

我正在尝试查看 jvm 支持的分析事件列表。如 doc 中所述,我使用了 list 命令,如下所示 -

root@vrni-platform:/home/ubuntu/async-profiler-2.0-linux-x64# ./profiler.sh list 10208
Basic events:
  cpu
  alloc
  lock
  wall
  itimer
Java method calls:
  ClassName.methodName
Perf events:
  page-faults
  context-switches
  cycles
  instructions
  cache-references
  cache-misses
  branches
  branch-misses
  bus-cycles
  L1-dcache-load-misses
  LLC-load-misses
  dTLB-load-misses
  mem:breakpoint
  trace:tracepoint

在上述输出中,我没有看到此 answer 中提到的事件。但是,如果我按照该答案中提到的那样执行上述事件,它似乎可以正常工作。

root@vrni-platform:/home/ubuntu/async-profiler-2.0-linux-x64# ./profiler.sh -e malloc -d 30 -f /tmp/flamegraph.html 10208
Profiling for 30 seconds
Done

enter image description here

有人可以让我知道如何查看特定 jvm 的 aysnc-profiler 支持的所有事件的列表吗?如果 listprofiler.sh 的正确参数,那么为什么 malloc 等会显示在所有事件列表下?

环境

ubuntu@vrni-platform:~/async-profiler-2.0-linux-x64# ./profiler.sh --version
Async-profiler 2.0 built on Mar 14 2021
copyright 2016-2021 Andrei Pangin
ubuntu@vrni-platform:~/async-profiler-2.0-linux-x64# uname -a
Linux vrni-platform 4.15.0-142-generic #146-Ubuntu SMP Tue Apr 13 01:11:19 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
ubuntu@vrni-platform:~/async-profiler-2.0-linux-x64$ java -version
openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment Zulu11.48+22-SA (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM Zulu11.48+22-SA (build 11.0.11+9-LTS,mixed mode)

解决方法

malloc 这里不是一个单独的事件。这只是一个执行断点的例子。

async-profiler 在 hardware breakpoints 的帮助下,可以跟踪对任何内存位置的访问。使用 perf-like syntax 作为硬件断点,您可以选择分析代码中任何给定地址的执行情况:

./profiler.sh -e mem:0x123450:x <pid>

可以指定本地函数名称而不是数字地址。 malloc 只是标准 C 库 (libc) 中函数的名称:

./profiler.sh -e mem:malloc:x <pid>

-e malloc 是上述事件描述符的快捷方式。如果 async-profiler 发现给定的事件名称对应于某个本地函数,它会分析该函数的执行情况。

除了 malloc,您还可以分析任何其他函数。例如,

  • -e pthread_start 查找谁启动了新线程(Java 和本机线程);
  • -e connect 来分析新的套接字连接;
  • -e JVM_GC 查找 System.gc() 的调用者;
  • -e G1CollectedHeap::humongous_obj_allocate 来分析 G1 巨大的分配;
  • -e Deoptimization::uncommon_trap 找到编译后的代码去优化的地方;

等等等等。在 JVM 中,在标准类库中,在 libc 中,有数以千计的本机函数。显然,在 async-profiler 帮助中列出所有这些实际上是不可能的。