This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcov questions
- From: Jim Wilson <jimw at sifive dot com>
- To: "daro_ox at o2 dot pl" <daro_ox at o2 dot pl>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Thu, 9 Aug 2018 11:25:48 -0700
- Subject: Re: gcov questions
- References: <f20ba68071f04e8692f18b4a17cbe4c9@grupawp.pl>
On 08/09/2018 02:38 AM, daro_ox@o2.pl wrote:
Hello, I wanted to ask what model for
branch coverage does gcov use?
There is a comment at the start of gcc/profile.c that gives some details
on how it works. It is computing execution counts for edges in the
control flow graph. As for which edges get instrumented, basically, you
construct a control flow graph, create a minimal spanning tree to cover
the graph, and then you only need to instrument the edges not on the
spanning tree, plus the function entry point. You can compute the rest
of the edge counts from that. Then there are some tricks to improve
efficiency by putting frequently executed edges on the minimal spanning
tree, so that infrequently edges get instrumented.
Gcov was originally written in 1990, based on an idea that came from
Knuth's Art of Computer Programming. Ball & Larus wrote a nice paper in
1994 that does a good job of covering the methods used, though they may
not have been aware of gcov at the time as it hadn't been accepted into
GCC yet. This is "Optimally Profiling and Tracing Programs" TOPLAS July
1994. I don't know if there are free copies of that available. There
may be better references available now, as these techniques are pretty
widely known nowadays
Jim