Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gmon.out is not created when executable forks another executable

Tags:

c++

linux

g++

gprof

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.

like image 449
quartz Avatar asked Mar 24 '23 01:03

quartz


2 Answers

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.

like image 111
n. 1.8e9-where's-my-share m. Avatar answered Apr 06 '23 09:04

n. 1.8e9-where's-my-share m.


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.

like image 23
marathon Avatar answered Apr 06 '23 09:04

marathon