java continous profiling

300 阅读1分钟

支持对 java 语言的性能分析,包括:

  • cpu
  • allocs, 内存分配
  • lock, 锁
  • wall,所有线程状态

以及将 java pprof 关联到对应的源代码。

所有的性能文件均针对线程做收集。

cpu

通过 perf 获取调用栈,asyncGetCallTrace 得到对应的函数。 这样得到的性能文件将会非常精确。 截屏2023-07-13 下午6.33.53.png

memory

通过接受 jdk.ObjectAllocationInNewTLAB, jdk.ObjectAllocationOutsideTLAB 事件,我们可以得到一段时间内的 java 堆内存分配。

截屏2023-07-13 下午6.35.56.png

同时,能够获取到这块内存是为了哪些对象分配的。

截屏2023-07-13 下午6.36.43.png

lock

通过监听 monitor 事件,我们可以获取 synchornized 关键字的耗时,包括想要同步的对象。 通过重载 park 函数,我们可以获取到 ReentrantLock,ReentrantReadWriteLock,Semaphore 等锁的好时。

截屏2023-07-13 下午6.40.27.png

wall

每隔一点时间,获取所有线程的调用栈以及状态。

  • running,运行中。
  • sleeping,睡眠io或者 block 等其他状态。

截屏2023-07-13 下午6.42.02.png

source code

通过反编译 jar 文件,成功的将 java 源代码与性能文件关联了起来。
1,jar xf jar file 2, decompile all jar file in lib directory 3, rewrite java file to make line number consistent

截屏2023-07-13 下午6.43.09.png