
Prepare a Linux Box for Profiling With perf_event_paranoid, kptr_restrict and CAP_PERFMON
Set kernel.perf_event_paranoid, kernel.kptr_restrict and CAP_PERFMON so perf can sample user and kernel code without running everything as root.
Tag
7 posts

Set kernel.perf_event_paranoid, kernel.kptr_restrict and CAP_PERFMON so perf can sample user and kernel code without running everything as root.

Use perf annotate to see which assembly instructions and source lines inside a hot function receive the most samples, and how to read skid correctly.

Build the perf tool from the Linux source tree with make -C tools/perf, check the feature report, and install it so its version matches the kernel you run.

Sample a program with perf record, rank functions with perf report, and read the Overhead, Command and Symbol columns to find the code that burns your CPU time.

Count cycles, instructions and cache misses with perf stat, then read instructions per cycle and miss ratios to tell compute from memory stalls.

Install perf from your distribution, check it matches the kernel, then run perf stat and perf record on a small C program to see where time goes.

Learn perf from first run to expert use: counting, sampling, call graphs, flame graphs, memory and scheduler analysis, tracing and a measurement workflow.