perf 和火焰图

环境 & 版本

  • Linux 5.10.16.3-microsoft-standard-WSL2 x86_64 x86_64
  • Ubuntu 20.04.2 LTS
  • perf version 5.10.16.3

NOTE: 如果没有特别说明,以下perf命令都在root权限下执行

查询 & 罗列

列出Virtual Memory相关的static tracepoint

vmscan

vmscan:*

kmem

kmem:*

perf stat

1
perf stat -a sleep

tracepoint 使能

通过 debugfs 中的相应文件使能 tracepoint

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root@sie-luc:~# find /sys/kernel/debug/tracing/events/ -type d| grep -E 'dma|gpu'
/sys/kernel/debug/tracing/events/dma_fence
/sys/kernel/debug/tracing/events/dma_fence/dma_fence_emit
/sys/kernel/debug/tracing/events/dma_fence/dma_fence_init
/sys/kernel/debug/tracing/events/dma_fence/dma_fence_destroy
/sys/kernel/debug/tracing/events/dma_fence/dma_fence_enable_signal
/sys/kernel/debug/tracing/events/dma_fence/dma_fence_signaled
/sys/kernel/debug/tracing/events/dma_fence/dma_fence_wait_start
/sys/kernel/debug/tracing/events/dma_fence/dma_fence_wait_end
root@sie-luc:~# cat /sys/kernel/debug/tracing/events/dma_fence/dma_fence_enable_signal/
cat: /sys/kernel/debug/tracing/events/dma_fence/dma_fence_enable_signal/: Is a directory
root@sie-luc:~# cat /sys/kernel/debug/tracing/events/dma_fence/dma_fence_enable_signal/
enable filter format id trigger
root@sie-luc:~# cat /sys/kernel/debug/tracing/events/dma_fence/dma_fence_enable_signal/enable
0

常用命令

  • perf top
  • perf record -F 999 -p PID -g
    上面输出的结果默认是 perf.data, 如果要生成火焰图还要进行以下几步:
    • perf script | /path/to/FlameGraph/stackcollapse-perf.pl | /path/to/FlameGraph/framegraph.pl > result.svg

FlameGraph