1

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)?

rbaleksandar
  • 8,713
  • 7
  • 76
  • 161
  • 1
    https://superuser.com/questions/980632/run-perf-without-root-rights – LMC Aug 19 '21 at 23:11
  • 1
    You should set `kernel.perf_event_paranoid = 0`. That's sufficient to do profiling of CPU events for user-space and even for kernel-space. You need `sudo` to make that one change, but then you can use `perf` as a non-root user any time. – Peter Cordes Aug 19 '21 at 23:32

1 Answers1

0

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

Roman Ivasyshyn
  • 118
  • 1
  • 8
  • For most things you only need `0`; `-1` allows some kernel tracepoint stuff for non-root that isn't necessary for profiling user-space code. I use `0` on my own desktop, although I don't use docker so IDK if that's special for some reason. – Peter Cordes Dec 03 '21 at 06:31