Linux – Do I need root (admin) permissions to run userspace ‘perf’ tool? (perf events are enabled in Linux kernel)

kernellinuxnot-root-userperf-event

Do I need to have to run perf userspace tool as system administrator (root), or can I run it (or at least some subcommands) as an ordinary user?

Best Answer

What you can do with perf without being root depends on the kernel.perf_event_paranoid sysctl setting.

  • kernel.perf_event_paranoid = 2: you can't take any measurements. The perf utility might still be useful to analyse existing records with perf ls, perf report, perf timechart or perf trace.
  • kernel.perf_event_paranoid = 1: you can trace a command with perf stat or perf record, and get kernel profiling data.
  • kernel.perf_event_paranoid = 0: you can trace a command with perf stat or perf record, and get CPU event data.
  • kernel.perf_event_paranoid = -1: you get raw access to kernel tracepoints (specifically, you can mmap the file created by perf_event_open, I don't know what the implications are).
Related Question