进程被杀死时如何获取.gcda文件?
我有一个带有 -fprofile-arcs
和 -ftest-coverage
的二进制版本。该二进制文件由进程监视器运行,该监视器将进程作为子进程生成。然后,当我想要进程退出时,我必须通过进程监视器。它向进程发送一个SIGKILL
。我发现在这种情况下不会生成 .gcda
文件。我能做些什么?
编辑:实际上进程监视器首先尝试使进程退出。但是,当用户发出停止进程的命令时,ProcessMonitor 库(在每个进程中使用)调用 _exit
而不是 exit
。这是一切麻烦的根源。
I have a binary build with -fprofile-arcs
and -ftest-coverage
. The binary is run by a process monitor which spawns the process as a child process. Then, when I want the process to exit, I have to go through the process monitor. It sends a SIGKILL
to the process. I found out that .gcda
files do not generate in this case. What can I do?
EDIT: Actually the process monitor first tries to make the process exit. However, the ProcessMonitor library (used in each process) calls _exit
instead of exit
when the user issues a command to stop the process. This is the cause of all trouble.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能有效:
http://nixcraft.com/coding-general/12544-gcov-g.html
总之:在程序中调用 __gcov_flush(),可能在信号处理程序中或在执行期间定期调用。
如果是 C++ 代码,请记住对函数进行 extern“C” 声明。
还要记住使用某种预处理器 ifdef ,以便程序在未使用分析构建时不会调用它。
This might work:
http://nixcraft.com/coding-general/12544-gcov-g.html
In summary: call __gcov_flush() in the program, possibly in a signal handler or periodically during execution.
If C++ code remember to make a extern "C" declaration of the function.
Also remember to use some kind of preprocessor ifdef so that the program does not call it when not built with profiling.
SIGKILL
是一个“硬”终止信号,应用程序无法捕获它。因此,应用程序没有机会写出.gcda
文件。我看到两个选项:
SIGKILL
之外的信号:任何明智的进程监视器都应首先发送SIGTERM
。init
和我遇到的批处理管理器就是这样做的。SIGKILL
是最后的手段,因此只能在SIGTERM
之后发送,然后是一个宽限期。SIGKILL
的中间程序运行该程序;让实际的程序定期(或在单独的线程中)检查其父级是否仍然存在,如果没有,则让它正常退出。SIGKILL
is a "hard" kill signal, that cannot be caught by the application. Therefore, the app has no chance to write out the.gcda
file.I see two options:
SIGKILL
: any sensible process monitor should send aSIGTERM
first.init
and the batch managers I've encountered do this.SIGKILL
is a last resort, so it should be sent only afterSIGTERM
followed by a grace period.SIGKILL
; have the actual program check periodically (or in a separate thread) if its parent still lives, and if not, have it exit gracefully.Afaik 编译器(IntelC 也是如此)仅在退出处理程序中存储分析统计信息。
那么如何以某种方式告诉进程退出而不是杀死它呢?
就像添加一个 SIGKILL 处理程序一样,其中包含 exit() ?
Afaik compilers (IntelC too) only store profiling stats in exit handler.
So what about somehow telling the process to quit, instead of killing it?
Like adding a SIGKILL handler maybe, with exit() in it?