It is very easy to change gprof to do wall-clock profiling. The only 8 chars to replace are:
ITIMER_PROF -> ITIMER_REAL
SIGPROF -> SIGALRM
in the file glibc/sysdeps/posix/profil.c
, function __profil
, near the calls to setitimer
and sigaction
(more exact __Setitimer
and __sigaction
)
After the change any program which uses SIGALRM will be broken and any program which have no blocking-syscall restarting code can give wrong results.
Also, you can directly change int values in glibc binary (please, dont do this on system wide libc.so
, make a separate copy and give it to the program with LD_LIBRARY_PATH)
For binary patch, ITIMER_PROF is 2; ITIMER_REAL is 0; SIGPROF is 27 (0x1b); SIGALRM is 14 (0x0e). There are two places for each constant in function profil
of glibc.
Another way is to write a ptrace-debugger, which will change arguments of setitimer and sigaction functions at run-time.