Arthas生成火焰圖命令
profiler start
報錯信息
Perf events unavailable. See stderr of the target process.
原因
官方列出了以下原因:
- /proc/sys/kernel/perf_event_paranoid 設置為受限模式(> = 2)(通常是這個原因)
- seccomp disables perf_event_open API in a container(seccomp禁用容器中的perf_event_open API。).
- OS runs under a hypervisor that does not virtualize performance counters.(操作系統在不虛擬化性能計數器的管理程序下運行。)
- perf_event_open API is not supported on this system, e.g. WSL.(該系統不支持perf_event_open API,例如WSL。)
解決方案
Docker
修改docker-compose.yml,增加
cap_add:
- SYS_ADMIN
例如:
version: '1'
services:
xxx:
container_name: xxx
hostname: xxx
image: xxx
...
# 使得arthas中可以打印火焰圖
cap_add:
- SYS_ADMIN
k8s
修改svc配置文件,增加
securityContext:
capabilities:
add:
- SYS_ADMIN
例如:
metadata:
labels:
service: hello-world
spec:
containers:
- image: "alpine:3.4"
command: ["/bin/echo", "hello", "world"]
# 使得arthas中可以打印火焰圖
securityContext:
capabilities:
add:
- SYS_ADMIN