Permissions

On some systems, using Perf hardware counters can be restricted by the value of /proc/sys/kernel/perf_event_paranoid.

perf_event_paranoid Description
3 Disable use of Perf events
2 Allow only user-space measurements
1 Allow kernel and user-space measurements
0 Allow access to CPU-specific data, but not raw trace‐point samples.
-1 No restrictions

The value of /proc/sys/kernel/perf_event_paranoid must be 2 or lower to collect Perf metrics. To set this until the next reboot, run the following commands:

sudo sysctl -w kernel.perf_event_paranoid=2

To permanently set the paranoid level, add the following line to /etc/sysctl.conf:

kernel.perf_event_paranoid=2