On this page
Deep Dive into perf
Coverage: perf record/report/annotate → Flame Graph → perf stat → PEBS → perf probe → Performance Analysis Methodology Applicable to: Linux perf_events (kernel 2.6.31+)
perf stat: CPU Performance Counters
# Counting mode: Hardware events during the entire program execution
# Output:
# task-clock: # Actual CPU time
# cycles: # CPU cycles (can be affected by frequency scaling; use cycles:u to restrict to user space)
# instructions: # Number of executed instructions
# IPC: # instructions/cycles (>1 = good superscalar utilization)
# branches: # Branch instructions
# branch-misses: # Branch prediction misses
# cache-misses: # Cache misses
# context-switches: # Context switches
# page-faults: # Page faults
# Key Metrics:
# IPC < 0.5: Severe stalling (cache miss, branch miss, data dependency)
# IPC > 2: High superscalar utilization
# branch-miss rate > 5%: Branch prediction issues
# cache-miss rate > 10%: Data locality issues
# Specify events:
perf record: Sampling
# Sampling (default cycles, sampling rate 4000 Hz):
# Reporting:
# Annotate (mixed source code + assembly + sampling):
# Real-time top:
Flame Graph
# 1. Sampling:
# 2. Generate Flame Graph (Brendan Gregg's tools):
# Or in one line:
| |
perf probe: Dynamic Probing
# Add a probe point to any user-space function:
# Add a probe point at any line:
# Record:
# View added probe points:
# Delete:
PEBS: Precise Sampling
# Default sampling: Reads instruction pointer after interrupt (may be imprecise, skid)
# PEBS (Precise Event-Based Sampling): Hardware records precise IP
System-Level Analysis
# System-wide sampling (requires root):
# Filter by process:
# Filter by CPU:
# CPU utilization breakdown (topdown):
# frontend bound / backend bound / bad speculation / retiring
Performance Analysis Methodology
References
- Documentation: https://perf.wiki.kernel.org, Brendan Gregg's perf examples
- Tools: https://github.com/brendangregg/FlameGraph
- Books: "Systems Performance" (Brendan Gregg), "BPF Performance Tools"
Keywords: perf, PEBS, IPC, cache-misses, flame graph, perf probe, topdown, branch prediction