进程被杀死时如何获取.gcda文件?

发布于 2024-10-06 17:38:20 字数 333 浏览 4 评论 0原文

我有一个带有 -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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倾其所爱 2024-10-13 17:38:20

这可能有效:
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.

紫轩蝶泪 2024-10-13 17:38:20

SIGKILL 是一个“硬”终止信号,应用程序无法捕获它。因此,应用程序没有机会写出 .gcda 文件。

我看到两个选项:

  1. 捕获除 SIGKILL 之外的信号:任何明智的进程监视器都应首先发送 SIGTERMinit 和我遇到的批处理管理器就是这样做的。 SIGKILL 是最后的手段,因此只能在 SIGTERM 之后发送,然后是一个宽限期。
  2. 解决方法:通过获取 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:

  1. Catch signals other than SIGKILL: any sensible process monitor should send a SIGTERM first. init and the batch managers I've encountered do this. SIGKILL is a last resort, so it should be sent only after SIGTERM followed by a grace period.
  2. Workaround: run the program via an intermediate program that gets the SIGKILL; have the actual program check periodically (or in a separate thread) if its parent still lives, and if not, have it exit gracefully.
疾风者 2024-10-13 17:38:20

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文