LLVM Coverage GCDA Flush API


I ran into the bug/feature request that you cannot flush gcov buffers while the app is running. They are only called when you exit the program, since the flush functions are registered with atexit(). This is the bug report: http://llvm.org/bugs/show_bug.cgi?id=12144

I have what I think is a basic implementation of the __gcov_flush call, although I called this version __llvm_gcov_flush. Here is the diff https://gist.github.com/ashgti/4685743 if anyone would like to see it.

So, my question is where should I go from here? Do I need to email the exact patch to llvm-commits? This touches both the llvm and compiler-rt, so I don’t know if that changes anything.


We do have a gcov “flush” implementation. It should be emitted with the normal coverage code. Is it not showing up?


The way -ftest-coverage -fprofile-arcs works at the moment it only flushes via atexit(). This patch allows you to flush the coverage at any point by calling __llvm_gcov_flush the same way __gcov_flush works for gcc.

If there is another way of doing this, I might of missed it but I was looking for __gcov_flush and I did not find the equivalent in llvm at the moment.

__gcov_flush is added by the GCOVProfiling.cpp pass by GCOVProfiler::insertFlush.

Ah, my mistake. So this already works. I guess that bug is out of date, since this feature works already.

Why does __gcov_flush only flush the current compilation unit? For gcc __gcov_flush flushes all of the loaded files.

Is there a way to have __gcov_flush flush everything?

The reason was due to how gcc uses the __gcov_flush function. I haven't looked at the code in a while, but it might be doable to flush all CUs...


Yikes! It only flushes the counts for the current compilation unit? That sounds like a terrible bug. Can you file a bugzilla report, please?

http://llvm.org/bugs/show_bug.cgi?id=15191 Filed a bug with a small sample to show the problem.