perf cheatsheet
- sources
- Quick ref
- Concepts
- Code path:
- How it works
- ftrace event tracing
- Top-down analysis
- MISC::tooltips
- MISC::How does perf work
- MISC::TPEBS (Intel)
- MISC::TRIVIAS
# sources
# Quick ref
Listing supported events:
$ perf list
Manually tackling ftrace:
# set trace points for kmalloc
$ echo kmalloc > /sys/kernel/debug/tracing/set_event
$ cat /sys/kernel/debug/tracing/trace
# Concepts
- top-down analysis
- https://ieeexplore.ieee.org/document/6844459/
perf Events
- HW events / HW cache events: events measured by processor’s PMU.
- Software Events: events measurable by kernel counter. (e.g. cpu-clock, page-faults)
- tracepoint events: code locations built into the kernel to collect trace information
- probe events: user-defined events dynamically inserted into the kernel
# Code path:
Slides Perf for User Space Program Analysis, Tetsuo Takata, NTT DATA CORP.
perf_event_open
API
userspace commands are commited via perf_event_open
syscall, which may
- register sw event handler.
- enable ftrace events.
- enable kprobes
- configure PMU (hardware Performance Monitor Units)
Sampling
perf module collects samples what about user space function tracing?) when an
event occurs. Collected data includes {IP, user/kernel stack, timer, HW
stuffs}. The collected data are written to a dedicated perf buffer to avoid
kernel-to-user copying.
The triggering events could be HW event, interrupt/exception event (timer irq, page fault..) or kernel SW event (context switch, cpu migration..)
# How it works
https://alex.dzyoba.com/blog/perf/
# ftrace event tracing
https://alex.dzyoba.com/blog/ftrace/
ftrace provides lockless ringbuffer framework; tracers builds the actual tracings
- function - default tracer
- function_graph
- latency tracers: {irqsoff, preempoff, preemptirqsoff, wakeup etc.}
- additional features: kernel tracepoints, kprobes, blktrace ..
function tracing
events tracing
kprobes tracing
# Top-down analysis
# MISC::tooltips
perf privileges / permissions
# MISC::How does perf work
# MISC::TPEBS (Intel)
- TPEBS: Timed Process Event Based Sampling1
- TMA: Top-down Microarchitecture Analysis
# MISC::TRIVIAS
there are tools built upon the same kernel perf support: {perf, oprofile, gprof, sysprof}. Perf is the most versatile and most relevant one.