Search code examples
eclipseprofilingperf

Eclipse profiling with perf - PERF_FLAG_FD_CLOEXEC failed with unexpected error 13 (permission denied)


I would like to learn more about profiling. In Eclipse CDT you have a button to trigger this action and it appears that (on Linux) it relies on perf as a default tool for this purpose.

I have installed perf and I'm exploring it's info and manpage. However I would also like to check how it's integrated into Eclipse CDT.

According to the official description no password is required to run the tool from the IDE. However I am getting

perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 13 (Permission denied)
perf_event_open(..., 0) failed unexpectedly with error 13 (Permission denied)
Error:
You may not have permission to collect stats.

Consider tweaking /proc/sys/kernel/perf_event_paranoid,
which controls use of the performance events system by
unprivileged users (without CAP_SYS_ADMIN).

The current value is 3:

  -1: Allow use of (almost) all events by all users
      Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK
>= 0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN
      Disallow raw tracepoint access by users without CAP_SYS_ADMIN
>= 1: Disallow CPU event access by users without CAP_SYS_ADMIN
>= 2: Disallow kernel profiling by users without CAP_SYS_ADMIN

To make this setting permanent, edit /etc/sysctl.conf too, e.g.:

    kernel.perf_event_paranoid = -1

/usr/bin/perf record --output=perf.data /home/rbaleksandar/Projects/Eclipse/workspace1/GameEngine/build/cmake.debug.linux.x86_64/bin/GameEngine ge.json 
Analysing recorded perf.data, please wait...
ERROR: Unable to find Perf version, please verify it is installed and on the run path

What should I do as a beginner profiler (pun intended)?


Solution

  • The answer is in the error message:

    To make this setting permanent, edit /etc/sysctl.conf too, e.g.:
    
    kernel.perf_event_paranoid = -1
    

    Also you can find another answer here:

    Use perf inside a docker container without --privileged