6

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?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Steven
  • 811
  • 4
  • 23

1 Answers1

8
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

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847