gprof and execl() - is it possible?

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-06-09T03:36:12Z Indexed on 2010/06/09 3:42 UTC
Read the original article Hit count: 178

Filed under:
|
|
|

Background: I have a game (an old-school-esque MUD) which I've been attempting to profile with gprof. The documentation of gprof (on Linux 2.6) states that

The profiled program must call "exit"(2) or return normally for the profiling information to be saved in the gmon.out file.

Now, if I kill the server with the shutdown command, the application "returns normally" (i.e., main() returns) and I get a gmon.out to analyze. However, it's far more common to reboot the server. The reboot command does the following:

  1. Writes usernames and socket FD numbers to disc.
  2. Makes a call to execl().
  3. The new process looks for the stored data, picks up the FDs, and moves on.

I see the following error on the command line, as the whole process fails:

Profiling timer expired ./program

Question: Is it possible to get a gmon.out file from the execl()-calling process? Perhaps some environmental parameter to execl(), or else perhaps a different, gprof-friendly, system call to achieve the same effect (beginning a new process while preserving file descriptors)?

© Stack Overflow or respective owner

Related posts about c++

Related posts about profiling