views:

277

answers:

2

I'm working on a project where I need to find which functions get called in various Linux programs (written in C) given particular inputs. My current approach has been to compile a program with -pg (profiling option), run it, and find which functions get called by processing gprof's output. Only functions that are called at least once appear in the output file.

The apparent problem is that only one process can write to the gprof output file. If the program forks multiple processes, I don't get any profiling output from the other processes.

Is there any way to make gprof produce an output file for each process (maybe labelled by pid)? The manual suggests having each process change into a different directory, but I don't want to modify the source code to do this. Is there another tool for Linux that can help?

+3  A: 

Here they suggest using tprof:

Have you tried valgrind?

http://www.network-theory.co.uk/docs/valgrind/valgrind_17.html

--child-silent-after-fork=<yes|no> [default: no]

When enabled, Valgrind will not show any debugging or logging output for the child process resulting from a fork call. This can make the output less confusing (although more misleading) when dealing with processes that create children. It is particularly useful in conjunction with --trace-children=. Use of this flag is also strongly recommended if you are requesting XML output (--xml=yes), since otherwise the XML from child and parent may become mixed up, which usually makes it useless.

Tom
+2  A: 

Take a look at GCov: http://gcc.gnu.org/onlinedocs/gcc/Gcov.html

Dimitri Tcaciuc
gcov has the exact same problem. Child process' coverage are not reported.
caspin