使用gcc -pg -g编译后,不会写入gmon.out [英] gmon.out is not written after compiling with gcc -pg -g

查看:170
本文介绍了使用gcc -pg -g编译后,不会写入gmon.out的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 gcc -pg -g 编译C ++程序(至少,这些是我在Makefile中提供的参数;没有什么命令的硬证据执行)。程序运行到正常完成,CWD设置为我的主目录。没有gmon.out文件。

Compiled a C++ program using gcc -pg -g (at least, those are the args I gave in the Makefile; don't have any hard evidence of what command was executed). Program ran to normal completion with CWD set to my home directory. No gmon.out file written.

gcc是4.4.7。 OS是centos 6。

gcc is 4.4.7. OS is centos 6.

我的程序是由一个手工滚动的Perl守护进程使用fork / exec启动的。我验证CWD是我的主目录,并且它是可写的,通过让守护进程在执行我的目标程序之前执行 touch foo 。至于我已经能够研究,这应该不会影响程序的分析或写gmon.out当它终止(通常)。

My program was launched by a hand-rolled Perl daemon using fork/exec. I've verified that the CWD is my home directory, and that it's writeable, by having the daemon execute touch foo just before exec'ing my target program. As far as I've been able to research, this shouldn't have affected the program's profiling or writing gmon.out when it terminated (normally).

推荐答案

进入同样的问题,在CentOS 7上的g ++ 4.8.2。 -pg 是存在的编译和链接,运行过程&它会正常退出,不会生成 gmon.out

Ran into this same issue, g++ 4.8.2 on CentOS 7. -pg was present for both compiling and linking, run the process & it exits normally, no gmon.out generated.

我通过替换 _exit(status)退出(状态)。注意前者是_exit(3),一个系统调用,后者是exit(2),一个标准库方法。

I fixed this by replacing a call to _exit(status) with exit(status). Note that the former is _exit(3), a system call, and the latter is exit(2), a standard library method.

为什么这样工作?从 gprof 手册页:

Why does this work? From the gprof man page:


剖析程序必须调用exit

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

很显然,gmon.out的写法是取决于(较高级别)出口(2)。所以,检查以确保代码使用exit(2)(从stdlib)和不_exit(3)(系统调用)。

Apparently the writing of gmon.out is dependent on (the higher-level) exit(2). So, check to be sure the code is using exit(2) (from stdlib) and not _exit(3) (system call).

这篇关于使用gcc -pg -g编译后,不会写入gmon.out的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆