Get gprof for a wall clock profile?

I understand that by default gprof takes CPU time into account. Is there a way to get it in a wall clock based profile?

My program has a lot of disk I / O, so the processor time it uses is only part of the actual runtime. I need to know which parts of disk I / O take the most time.

+7
c ++ profiling gprof
source share
4 answers

You can measure the wall clock time using the profiler from google-perftools. To switch google profiler to wall clock mode, set the environment variable CPUPROFILE_REALTIME = 1.

+4
source share

gprof will not do this. Look at that .

And this.

In a nutshell: under gdb , run it and do Ctrl-Break or Ctrl-C 10 times in random order and display the call stack. If your I / O takes (for example) 60% of the time, and then (about) 6 out of 10 pauses, you will see it in writebuf or readbuf, and the lines of code that require I / O will be clearly displayed on the stack.

You can also use lsstack to get the same information.

+1
source share

You can use strace or cachegrind to correctly profile the code. strace will give you detailed information about the time spent on system calls, and cachegrind will give you a detailed analysis of resource usage.

+1
source share

It is very easy to modify gprof to profile wall clocks. The only 8 characters to replace are:

ITIMER_PROF -> ITIMER_REAL SIGPROF -> SIGALRM 

in the glibc/sysdeps/posix/profil.c , the __profil function, next to the setitimer and sigaction (more precise __Setitimer and __sigaction )

After the change, any program that uses SIGALRM will be interrupted, and any program that does not restart the syscall lock code may produce incorrect results.

In addition, you can directly modify int values ​​in a glibc binary (please do not do this throughout the libc.so system, create a separate copy and pass it to the program with LD_LIBRARY_PATH)

For a binary patch, ITIMER_PROF is 2; ITIMER_REAL - 0; SIGPROF is 27 (0x1b); SIGALRM is 14 (0x0e). There are two places for each constant in the profil glibc function.

Another way is to write ptrace-debugger, which will change the arguments to the setitimer and sigaction functions at run time.

0
source share

All Articles