开发者

How to get .gcda files when the process is killed?

I have a binary build with -fprofile-arcs and -ftest-coverage. The binary is r开发者_StackOverflowun 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.


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 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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜