简体   繁体   English

当可执行文件分叉另一个可执行文件时,不会创建gmon.out

[英]gmon.out is not created when executable forks another executable

I am using gprof for profiling. 我正在使用gprof进行性能分析。 But gmon.out is not created when I fork another executable inside the main executable which is compiled with option -pg. 但是当我在使用选项-pg编译的主可执行文件中分叉另一个可执行文件时,不会创建gmon.out。 Any idea how to resolve it. 知道如何解决它。

But gmon.out is not created when I fork another executable 但是当我分叉另一个可执行文件时,不会创建gmon.out

It probably does. 它可能会。 It simply has the same name as all the other gmon.out files. 它只是与所有其他gmon.out文件同名。 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. GNU以其无限的智慧,建议您要分析的每个子进程都在其自己的当前目录中执行。 Use mkdir and chdir in your code as needed. 根据需要在代码中使用mkdirchdir Since gmon.out is written out as the process finishes, it is only necessary to chdir before calling exit . 由于gmon.out在进程完成时写出,因此只需要在调用exit之前使用chdir

I also recommend looking at valgrind . 我也建议看看valgrind Among other nice things, it has its output files named something.somethingelse.$PID . 在其他好东西中,它的输出文件名为something.somethingelse.$PID

当您设置GMON_OUT_PREFIX=some_file_name环境变量时,gprof将为每个名为some_file_name.pid子进程创建其他gmon文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM