Question

I am using gprof for profiling. But gmon.out is not created when I fork another executable inside the main executable which is compiled with option -pg. Any idea how to resolve it.

Was it helpful?

Solution

But gmon.out is not created when I fork another executable

It probably does. It simply has the same name as all the other gmon.out files. They just silently overwrite each other.

GNU, in all its infinite wisdom, recommends that each child process that you want to profile be executed in its own current directory. Use mkdir and chdir in your code as needed. Since gmon.out is written out as the process finishes, it is only necessary to chdir before calling exit.

I also recommend looking at valgrind. Among other nice things, it has its output files named something.somethingelse.$PID.

OTHER TIPS

when you set the GMON_OUT_PREFIX=some_file_name environment variable, gprof will create additional gmon files for each child process with the name some_file_name.pid.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top