I tried to use "cargo flamegraph" on Linux (Ubuntu 20.04 LTS).
The executable needs the CAP_PERFMON capability to run. Reasonable enough. Then it turns out the Ubuntu "setcap" program is broken, and doesn't recognize CAP_PERFMON. Somebody built "setcap" with the wrong library. Reported and fixed for CentOS/RedHat a few months back. I just reported it for Ubuntu. Amazed this didn't get noticed by someone else long ago. I guess nobody does this much.
Doing everything as root, or giving "flamegraph" root-level permissions, would work around this, but that's insecure.
The default permissions for perf have changed somewhat recently in Linux. To restore the old behavior, you can set /proc/sys/kernel/perf_event_paranoid. Values are as follows:
2 allow only user-space measurements (default since
Linux 4.6).
1 allow both kernel and user measurements (default
before Linux 4.6).
0 allow access to CPU-specific data but not raw
tracepoint samples.
-1 no restrictions.
I can not find anywhere in the linux kernel source that seems to deal with any values higher than two. Two and up seem to all be treated equally. Maybe it's a distro thing being used flag something for software other than the kernel?