Playing With Perf Probes - II
Problem: Need Sudo To Probe
perf probe -x ./code --add='add_with_sleep:0 sleep_us'
This will fail without sudo
unless you’re root. A solid setup that fixes most perf permissions issues:
#!/bin/bash
sudo mount -o remount,mode=755 /sys/kernel/debug
sudo mount -o remount,mode=755 /sys/kernel/debug/tracing
echo 0 | sudo tee /proc/sys/kernel/kptr_restrict
echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid
sudo chown root:tracing /sys/kernel/debug/tracing/uprobe_events
sudo chmod g+rw /sys/kernel/debug/tracing/uprobe_events
Probing Internal Library Functions
You’re going through the source code of your library, and there’s a specific internal function you want to profile. But it’s not listed in perf probe -x exec -F
. It probably isn’t listed in nm -a exec
either. If your functions are using this:
static __inline__ FN __attribute__((always_inline));
There’s no way they’re making it to the compiled output. This must be deleted. With __inline__
and inline
, things vary. There are two things I needed to get gcc to preserve my symbols up to the final .so
object:
- Remove
always_inline
from code - Add
-fvisibility=default
to my compiler flags - Add
-fno-inline
to counter the anti-debugging forces channeled by-O3
More references: