perf 和火焰图

RedEclipse on R7340

环境 & 版本

  • 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

  • perf list 'vmscan:*'

  • `perf list ‘kmem:*’
    k

  • 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 -e cycles

perf top

  • perf record -F 999 -p PID -g

    • 默认会在当前目录下生成 perf.data, 后面如果再执行之前的 perf.data 会自动重命名 perf.data.old
  • perf script | /path/to/FlameGraph/stackcollapse-perf.pl | /path/to/FlameGraph/framegraph.pl > result.svg

    • 生成火焰图需要这个脚本工具 FlameGraph,而且如果想看到详细的调用栈需要编译跟踪对象为 Debug 版本

References