OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [share/] [man/] [man1/] [or1knd-elf-gcov.1] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16)
2
.\"
3
.\" Standard preamble:
4
.\" ========================================================================
5
.de Sp \" Vertical space (when we can't use .PP)
6
.if t .sp .5v
7
.if n .sp
8
..
9
.de Vb \" Begin verbatim text
10
.ft CW
11
.nf
12
.ne \\$1
13
..
14
.de Ve \" End verbatim text
15
.ft R
16
.fi
17
..
18
.\" Set up some character translations and predefined strings.  \*(-- will
19
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23
.\" nothing in troff, for use with C<>.
24
.tr \(*W-
25
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26
.ie n \{\
27
.    ds -- \(*W-
28
.    ds PI pi
29
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31
.    ds L" ""
32
.    ds R" ""
33
.    ds C` ""
34
.    ds C' ""
35
'br\}
36
.el\{\
37
.    ds -- \|\(em\|
38
.    ds PI \(*p
39
.    ds L" ``
40
.    ds R" ''
41
'br\}
42
.\"
43
.\" Escape single quotes in literal strings from groff's Unicode transform.
44
.ie \n(.g .ds Aq \(aq
45
.el       .ds Aq '
46
.\"
47
.\" If the F register is turned on, we'll generate index entries on stderr for
48
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
49
.\" entries marked with X<> in POD.  Of course, you'll have to process the
50
.\" output yourself in some meaningful fashion.
51
.ie \nF \{\
52
.    de IX
53
.    tm Index:\\$1\t\\n%\t"\\$2"
54
..
55
.    nr % 0
56
.    rr F
57
.\}
58
.el \{\
59
.    de IX
60
..
61
.\}
62
.\"
63
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
64
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
65
.    \" fudge factors for nroff and troff
66
.if n \{\
67
.    ds #H 0
68
.    ds #V .8m
69
.    ds #F .3m
70
.    ds #[ \f1
71
.    ds #] \fP
72
.\}
73
.if t \{\
74
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
75
.    ds #V .6m
76
.    ds #F 0
77
.    ds #[ \&
78
.    ds #] \&
79
.\}
80
.    \" simple accents for nroff and troff
81
.if n \{\
82
.    ds ' \&
83
.    ds ` \&
84
.    ds ^ \&
85
.    ds , \&
86
.    ds ~ ~
87
.    ds /
88
.\}
89
.if t \{\
90
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
91
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
92
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
93
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
94
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
95
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
96
.\}
97
.    \" troff and (daisy-wheel) nroff accents
98
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
99
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
100
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
101
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
102
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
103
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
104
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
105
.ds ae a\h'-(\w'a'u*4/10)'e
106
.ds Ae A\h'-(\w'A'u*4/10)'E
107
.    \" corrections for vroff
108
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
109
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
110
.    \" for low resolution devices (crt and lpr)
111
.if \n(.H>23 .if \n(.V>19 \
112
\{\
113
.    ds : e
114
.    ds 8 ss
115
.    ds o a
116
.    ds d- d\h'-1'\(ga
117
.    ds D- D\h'-1'\(hy
118
.    ds th \o'bp'
119
.    ds Th \o'LP'
120
.    ds ae ae
121
.    ds Ae AE
122
.\}
123
.rm #[ #] #H #V #F C
124
.\" ========================================================================
125
.\"
126
.IX Title "GCOV 1"
127
.TH GCOV 1 "2012-11-29" "gcc-4.8.0" "GNU"
128
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
129
.\" way too many mistakes in technical documents.
130
.if n .ad l
131
.nh
132
.SH "NAME"
133
gcov \- coverage testing tool
134
.SH "SYNOPSIS"
135
.IX Header "SYNOPSIS"
136
gcov [\fB\-v\fR|\fB\-\-version\fR] [\fB\-h\fR|\fB\-\-help\fR]
137
     [\fB\-a\fR|\fB\-\-all\-blocks\fR]
138
     [\fB\-b\fR|\fB\-\-branch\-probabilities\fR]
139
     [\fB\-c\fR|\fB\-\-branch\-counts\fR]
140
     [\fB\-u\fR|\fB\-\-unconditional\-branches\fR]
141
     [\fB\-n\fR|\fB\-\-no\-output\fR]
142
     [\fB\-l\fR|\fB\-\-long\-file\-names\fR]
143
     [\fB\-p\fR|\fB\-\-preserve\-paths\fR]
144
     [\fB\-r\fR|\fB\-\-relative\-only\fR]
145
     [\fB\-f\fR|\fB\-\-function\-summaries\fR]
146
     [\fB\-o\fR|\fB\-\-object\-directory\fR \fIdirectory|file\fR]
147
     [\fB\-s\fR|\fB\-\-source\-prefix\fR \fIdirectory\fR]
148
     [\fB\-d\fR|\fB\-\-display\-progress\fR]
149
     \fIfiles\fR
150
.SH "DESCRIPTION"
151
.IX Header "DESCRIPTION"
152
\&\fBgcov\fR is a test coverage program.  Use it in concert with \s-1GCC\s0
153
to analyze your programs to help create more efficient, faster running
154
code and to discover untested parts of your program.  You can use
155
\&\fBgcov\fR as a profiling tool to help discover where your
156
optimization efforts will best affect your code.  You can also use
157
\&\fBgcov\fR along with the other profiling tool, \fBgprof\fR, to
158
assess which parts of your code use the greatest amount of computing
159
time.
160
.PP
161
Profiling tools help you analyze your code's performance.  Using a
162
profiler such as \fBgcov\fR or \fBgprof\fR, you can find out some
163
basic performance statistics, such as:
164
.IP "\(bu" 4
165
how often each line of code executes
166
.IP "\(bu" 4
167
what lines of code are actually executed
168
.IP "\(bu" 4
169
how much computing time each section of code uses
170
.PP
171
Once you know these things about how your code works when compiled, you
172
can look at each module to see which modules should be optimized.
173
\&\fBgcov\fR helps you determine where to work on optimization.
174
.PP
175
Software developers also use coverage testing in concert with
176
testsuites, to make sure software is actually good enough for a release.
177
Testsuites can verify that a program works as expected; a coverage
178
program tests to see how much of the program is exercised by the
179
testsuite.  Developers can then determine what kinds of test cases need
180
to be added to the testsuites to create both better testing and a better
181
final product.
182
.PP
183
You should compile your code without optimization if you plan to use
184
\&\fBgcov\fR because the optimization, by combining some lines of code
185
into one function, may not give you as much information as you need to
186
look for `hot spots' where the code is using a great deal of computer
187
time.  Likewise, because \fBgcov\fR accumulates statistics by line (at
188
the lowest resolution), it works best with a programming style that
189
places only one statement on each line.  If you use complicated macros
190
that expand to loops or to other control structures, the statistics are
191
less helpful\-\-\-they only report on the line where the macro call
192
appears.  If your complex macros behave like functions, you can replace
193
them with inline functions to solve this problem.
194
.PP
195
\&\fBgcov\fR creates a logfile called \fI\fIsourcefile\fI.gcov\fR which
196
indicates how many times each line of a source file \fI\fIsourcefile\fI.c\fR
197
has executed.  You can use these logfiles along with \fBgprof\fR to aid
198
in fine-tuning the performance of your programs.  \fBgprof\fR gives
199
timing information you can use along with the information you get from
200
\&\fBgcov\fR.
201
.PP
202
\&\fBgcov\fR works only on code compiled with \s-1GCC\s0.  It is not
203
compatible with any other profiling or test coverage mechanism.
204
.SH "OPTIONS"
205
.IX Header "OPTIONS"
206
.IP "\fB\-h\fR" 4
207
.IX Item "-h"
208
.PD 0
209
.IP "\fB\-\-help\fR" 4
210
.IX Item "--help"
211
.PD
212
Display help about using \fBgcov\fR (on the standard output), and
213
exit without doing any further processing.
214
.IP "\fB\-v\fR" 4
215
.IX Item "-v"
216
.PD 0
217
.IP "\fB\-\-version\fR" 4
218
.IX Item "--version"
219
.PD
220
Display the \fBgcov\fR version number (on the standard output),
221
and exit without doing any further processing.
222
.IP "\fB\-a\fR" 4
223
.IX Item "-a"
224
.PD 0
225
.IP "\fB\-\-all\-blocks\fR" 4
226
.IX Item "--all-blocks"
227
.PD
228
Write individual execution counts for every basic block.  Normally gcov
229
outputs execution counts only for the main blocks of a line.  With this
230
option you can determine if blocks within a single line are not being
231
executed.
232
.IP "\fB\-b\fR" 4
233
.IX Item "-b"
234
.PD 0
235
.IP "\fB\-\-branch\-probabilities\fR" 4
236
.IX Item "--branch-probabilities"
237
.PD
238
Write branch frequencies to the output file, and write branch summary
239
info to the standard output.  This option allows you to see how often
240
each branch in your program was taken.  Unconditional branches will not
241
be shown, unless the \fB\-u\fR option is given.
242
.IP "\fB\-c\fR" 4
243
.IX Item "-c"
244
.PD 0
245
.IP "\fB\-\-branch\-counts\fR" 4
246
.IX Item "--branch-counts"
247
.PD
248
Write branch frequencies as the number of branches taken, rather than
249
the percentage of branches taken.
250
.IP "\fB\-n\fR" 4
251
.IX Item "-n"
252
.PD 0
253
.IP "\fB\-\-no\-output\fR" 4
254
.IX Item "--no-output"
255
.PD
256
Do not create the \fBgcov\fR output file.
257
.IP "\fB\-l\fR" 4
258
.IX Item "-l"
259
.PD 0
260
.IP "\fB\-\-long\-file\-names\fR" 4
261
.IX Item "--long-file-names"
262
.PD
263
Create long file names for included source files.  For example, if the
264
header file \fIx.h\fR contains code, and was included in the file
265
\&\fIa.c\fR, then running \fBgcov\fR on the file \fIa.c\fR will
266
produce an output file called \fIa.c##x.h.gcov\fR instead of
267
\&\fIx.h.gcov\fR.  This can be useful if \fIx.h\fR is included in
268
multiple source files and you want to see the individual
269
contributions.  If you use the \fB\-p\fR option, both the including
270
and included file names will be complete path names.
271
.IP "\fB\-p\fR" 4
272
.IX Item "-p"
273
.PD 0
274
.IP "\fB\-\-preserve\-paths\fR" 4
275
.IX Item "--preserve-paths"
276
.PD
277
Preserve complete path information in the names of generated
278
\&\fI.gcov\fR files.  Without this option, just the filename component is
279
used.  With this option, all directories are used, with \fB/\fR characters
280
translated to \fB#\fR characters, \fI.\fR directory components
281
removed and unremoveable \fI..\fR
282
components renamed to \fB^\fR.  This is useful if sourcefiles are in several
283
different directories.
284
.IP "\fB\-r\fR" 4
285
.IX Item "-r"
286
.PD 0
287
.IP "\fB\-\-relative\-only\fR" 4
288
.IX Item "--relative-only"
289
.PD
290
Only output information about source files with a relative pathname
291
(after source prefix elision).  Absolute paths are usually system
292
header files and coverage of any inline functions therein is normally
293
uninteresting.
294
.IP "\fB\-f\fR" 4
295
.IX Item "-f"
296
.PD 0
297
.IP "\fB\-\-function\-summaries\fR" 4
298
.IX Item "--function-summaries"
299
.PD
300
Output summaries for each function in addition to the file level summary.
301
.IP "\fB\-o\fR \fIdirectory|file\fR" 4
302
.IX Item "-o directory|file"
303
.PD 0
304
.IP "\fB\-\-object\-directory\fR \fIdirectory\fR" 4
305
.IX Item "--object-directory directory"
306
.IP "\fB\-\-object\-file\fR \fIfile\fR" 4
307
.IX Item "--object-file file"
308
.PD
309
Specify either the directory containing the gcov data files, or the
310
object path name.  The \fI.gcno\fR, and
311
\&\fI.gcda\fR data files are searched for using this option.  If a directory
312
is specified, the data files are in that directory and named after the
313
input file name, without its extension.  If a file is specified here,
314
the data files are named after that file, without its extension.
315
.IP "\fB\-s\fR \fIdirectory\fR" 4
316
.IX Item "-s directory"
317
.PD 0
318
.IP "\fB\-\-source\-prefix\fR \fIdirectory\fR" 4
319
.IX Item "--source-prefix directory"
320
.PD
321
A prefix for source file names to remove when generating the output
322
coverage files.  This option is useful when building in a separate
323
directory, and the pathname to the source directory is not wanted when
324
determining the output file names.  Note that this prefix detection is
325
applied before determining whether the source file is absolute.
326
.IP "\fB\-u\fR" 4
327
.IX Item "-u"
328
.PD 0
329
.IP "\fB\-\-unconditional\-branches\fR" 4
330
.IX Item "--unconditional-branches"
331
.PD
332
When branch probabilities are given, include those of unconditional branches.
333
Unconditional branches are normally not interesting.
334
.IP "\fB\-d\fR" 4
335
.IX Item "-d"
336
.PD 0
337
.IP "\fB\-\-display\-progress\fR" 4
338
.IX Item "--display-progress"
339
.PD
340
Display the progress on the standard output.
341
.PP
342
\&\fBgcov\fR should be run with the current directory the same as that
343
when you invoked the compiler.  Otherwise it will not be able to locate
344
the source files.  \fBgcov\fR produces files called
345
\&\fI\fImangledname\fI.gcov\fR in the current directory.  These contain
346
the coverage information of the source file they correspond to.
347
One \fI.gcov\fR file is produced for each source (or header) file
348
containing code,
349
which was compiled to produce the data files.  The \fImangledname\fR part
350
of the output file name is usually simply the source file name, but can
351
be something more complicated if the \fB\-l\fR or \fB\-p\fR options are
352
given.  Refer to those options for details.
353
.PP
354
If you invoke \fBgcov\fR with multiple input files, the
355
contributions from each input file are summed.  Typically you would
356
invoke it with the same list of files as the final link of your executable.
357
.PP
358
The \fI.gcov\fR files contain the \fB:\fR separated fields along with
359
program source code.  The format is
360
.PP
361
.Vb 1
362
\&        ::
363
.Ve
364
.PP
365
Additional block information may succeed each line, when requested by
366
command line option.  The \fIexecution_count\fR is \fB\-\fR for lines
367
containing no code.  Unexecuted lines are marked \fB#####\fR or
368
\&\fB====\fR, depending on whether they are reachable by
369
non-exceptional paths or only exceptional paths such as \*(C+ exception
370
handlers, respectively.
371
.PP
372
Some lines of information at the start have \fIline_number\fR of zero.
373
These preamble lines are of the form
374
.PP
375
.Vb 1
376
\&        \-:0::
377
.Ve
378
.PP
379
The ordering and number of these preamble lines will be augmented as
380
\&\fBgcov\fR development progresses \-\-\- do not rely on them remaining
381
unchanged.  Use \fItag\fR to locate a particular preamble line.
382
.PP
383
The additional block information is of the form
384
.PP
385
.Vb 1
386
\&         
387
.Ve
388
.PP
389
The \fIinformation\fR is human readable, but designed to be simple
390
enough for machine parsing too.
391
.PP
392
When printing percentages, 0% and 100% are only printed when the values
393
are \fIexactly\fR 0% and 100% respectively.  Other values which would
394
conventionally be rounded to 0% or 100% are instead printed as the
395
nearest non-boundary value.
396
.PP
397
When using \fBgcov\fR, you must first compile your program with two
398
special \s-1GCC\s0 options: \fB\-fprofile\-arcs \-ftest\-coverage\fR.
399
This tells the compiler to generate additional information needed by
400
gcov (basically a flow graph of the program) and also includes
401
additional code in the object files for generating the extra profiling
402
information needed by gcov.  These additional files are placed in the
403
directory where the object file is located.
404
.PP
405
Running the program will cause profile output to be generated.  For each
406
source file compiled with \fB\-fprofile\-arcs\fR, an accompanying
407
\&\fI.gcda\fR file will be placed in the object file directory.
408
.PP
409
Running \fBgcov\fR with your program's source file names as arguments
410
will now produce a listing of the code along with frequency of execution
411
for each line.  For example, if your program is called \fItmp.c\fR, this
412
is what you see when you use the basic \fBgcov\fR facility:
413
.PP
414
.Vb 5
415
\&        $ gcc \-fprofile\-arcs \-ftest\-coverage tmp.c
416
\&        $ a.out
417
\&        $ gcov tmp.c
418
\&        90.00% of 10 source lines executed in file tmp.c
419
\&        Creating tmp.c.gcov.
420
.Ve
421
.PP
422
The file \fItmp.c.gcov\fR contains output from \fBgcov\fR.
423
Here is a sample:
424
.PP
425
.Vb 10
426
\&                \-:    0:Source:tmp.c
427
\&                \-:    0:Graph:tmp.gcno
428
\&                \-:    0:Data:tmp.gcda
429
\&                \-:    0:Runs:1
430
\&                \-:    0:Programs:1
431
\&                \-:    1:#include 
432
\&                \-:    2:
433
\&                \-:    3:int main (void)
434
\&                1:    4:{
435
\&                1:    5:  int i, total;
436
\&                \-:    6:
437
\&                1:    7:  total = 0;
438
\&                \-:    8:
439
\&               11:    9:  for (i = 0; i < 10; i++)
440
\&               10:   10:    total += i;
441
\&                \-:   11:
442
\&                1:   12:  if (total != 45)
443
\&            #####:   13:    printf ("Failure\en");
444
\&                \-:   14:  else
445
\&                1:   15:    printf ("Success\en");
446
\&                1:   16:  return 0;
447
\&                \-:   17:}
448
.Ve
449
.PP
450
When you use the \fB\-a\fR option, you will get individual block
451
counts, and the output looks like this:
452
.PP
453
.Vb 10
454
\&                \-:    0:Source:tmp.c
455
\&                \-:    0:Graph:tmp.gcno
456
\&                \-:    0:Data:tmp.gcda
457
\&                \-:    0:Runs:1
458
\&                \-:    0:Programs:1
459
\&                \-:    1:#include 
460
\&                \-:    2:
461
\&                \-:    3:int main (void)
462
\&                1:    4:{
463
\&                1:    4\-block  0
464
\&                1:    5:  int i, total;
465
\&                \-:    6:
466
\&                1:    7:  total = 0;
467
\&                \-:    8:
468
\&               11:    9:  for (i = 0; i < 10; i++)
469
\&               11:    9\-block  0
470
\&               10:   10:    total += i;
471
\&               10:   10\-block  0
472
\&                \-:   11:
473
\&                1:   12:  if (total != 45)
474
\&                1:   12\-block  0
475
\&            #####:   13:    printf ("Failure\en");
476
\&            $$$$$:   13\-block  0
477
\&                \-:   14:  else
478
\&                1:   15:    printf ("Success\en");
479
\&                1:   15\-block  0
480
\&                1:   16:  return 0;
481
\&                1:   16\-block  0
482
\&                \-:   17:}
483
.Ve
484
.PP
485
In this mode, each basic block is only shown on one line \*(-- the last
486
line of the block.  A multi-line block will only contribute to the
487
execution count of that last line, and other lines will not be shown
488
to contain code, unless previous blocks end on those lines.
489
The total execution count of a line is shown and subsequent lines show
490
the execution counts for individual blocks that end on that line.  After each
491
block, the branch and call counts of the block will be shown, if the
492
\&\fB\-b\fR option is given.
493
.PP
494
Because of the way \s-1GCC\s0 instruments calls, a call count can be shown
495
after a line with no individual blocks.
496
As you can see, line 13 contains a basic block that was not executed.
497
.PP
498
When you use the \fB\-b\fR option, your output looks like this:
499
.PP
500
.Vb 6
501
\&        $ gcov \-b tmp.c
502
\&        90.00% of 10 source lines executed in file tmp.c
503
\&        80.00% of 5 branches executed in file tmp.c
504
\&        80.00% of 5 branches taken at least once in file tmp.c
505
\&        50.00% of 2 calls executed in file tmp.c
506
\&        Creating tmp.c.gcov.
507
.Ve
508
.PP
509
Here is a sample of a resulting \fItmp.c.gcov\fR file:
510
.PP
511
.Vb 10
512
\&                \-:    0:Source:tmp.c
513
\&                \-:    0:Graph:tmp.gcno
514
\&                \-:    0:Data:tmp.gcda
515
\&                \-:    0:Runs:1
516
\&                \-:    0:Programs:1
517
\&                \-:    1:#include 
518
\&                \-:    2:
519
\&                \-:    3:int main (void)
520
\&        function main called 1 returned 1 blocks executed 75%
521
\&                1:    4:{
522
\&                1:    5:  int i, total;
523
\&                \-:    6:
524
\&                1:    7:  total = 0;
525
\&                \-:    8:
526
\&               11:    9:  for (i = 0; i < 10; i++)
527
\&        branch  0 taken 91% (fallthrough)
528
\&        branch  1 taken 9%
529
\&               10:   10:    total += i;
530
\&                \-:   11:
531
\&                1:   12:  if (total != 45)
532
\&        branch  0 taken 0% (fallthrough)
533
\&        branch  1 taken 100%
534
\&            #####:   13:    printf ("Failure\en");
535
\&        call    0 never executed
536
\&                \-:   14:  else
537
\&                1:   15:    printf ("Success\en");
538
\&        call    0 called 1 returned 100%
539
\&                1:   16:  return 0;
540
\&                \-:   17:}
541
.Ve
542
.PP
543
For each function, a line is printed showing how many times the function
544
is called, how many times it returns and what percentage of the
545
function's blocks were executed.
546
.PP
547
For each basic block, a line is printed after the last line of the basic
548
block describing the branch or call that ends the basic block.  There can
549
be multiple branches and calls listed for a single source line if there
550
are multiple basic blocks that end on that line.  In this case, the
551
branches and calls are each given a number.  There is no simple way to map
552
these branches and calls back to source constructs.  In general, though,
553
the lowest numbered branch or call will correspond to the leftmost construct
554
on the source line.
555
.PP
556
For a branch, if it was executed at least once, then a percentage
557
indicating the number of times the branch was taken divided by the
558
number of times the branch was executed will be printed.  Otherwise, the
559
message \*(L"never executed\*(R" is printed.
560
.PP
561
For a call, if it was executed at least once, then a percentage
562
indicating the number of times the call returned divided by the number
563
of times the call was executed will be printed.  This will usually be
564
100%, but may be less for functions that call \f(CW\*(C`exit\*(C'\fR or \f(CW\*(C`longjmp\*(C'\fR,
565
and thus may not return every time they are called.
566
.PP
567
The execution counts are cumulative.  If the example program were
568
executed again without removing the \fI.gcda\fR file, the count for the
569
number of times each line in the source was executed would be added to
570
the results of the previous run(s).  This is potentially useful in
571
several ways.  For example, it could be used to accumulate data over a
572
number of program runs as part of a test verification suite, or to
573
provide more accurate long-term information over a large number of
574
program runs.
575
.PP
576
The data in the \fI.gcda\fR files is saved immediately before the program
577
exits.  For each source file compiled with \fB\-fprofile\-arcs\fR, the
578
profiling code first attempts to read in an existing \fI.gcda\fR file; if
579
the file doesn't match the executable (differing number of basic block
580
counts) it will ignore the contents of the file.  It then adds in the
581
new execution counts and finally writes the data to the file.
582
.SS "Using \fBgcov\fP with \s-1GCC\s0 Optimization"
583
.IX Subsection "Using gcov with GCC Optimization"
584
If you plan to use \fBgcov\fR to help optimize your code, you must
585
first compile your program with two special \s-1GCC\s0 options:
586
\&\fB\-fprofile\-arcs \-ftest\-coverage\fR.  Aside from that, you can use any
587
other \s-1GCC\s0 options; but if you want to prove that every single line
588
in your program was executed, you should not compile with optimization
589
at the same time.  On some machines the optimizer can eliminate some
590
simple code lines by combining them with other lines.  For example, code
591
like this:
592
.PP
593
.Vb 4
594
\&        if (a != b)
595
\&          c = 1;
596
\&        else
597
\&          c = 0;
598
.Ve
599
.PP
600
can be compiled into one instruction on some machines.  In this case,
601
there is no way for \fBgcov\fR to calculate separate execution counts
602
for each line because there isn't separate code for each line.  Hence
603
the \fBgcov\fR output looks like this if you compiled the program with
604
optimization:
605
.PP
606
.Vb 4
607
\&              100:   12:if (a != b)
608
\&              100:   13:  c = 1;
609
\&              100:   14:else
610
\&              100:   15:  c = 0;
611
.Ve
612
.PP
613
The output shows that this block of code, combined by optimization,
614
executed 100 times.  In one sense this result is correct, because there
615
was only one instruction representing all four of these lines.  However,
616
the output does not indicate how many times the result was 0 and how
617
many times the result was 1.
618
.PP
619
Inlineable functions can create unexpected line counts.  Line counts are
620
shown for the source code of the inlineable function, but what is shown
621
depends on where the function is inlined, or if it is not inlined at all.
622
.PP
623
If the function is not inlined, the compiler must emit an out of line
624
copy of the function, in any object file that needs it.  If
625
\&\fIfileA.o\fR and \fIfileB.o\fR both contain out of line bodies of a
626
particular inlineable function, they will also both contain coverage
627
counts for that function.  When \fIfileA.o\fR and \fIfileB.o\fR are
628
linked together, the linker will, on many systems, select one of those
629
out of line bodies for all calls to that function, and remove or ignore
630
the other.  Unfortunately, it will not remove the coverage counters for
631
the unused function body.  Hence when instrumented, all but one use of
632
that function will show zero counts.
633
.PP
634
If the function is inlined in several places, the block structure in
635
each location might not be the same.  For instance, a condition might
636
now be calculable at compile time in some instances.  Because the
637
coverage of all the uses of the inline function will be shown for the
638
same source lines, the line counts themselves might seem inconsistent.
639
.PP
640
Long-running applications can use the \f(CW\*(C`_gcov_reset\*(C'\fR and \f(CW\*(C`_gcov_dump\*(C'\fR
641
facilities to restrict profile collection to the program region of
642
interest. Calling \f(CW\*(C`_gcov_reset(void)\*(C'\fR will clear all profile counters
643
to zero, and calling \f(CW\*(C`_gcov_dump(void)\*(C'\fR will cause the profile information
644
collected at that point to be dumped to \fI.gcda\fR output files.
645
.SH "SEE ALSO"
646
.IX Header "SEE ALSO"
647
\&\fIgpl\fR\|(7), \fIgfdl\fR\|(7), \fIfsf\-funding\fR\|(7), \fIgcc\fR\|(1) and the Info entry for \fIgcc\fR.
648
.SH "COPYRIGHT"
649
.IX Header "COPYRIGHT"
650
Copyright (c) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004,
651
2005, 2008, 2010  Free Software Foundation, Inc.
652
.PP
653
Permission is granted to copy, distribute and/or modify this document
654
under the terms of the \s-1GNU\s0 Free Documentation License, Version 1.3 or
655
any later version published by the Free Software Foundation; with the
656
Invariant Sections being \*(L"\s-1GNU\s0 General Public License\*(R" and \*(L"Funding
657
Free Software\*(R", the Front-Cover texts being (a) (see below), and with
658
the Back-Cover Texts being (b) (see below).  A copy of the license is
659
included in the \fIgfdl\fR\|(7) man page.
660
.PP
661
(a) The \s-1FSF\s0's Front-Cover Text is:
662
.PP
663
.Vb 1
664
\&     A GNU Manual
665
.Ve
666
.PP
667
(b) The \s-1FSF\s0's Back-Cover Text is:
668
.PP
669
.Vb 3
670
\&     You have freedom to copy and modify this GNU Manual, like GNU
671
\&     software.  Copies published by the Free Software Foundation raise
672
\&     funds for GNU development.
673
.Ve

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.