Execution profiling - CODE COVERAGE

Richard A. O'Keefe ok at quintus.uucp
Tue Aug 30 14:40:05 AEST 1988


> From: mdr at reed.UUCP (Mike Rutenberg)
> I'm interested in finding a code coverage tool which
> will let me know (ideally in terms of C constructs,
> but assembler is fine) what portions of my program
> has not been executed during a run.  Does anyone know
> of such beasts (ideally running under unix)?

Many versions of UNIX have a tool called "tcov".
For example, to analyse a program "fred.c", do
	cc -a fred.c	# produces a.out and fred.d
	a.out		# 
	tcov fred.c	# reads fred.c, fred.d, writes fred.tcov
The "fred.tcov" file is a listing of the source files named in the
"tcov" command, with each basic block preceded by a count of the
number of times it was executed.  Unexecuted basic blocks are
preceded by "#####".  A basic block is just a straight-line chunk
of code.  You can get counts for each statement too.  I find that
it is a big help in debugging.

Several people mentioned "prof".  Unfortunately, "prof" only tells
you about procedures, not basic blocks, so isn't much use for finding
out which parts of a program have been exercised, though System V
comes with a marker macro you can use to break it down a bit.



More information about the Comp.lang.c mailing list