I tried to use perf stat
with LD_PRELOAD
as prefix for executable such as:
perf stat LD_PRELOAD=$PWD/../user/preload.so ./write 1
It seems not work for perf, are there any way to achieve it?
perf stat env LD_PRELOAD=.... ./write 1
That should work, although that means /usr/bin/env
is the process being profiled so you're getting its overhead, too. At least it's cheaper than a command like sh -c 'LD_PRELOAD=... exec ./write 1'
.
If startup overhead becomes a problem, you can have your write
itself fork/exec perf stat -p <PID>
on itself. perf stat for part of program