QA
Senior LevelLinux Commands & SysAdmin

How do you profile CPU performance and generate FlameGraphs using Linux perf tools?

❓ Interview Prompt: Explain Linux perf framework, hardware PMU events, sampling CPU instruction pointers (perf record), and generating Brendan Gregg FlameGraphs.

'perf' (Performance Counters for Linux) interfaces with CPU Hardware Performance Monitoring Units (PMUs) to profile system performance:

FlameGraph Profiling Workflow:

1
Sample CPU Stack Traces: 'perf record -F 99 -g -p <PID> -- sleep 30'
2
Process Call Chains: 'perf script > out.perf'
3
Render FlameGraph: Convert stack traces into an SVG FlameGraph visual chart showing exact CPU time consumption per function call stack!

Code Implementation Example

bash
# Sample CPU call stacks for process PID 5678 at 99Hz for 20 seconds
sudo perf record -F 99 -p 5678 -g -- sleep 20

# Collapse stack traces and generate FlameGraph SVG
sudo perf script | ./stackcollapse-perf.pl | ./flamegraph.pl > cpu-flamegraph.svg
💡Profiling CPU performance and generating FlameGraph visual charts using perf.
🎯 Interview Key Takeaway

Use perf record and Brendan Gregg's FlameGraph tools to visually pinpoint CPU-bound bottlenecks in production applications.

#perf#FlameGraphs#CPU Profiling#Performance#Senior
Back to all Linux Commands & SysAdmin Questions→

More Linux Commands & SysAdmin Interview Questions

Beginner LevelLinux Commands & SysAdmin

How do Linux File Permissions (chmod, chown, chgrp) work in Octal and Symbolic notation?

Beginner LevelLinux Commands & SysAdmin

What is the Linux Filesystem Hierarchy Standard (/bin, /etc, /var, /usr, /opt, /tmp)?

Beginner LevelLinux Commands & SysAdmin

What are File Descriptors (0=stdin, 1=stdout, 2=stderr) and Redirection (>, >>, 2>&1)?