如下是一個集成各類工具,生成java docker應用火焰圖的嘗試,仍是有缺陷的,更好的方式仍是使用async-profiler(簡單,全家桶)html
環境預備
- docker&&bindfs安裝
這個能夠參考相關文檔,比較簡單,yum 就能夠 - perf-agent-map 安裝
這個須要構建,使用了支持docker 的版本https://github.com/chbatey/perf-map-agent
構建代碼在 / 目錄java
git clone https://github.com/chbatey/perf-map-agent.git
cd perf-map-agent
cmake .
make
- flamescope 環境
version: "3"
services:
flamescope:
image: dalongrong/flamescope
ports:
- "5000:5000"
volumes:
- "./profiles:/profiles"
- 容器運行
一個tomcat 應用,添加了perf-map 掛載
docker run -d -p 8080:8080 -v /perf-map:/perf-map -e JAVA_OPTS='-XX:NativeMemoryTracking=summary -XX:+UnlockDiagnosticVMOptions -XX:+AlwaysPreTouch -XX:+UseG1GC -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PreserveFramePointer -XX:+PrintGCTimeStamps -XX:+PrintGC -XX:+UnlockDiagnosticVMOptions -XX:+ShowHiddenFrames' tomcat
- 掛載容器文件系統
查看tomcat 的pid,查看
docker inspect <containerid>
參考以下:linux
docker inspect ed041189bb1b
[
{
"Id": "ed041189bb1badbac2462c2855ccaf2b58d21b03904e20e9242fa017010a89ab",
"Created": "2019-12-24T14:41:13.44200869Z",
"Path": "catalina.sh",
"Args": [
"run"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 8317,
掛載git
mkdir -p /opt/mytomcat-perf/
bindfs /proc/8317/root /opt/mytomcat-perf
- 運行perf
支持cgroup 的信息獲取github
perf record -F 99 -e cpu-clock -e syscalls:* --cgroup=docker/ed041189bb1badbac2462c2855ccaf2b58d21b03904e20e9242fa017010a89ab -ag dwarf -- sleep 120
- 簡單壓測
ab -n 2000 -c 200 http://127.0.0.1:8080/
- 生成jvm jit perf map 信息
./docker-create-java-perf-map.sh ed041189bb1b 8317
效果docker
+ container=ed041189bb1b
+ host_pid=8317
++ docker exec ed041189bb1b jps
++ grep -v Jps
++ cut -f 1 -d ' '
+ container_pid=1
+ echo 'Container PID: 1'
Container PID: 1
+ sudo rm -rf /tmp/perf-8317.map
+ docker exec ed041189bb1b /perf-map/bin/create-java-perf-map.sh 1
+ docker exec ed041189bb1b cat /tmp/perf-1.map --
+ sudo chown root:root /tmp/perf-8317.map
- 生成報告
perf script --symfs=/opt/mytomcat-perf --kallsyms=/proc/kallsyms > mytomcat-agent-pef
- flamescope 查看信息
須要先啓動tomcat
效果
jvm
查看火焰圖
async
說明
經過以上比較多的工具,出來了火焰圖,可是仍是稍有複雜,使用async-profiler 會簡單點,文章寫的也比較簡單,後邊還須要仔細研究下工具
參考資料
https://github.com/chbatey/perf-map-agent
https://github.com/jvm-profiling-tools/async-profiler
https://github.com/jvm-profiling-tools/perf-map-agent
https://github.com/mpartel/bindfs
https://github.com/Netflix/flamescope
http://www.brendangregg.com/linuxperf.html