Wednesday, June 03, 2009

kill, exit(), _exit() and issues getting gcov results

Hi,

We are currently running code coverage for MySQL Cluster testing and have hit a few bumps along the road when it cam to collecting the "block" coverage for the NDBD.

I wanted to share them here for others that might run into similar frustrations when doing testing code coverage.

Gcov accumulates during each run information on which functions and lines of code are called and a total for the times called.

The problem comes from when gcov dumps this information out. The actual data is dumped on the "exit" of the program.

After much time tracking this issue down, it turns out that the NDBD code had been changed to use _exit() instead of just exit()

What is the difference?

exit()
Terminate the process after cleanup.

_exit()
Terminate process immediately.

So by calling _exit(), gcov never had a chance to dump the data that it had collected.

So the quick workaround to this is to wrap all the _exit() calls with an #ifndef

i.e.

#ifndef HAVE_gcov
_exit(0)
#else
exit(0)
#endif

Question: Why use the _exit? If you have trouble with a program hanging after the exit() has been called a solution is to use _exit().

Then we also found that some of the testing was using the "kill -9" to end the Cluster instance. This, of course, is the same as calling _exit().

So if you are using gcov, and not getting results, the above may have to do with your frustration.

Hope this saves someone some time and frustration!!!

Cheers,
/Jeb

2 comments:

Android_Feverista said...

Thanks. This was helpful.

Anonymous said...

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!