Skip to content

Perf

Last update: 05. March 2023 (Created: 19. February 2023)

Perf

Visualizers

Install (Debian): apt install linux-tools-<kernel-version> linux-perf-<kernel-version>

Compile applications with: -fno-omit-frame-pointer

# Recording Examples

# All processes with simple callstack for 30 seconds.
perf record -ag -- sleep 30

# 99 samples per second.
perf record -F 99 -ag -- sleep 30

# Specific process with simple callstack for 60 seconds.
Perf record -g -p <pid> -- sleep 60

# Specific process with dwarf-callstack
perf record --call-graph=dwarf -p <pid> -- sleep 60
perf record -F 99 --call-graph=dwarf -p <pid> -- sleep 60
# For firefox visualizer
perf record -a -g -F 1000 > perf.data
perf script -F +pid | gzip > perf.gz
# Analysis

# Output as Tree
perf report -n --stdio
perf report --call-graph --stdio -G

# Output as flamegraph
# http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html
# Flamegraphs need `flamegraph.pl` and `stackcollapse-perf.pl` from https://github.com/brendangregg/FlameGraph

perf script | ./stackcollapse-perf.pl > out.perf-folded
./flamegraph.pl out.perf-folded > perf-kernel.svg
# perf timechart can also be used to see the timing of processes better

# Records
perf timechart record

# Makes SVG
# WILL BE VERY BIG! TRY INKSCAPE OR EVEN BETTER ADOBE ILLUSTRATOR TO VIEW!
perf timechart
# Compiler Flags:

V1:
-g -fno-inline -fno-omit-frame-pointer -fno-optimize-sibling-calls -marm

V2:
-g -fno-inline -fno-omit-frame-pointer -marm -mapcs-frame

V3:
-g -fno-inline -fno-omit-frame-pointer -fno-optimize-sibling-calls -marm -mapcs-frame