annotate gcc/doc/gcov.texi @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1 @c Copyright (C) 1996-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 @c This is part of the GCC manual.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 @c For copying conditions, see the file gcc.texi.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 @ignore
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 @c man begin COPYRIGHT
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
7 Copyright @copyright{} 1996-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Permission is granted to copy, distribute and/or modify this document
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
10 under the terms of the GNU Free Documentation License, Version 1.3 or
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 any later version published by the Free Software Foundation; with the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 Invariant Sections being ``GNU General Public License'' and ``Funding
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 Free Software'', the Front-Cover texts being (a) (see below), and with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 the Back-Cover Texts being (b) (see below). A copy of the license is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 included in the gfdl(7) man page.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 (a) The FSF's Front-Cover Text is:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 A GNU Manual
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 (b) The FSF's Back-Cover Text is:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 You have freedom to copy and modify this GNU Manual, like GNU
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 software. Copies published by the Free Software Foundation raise
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 funds for GNU development.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 @c man end
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 @c Set file name and title for the man page.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 @setfilename gcov
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 @settitle coverage testing tool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 @end ignore
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 @node Gcov
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 @chapter @command{gcov}---a Test Coverage Program
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 @command{gcov} is a tool you can use in conjunction with GCC to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 test code coverage in your programs.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 @menu
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 * Gcov Intro:: Introduction to gcov.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 * Invoking Gcov:: How to use gcov.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 * Gcov and Optimization:: Using gcov with GCC optimization.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 * Gcov Data Files:: The files used by gcov.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 * Cross-profiling:: Data file relocation.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 @end menu
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 @node Gcov Intro
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 @section Introduction to @command{gcov}
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 @c man begin DESCRIPTION
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 @command{gcov} is a test coverage program. Use it in concert with GCC
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 to analyze your programs to help create more efficient, faster running
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 code and to discover untested parts of your program. You can use
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 @command{gcov} as a profiling tool to help discover where your
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 optimization efforts will best affect your code. You can also use
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 @command{gcov} along with the other profiling tool, @command{gprof}, to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 assess which parts of your code use the greatest amount of computing
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 time.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 Profiling tools help you analyze your code's performance. Using a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 profiler such as @command{gcov} or @command{gprof}, you can find out some
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 basic performance statistics, such as:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 @itemize @bullet
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 @item
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 how often each line of code executes
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 @item
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 what lines of code are actually executed
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 @item
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 how much computing time each section of code uses
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 @end itemize
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 Once you know these things about how your code works when compiled, you
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 can look at each module to see which modules should be optimized.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 @command{gcov} helps you determine where to work on optimization.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 Software developers also use coverage testing in concert with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 testsuites, to make sure software is actually good enough for a release.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 Testsuites can verify that a program works as expected; a coverage
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 program tests to see how much of the program is exercised by the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 testsuite. Developers can then determine what kinds of test cases need
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 to be added to the testsuites to create both better testing and a better
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 final product.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 You should compile your code without optimization if you plan to use
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 @command{gcov} because the optimization, by combining some lines of code
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 into one function, may not give you as much information as you need to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 look for `hot spots' where the code is using a great deal of computer
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 time. Likewise, because @command{gcov} accumulates statistics by line (at
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 the lowest resolution), it works best with a programming style that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 places only one statement on each line. If you use complicated macros
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 that expand to loops or to other control structures, the statistics are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 less helpful---they only report on the line where the macro call
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 appears. If your complex macros behave like functions, you can replace
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 them with inline functions to solve this problem.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 @command{gcov} creates a logfile called @file{@var{sourcefile}.gcov} which
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 indicates how many times each line of a source file @file{@var{sourcefile}.c}
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 has executed. You can use these logfiles along with @command{gprof} to aid
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 in fine-tuning the performance of your programs. @command{gprof} gives
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 timing information you can use along with the information you get from
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 @command{gcov}.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 @command{gcov} works only on code compiled with GCC@. It is not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 compatible with any other profiling or test coverage mechanism.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 @c man end
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 @node Invoking Gcov
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 @section Invoking @command{gcov}
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 @smallexample
111
kono
parents: 67
diff changeset
114 gcov @r{[}@var{options}@r{]} @var{files}
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 @end smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 @command{gcov} accepts the following options:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 @ignore
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 @c man begin SYNOPSIS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 gcov [@option{-v}|@option{--version}] [@option{-h}|@option{--help}]
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 [@option{-a}|@option{--all-blocks}]
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 [@option{-b}|@option{--branch-probabilities}]
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 [@option{-c}|@option{--branch-counts}]
111
kono
parents: 67
diff changeset
125 [@option{-d}|@option{--display-progress}]
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 [@option{-f}|@option{--function-summaries}]
111
kono
parents: 67
diff changeset
127 [@option{-i}|@option{--intermediate-format}]
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
128 [@option{-j}|@option{--human-readable}]
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
129 [@option{-k}|@option{--use-colors}]
111
kono
parents: 67
diff changeset
130 [@option{-l}|@option{--long-file-names}]
kono
parents: 67
diff changeset
131 [@option{-m}|@option{--demangled-names}]
kono
parents: 67
diff changeset
132 [@option{-n}|@option{--no-output}]
kono
parents: 67
diff changeset
133 [@option{-o}|@option{--object-directory} @var{directory|file}]
kono
parents: 67
diff changeset
134 [@option{-p}|@option{--preserve-paths}]
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
135 [@option{-q}|@option{--use-hotness-colors}]
111
kono
parents: 67
diff changeset
136 [@option{-r}|@option{--relative-only}]
kono
parents: 67
diff changeset
137 [@option{-s}|@option{--source-prefix} @var{directory}]
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
138 [@option{-t}|@option{--stdout}]
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 [@option{-u}|@option{--unconditional-branches}]
111
kono
parents: 67
diff changeset
140 [@option{-x}|@option{--hash-filenames}]
kono
parents: 67
diff changeset
141 @var{files}
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 @c man end
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 @c man begin SEEALSO
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entry for @file{gcc}.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 @c man end
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 @end ignore
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 @c man begin OPTIONS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 @table @gcctabopt
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 @item -a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 @itemx --all-blocks
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 Write individual execution counts for every basic block. Normally gcov
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 outputs execution counts only for the main blocks of a line. With this
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 option you can determine if blocks within a single line are not being
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 executed.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 @item -b
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 @itemx --branch-probabilities
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 Write branch frequencies to the output file, and write branch summary
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 info to the standard output. This option allows you to see how often
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 each branch in your program was taken. Unconditional branches will not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 be shown, unless the @option{-u} option is given.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 @item -c
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 @itemx --branch-counts
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 Write branch frequencies as the number of branches taken, rather than
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 the percentage of branches taken.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
111
kono
parents: 67
diff changeset
170 @item -d
kono
parents: 67
diff changeset
171 @itemx --display-progress
kono
parents: 67
diff changeset
172 Display the progress on the standard output.
kono
parents: 67
diff changeset
173
kono
parents: 67
diff changeset
174 @item -f
kono
parents: 67
diff changeset
175 @itemx --function-summaries
kono
parents: 67
diff changeset
176 Output summaries for each function in addition to the file level summary.
kono
parents: 67
diff changeset
177
kono
parents: 67
diff changeset
178 @item -h
kono
parents: 67
diff changeset
179 @itemx --help
kono
parents: 67
diff changeset
180 Display help about using @command{gcov} (on the standard output), and
kono
parents: 67
diff changeset
181 exit without doing any further processing.
kono
parents: 67
diff changeset
182
kono
parents: 67
diff changeset
183 @item -i
kono
parents: 67
diff changeset
184 @itemx --intermediate-format
kono
parents: 67
diff changeset
185 Output gcov file in an easy-to-parse intermediate text format that can
kono
parents: 67
diff changeset
186 be used by @command{lcov} or other tools. The output is a single
kono
parents: 67
diff changeset
187 @file{.gcov} file per @file{.gcda} file. No source code is required.
kono
parents: 67
diff changeset
188
kono
parents: 67
diff changeset
189 The format of the intermediate @file{.gcov} file is plain text with
kono
parents: 67
diff changeset
190 one entry per line
kono
parents: 67
diff changeset
191
kono
parents: 67
diff changeset
192 @smallexample
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
193 version:@var{gcc_version}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
194 cwd:@var{working_directory}
111
kono
parents: 67
diff changeset
195 file:@var{source_file_name}
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
196 function:@var{start_line_number},@var{end_line_number},@var{execution_count},@var{function_name}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
197 lcount:@var{line number},@var{execution_count},@var{has_unexecuted_block}
111
kono
parents: 67
diff changeset
198 branch:@var{line_number},@var{branch_coverage_type}
kono
parents: 67
diff changeset
199
kono
parents: 67
diff changeset
200 Where the @var{branch_coverage_type} is
kono
parents: 67
diff changeset
201 notexec (Branch not executed)
kono
parents: 67
diff changeset
202 taken (Branch executed and taken)
kono
parents: 67
diff changeset
203 nottaken (Branch executed, but not taken)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
204 @end smallexample
111
kono
parents: 67
diff changeset
205
kono
parents: 67
diff changeset
206 There can be multiple @var{file} entries in an intermediate gcov
kono
parents: 67
diff changeset
207 file. All entries following a @var{file} pertain to that source file
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
208 until the next @var{file} entry. If there are multiple functions that
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
209 start on a single line, then corresponding lcount is repeated multiple
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
210 times.
111
kono
parents: 67
diff changeset
211
kono
parents: 67
diff changeset
212 Here is a sample when @option{-i} is used in conjunction with @option{-b} option:
kono
parents: 67
diff changeset
213
kono
parents: 67
diff changeset
214 @smallexample
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
215 version: 8.1.0 20180103
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
216 cwd:/home/gcc/testcase
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
217 file:tmp.cpp
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
218 function:7,7,0,_ZN3FooIcEC2Ev
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
219 function:7,7,1,_ZN3FooIiEC2Ev
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
220 function:8,8,0,_ZN3FooIcE3incEv
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
221 function:8,8,2,_ZN3FooIiE3incEv
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
222 function:18,37,1,main
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
223 lcount:7,0,1
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
224 lcount:7,1,0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
225 lcount:8,0,1
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
226 lcount:8,2,0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
227 lcount:18,1,0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
228 lcount:21,1,0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
229 branch:21,taken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
230 branch:21,nottaken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
231 lcount:23,1,0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
232 branch:23,taken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
233 branch:23,nottaken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
234 lcount:24,1,0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
235 branch:24,taken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
236 branch:24,nottaken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
237 lcount:25,1,0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
238 lcount:27,11,0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
239 branch:27,taken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
240 branch:27,taken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
241 lcount:28,10,0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
242 lcount:30,1,1
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
243 branch:30,nottaken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
244 branch:30,taken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
245 lcount:32,1,0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
246 branch:32,nottaken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
247 branch:32,taken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
248 lcount:33,0,1
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
249 branch:33,notexec
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
250 branch:33,notexec
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
251 lcount:35,1,0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
252 branch:35,taken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
253 branch:35,nottaken
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
254 lcount:36,1,0
111
kono
parents: 67
diff changeset
255 @end smallexample
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
257 @item -j
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
258 @itemx --human-readable
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
259 Write counts in human readable format (like 24.6k).
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
260
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
261 @item -k
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
262 @itemx --use-colors
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
263
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
264 Use colors for lines of code that have zero coverage. We use red color for
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
265 non-exceptional lines and cyan for exceptional. Same colors are used for
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
266 basic blocks with @option{-a} option.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
267
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 @item -l
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 @itemx --long-file-names
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 Create long file names for included source files. For example, if the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 header file @file{x.h} contains code, and was included in the file
111
kono
parents: 67
diff changeset
272 @file{a.c}, then running @command{gcov} on the file @file{a.c} will
kono
parents: 67
diff changeset
273 produce an output file called @file{a.c##x.h.gcov} instead of
kono
parents: 67
diff changeset
274 @file{x.h.gcov}. This can be useful if @file{x.h} is included in
kono
parents: 67
diff changeset
275 multiple source files and you want to see the individual
kono
parents: 67
diff changeset
276 contributions. If you use the @samp{-p} option, both the including
kono
parents: 67
diff changeset
277 and included file names will be complete path names.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278
111
kono
parents: 67
diff changeset
279 @item -m
kono
parents: 67
diff changeset
280 @itemx --demangled-names
kono
parents: 67
diff changeset
281 Display demangled function names in output. The default is to show
kono
parents: 67
diff changeset
282 mangled function names.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283
111
kono
parents: 67
diff changeset
284 @item -n
kono
parents: 67
diff changeset
285 @itemx --no-output
kono
parents: 67
diff changeset
286 Do not create the @command{gcov} output file.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 @item -o @var{directory|file}
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 @itemx --object-directory @var{directory}
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 @itemx --object-file @var{file}
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 Specify either the directory containing the gcov data files, or the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 object path name. The @file{.gcno}, and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 @file{.gcda} data files are searched for using this option. If a directory
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 is specified, the data files are in that directory and named after the
111
kono
parents: 67
diff changeset
295 input file name, without its extension. If a file is specified here,
kono
parents: 67
diff changeset
296 the data files are named after that file, without its extension.
kono
parents: 67
diff changeset
297
kono
parents: 67
diff changeset
298 @item -p
kono
parents: 67
diff changeset
299 @itemx --preserve-paths
kono
parents: 67
diff changeset
300 Preserve complete path information in the names of generated
kono
parents: 67
diff changeset
301 @file{.gcov} files. Without this option, just the filename component is
kono
parents: 67
diff changeset
302 used. With this option, all directories are used, with @samp{/} characters
kono
parents: 67
diff changeset
303 translated to @samp{#} characters, @file{.} directory components
kono
parents: 67
diff changeset
304 removed and unremoveable @file{..}
kono
parents: 67
diff changeset
305 components renamed to @samp{^}. This is useful if sourcefiles are in several
kono
parents: 67
diff changeset
306 different directories.
kono
parents: 67
diff changeset
307
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
308 @item -q
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
309 @itemx --use-hotness-colors
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
310
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
311 Emit perf-like colored output for hot lines. Legend of the color scale
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
312 is printed at the very beginning of the output file.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
313
111
kono
parents: 67
diff changeset
314 @item -r
kono
parents: 67
diff changeset
315 @itemx --relative-only
kono
parents: 67
diff changeset
316 Only output information about source files with a relative pathname
kono
parents: 67
diff changeset
317 (after source prefix elision). Absolute paths are usually system
kono
parents: 67
diff changeset
318 header files and coverage of any inline functions therein is normally
kono
parents: 67
diff changeset
319 uninteresting.
kono
parents: 67
diff changeset
320
kono
parents: 67
diff changeset
321 @item -s @var{directory}
kono
parents: 67
diff changeset
322 @itemx --source-prefix @var{directory}
kono
parents: 67
diff changeset
323 A prefix for source file names to remove when generating the output
kono
parents: 67
diff changeset
324 coverage files. This option is useful when building in a separate
kono
parents: 67
diff changeset
325 directory, and the pathname to the source directory is not wanted when
kono
parents: 67
diff changeset
326 determining the output file names. Note that this prefix detection is
kono
parents: 67
diff changeset
327 applied before determining whether the source file is absolute.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
329 @item -t
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
330 @itemx --stdout
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
331 Output to standard output instead of output files.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
332
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 @item -u
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 @itemx --unconditional-branches
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 When branch probabilities are given, include those of unconditional branches.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 Unconditional branches are normally not interesting.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337
111
kono
parents: 67
diff changeset
338 @item -v
kono
parents: 67
diff changeset
339 @itemx --version
kono
parents: 67
diff changeset
340 Display the @command{gcov} version number (on the standard output),
kono
parents: 67
diff changeset
341 and exit without doing any further processing.
kono
parents: 67
diff changeset
342
kono
parents: 67
diff changeset
343 @item -w
kono
parents: 67
diff changeset
344 @itemx --verbose
kono
parents: 67
diff changeset
345 Print verbose informations related to basic blocks and arcs.
kono
parents: 67
diff changeset
346
kono
parents: 67
diff changeset
347 @item -x
kono
parents: 67
diff changeset
348 @itemx --hash-filenames
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
349 By default, gcov uses the full pathname of the source files to create
111
kono
parents: 67
diff changeset
350 an output filename. This can lead to long filenames that can overflow
kono
parents: 67
diff changeset
351 filesystem limits. This option creates names of the form
kono
parents: 67
diff changeset
352 @file{@var{source-file}##@var{md5}.gcov},
kono
parents: 67
diff changeset
353 where the @var{source-file} component is the final filename part and
kono
parents: 67
diff changeset
354 the @var{md5} component is calculated from the full mangled name that
kono
parents: 67
diff changeset
355 would have been used otherwise.
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
356
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 @end table
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 @command{gcov} should be run with the current directory the same as that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 when you invoked the compiler. Otherwise it will not be able to locate
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 the source files. @command{gcov} produces files called
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 @file{@var{mangledname}.gcov} in the current directory. These contain
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 the coverage information of the source file they correspond to.
111
kono
parents: 67
diff changeset
364 One @file{.gcov} file is produced for each source (or header) file
kono
parents: 67
diff changeset
365 containing code,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 which was compiled to produce the data files. The @var{mangledname} part
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 of the output file name is usually simply the source file name, but can
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 be something more complicated if the @samp{-l} or @samp{-p} options are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 given. Refer to those options for details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
370
111
kono
parents: 67
diff changeset
371 If you invoke @command{gcov} with multiple input files, the
kono
parents: 67
diff changeset
372 contributions from each input file are summed. Typically you would
kono
parents: 67
diff changeset
373 invoke it with the same list of files as the final link of your executable.
kono
parents: 67
diff changeset
374
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 The @file{.gcov} files contain the @samp{:} separated fields along with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 program source code. The format is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 @smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 @var{execution_count}:@var{line_number}:@var{source line text}
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 @end smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 Additional block information may succeed each line, when requested by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 command line option. The @var{execution_count} is @samp{-} for lines
111
kono
parents: 67
diff changeset
384 containing no code. Unexecuted lines are marked @samp{#####} or
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
385 @samp{=====}, depending on whether they are reachable by
111
kono
parents: 67
diff changeset
386 non-exceptional paths or only exceptional paths such as C++ exception
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
387 handlers, respectively. Given the @samp{-a} option, unexecuted blocks are
111
kono
parents: 67
diff changeset
388 marked @samp{$$$$$} or @samp{%%%%%}, depending on whether a basic block
kono
parents: 67
diff changeset
389 is reachable via non-exceptional or exceptional paths.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
390 Executed basic blocks having a statement with zero @var{execution_count}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
391 end with @samp{*} character and are colored with magenta color with
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
392 the @option{-k} option. This functionality is not supported in Ada.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
393
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
394 Note that GCC can completely remove the bodies of functions that are
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
395 not needed -- for instance if they are inlined everywhere. Such functions
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
396 are marked with @samp{-}, which can be confusing.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
397 Use the @option{-fkeep-inline-functions} and @option{-fkeep-static-functions}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
398 options to retain these functions and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
399 allow gcov to properly show their @var{execution_count}.
111
kono
parents: 67
diff changeset
400
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 Some lines of information at the start have @var{line_number} of zero.
111
kono
parents: 67
diff changeset
402 These preamble lines are of the form
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 @smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 -:0:@var{tag}:@var{value}
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 @end smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 The ordering and number of these preamble lines will be augmented as
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 @command{gcov} development progresses --- do not rely on them remaining
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 unchanged. Use @var{tag} to locate a particular preamble line.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 The additional block information is of the form
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 @smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 @var{tag} @var{information}
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 @end smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 The @var{information} is human readable, but designed to be simple
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 enough for machine parsing too.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 When printing percentages, 0% and 100% are only printed when the values
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 are @emph{exactly} 0% and 100% respectively. Other values which would
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 conventionally be rounded to 0% or 100% are instead printed as the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 nearest non-boundary value.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 When using @command{gcov}, you must first compile your program with two
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 special GCC options: @samp{-fprofile-arcs -ftest-coverage}.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 This tells the compiler to generate additional information needed by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 gcov (basically a flow graph of the program) and also includes
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 additional code in the object files for generating the extra profiling
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 information needed by gcov. These additional files are placed in the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 directory where the object file is located.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 Running the program will cause profile output to be generated. For each
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 source file compiled with @option{-fprofile-arcs}, an accompanying
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 @file{.gcda} file will be placed in the object file directory.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 Running @command{gcov} with your program's source file names as arguments
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 will now produce a listing of the code along with frequency of execution
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
440 for each line. For example, if your program is called @file{tmp.cpp}, this
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 is what you see when you use the basic @command{gcov} facility:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 @smallexample
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
444 $ g++ -fprofile-arcs -ftest-coverage tmp.cpp
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 $ a.out
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
446 $ gcov tmp.cpp -m
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
447 File 'tmp.cpp'
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
448 Lines executed:92.86% of 14
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
449 Creating 'tmp.cpp.gcov'
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 @end smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
452 The file @file{tmp.cpp.gcov} contains output from @command{gcov}.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 Here is a sample:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 @smallexample
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
456 -: 0:Source:tmp.cpp
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
457 -: 0:Working directory:/home/gcc/testcase
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 -: 0:Graph:tmp.gcno
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 -: 0:Data:tmp.gcda
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 -: 0:Runs:1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 -: 0:Programs:1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 -: 1:#include <stdio.h>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 -: 2:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
464 -: 3:template<class T>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
465 -: 4:class Foo
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
466 -: 5:@{
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
467 -: 6: public:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
468 1*: 7: Foo(): b (1000) @{@}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
469 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
470 Foo<char>::Foo():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
471 #####: 7: Foo(): b (1000) @{@}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
472 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
473 Foo<int>::Foo():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
474 1: 7: Foo(): b (1000) @{@}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
475 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
476 2*: 8: void inc () @{ b++; @}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
477 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
478 Foo<char>::inc():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
479 #####: 8: void inc () @{ b++; @}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
480 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
481 Foo<int>::inc():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
482 2: 8: void inc () @{ b++; @}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
483 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
484 -: 9:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
485 -: 10: private:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
486 -: 11: int b;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
487 -: 12:@};
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
488 -: 13:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
489 -: 14:template class Foo<int>;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
490 -: 15:template class Foo<char>;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
491 -: 16:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
492 -: 17:int
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
493 1: 18:main (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
494 -: 19:@{
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
495 -: 20: int i, total;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
496 1: 21: Foo<int> counter;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
497 -: 22:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
498 1: 23: counter.inc();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
499 1: 24: counter.inc();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
500 1: 25: total = 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
501 -: 26:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
502 11: 27: for (i = 0; i < 10; i++)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
503 10: 28: total += i;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
504 -: 29:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
505 1*: 30: int v = total > 100 ? 1 : 2;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
506 -: 31:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
507 1: 32: if (total != 45)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
508 #####: 33: printf ("Failure\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
509 -: 34: else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
510 1: 35: printf ("Success\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
511 1: 36: return 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
512 -: 37:@}
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 @end smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
515 Note that line 7 is shown in the report multiple times. First occurrence
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
516 presents total number of execution of the line and the next two belong
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
517 to instances of class Foo constructors. As you can also see, line 30 contains
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
518 some unexecuted basic blocks and thus execution count has asterisk symbol.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
519
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 When you use the @option{-a} option, you will get individual block
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 counts, and the output looks like this:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 @smallexample
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
524 -: 0:Source:tmp.cpp
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
525 -: 0:Working directory:/home/gcc/testcase
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 -: 0:Graph:tmp.gcno
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 -: 0:Data:tmp.gcda
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 -: 0:Runs:1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 -: 0:Programs:1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 -: 1:#include <stdio.h>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 -: 2:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
532 -: 3:template<class T>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
533 -: 4:class Foo
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
534 -: 5:@{
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
535 -: 6: public:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
536 1*: 7: Foo(): b (1000) @{@}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
537 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
538 Foo<char>::Foo():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
539 #####: 7: Foo(): b (1000) @{@}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
540 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
541 Foo<int>::Foo():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
542 1: 7: Foo(): b (1000) @{@}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
543 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
544 2*: 8: void inc () @{ b++; @}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
545 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
546 Foo<char>::inc():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
547 #####: 8: void inc () @{ b++; @}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
548 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
549 Foo<int>::inc():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
550 2: 8: void inc () @{ b++; @}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
551 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
552 -: 9:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
553 -: 10: private:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
554 -: 11: int b;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
555 -: 12:@};
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
556 -: 13:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
557 -: 14:template class Foo<int>;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
558 -: 15:template class Foo<char>;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
559 -: 16:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
560 -: 17:int
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
561 1: 18:main (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
562 -: 19:@{
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
563 -: 20: int i, total;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
564 1: 21: Foo<int> counter;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
565 1: 21-block 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
566 -: 22:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
567 1: 23: counter.inc();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
568 1: 23-block 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
569 1: 24: counter.inc();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
570 1: 24-block 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
571 1: 25: total = 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
572 -: 26:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
573 11: 27: for (i = 0; i < 10; i++)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
574 1: 27-block 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
575 11: 27-block 1
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
576 10: 28: total += i;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
577 10: 28-block 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
578 -: 29:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
579 1*: 30: int v = total > 100 ? 1 : 2;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
580 1: 30-block 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
581 %%%%%: 30-block 1
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
582 1: 30-block 2
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
583 -: 31:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
584 1: 32: if (total != 45)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
585 1: 32-block 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
586 #####: 33: printf ("Failure\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
587 %%%%%: 33-block 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
588 -: 34: else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
589 1: 35: printf ("Success\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
590 1: 35-block 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
591 1: 36: return 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
592 1: 36-block 0
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
593 -: 37:@}
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 @end smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 In this mode, each basic block is only shown on one line -- the last
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 line of the block. A multi-line block will only contribute to the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 execution count of that last line, and other lines will not be shown
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 to contain code, unless previous blocks end on those lines.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 The total execution count of a line is shown and subsequent lines show
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 the execution counts for individual blocks that end on that line. After each
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 block, the branch and call counts of the block will be shown, if the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 @option{-b} option is given.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 Because of the way GCC instruments calls, a call count can be shown
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 after a line with no individual blocks.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
607 As you can see, line 33 contains a basic block that was not executed.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 @need 450
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 When you use the @option{-b} option, your output looks like this:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 @smallexample
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
613 -: 0:Source:tmp.cpp
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
614 -: 0:Working directory:/home/gcc/testcase
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 -: 0:Graph:tmp.gcno
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 -: 0:Data:tmp.gcda
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 -: 0:Runs:1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
618 -: 0:Programs:1
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 -: 1:#include <stdio.h>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 -: 2:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
621 -: 3:template<class T>
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
622 -: 4:class Foo
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
623 -: 5:@{
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
624 -: 6: public:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
625 1*: 7: Foo(): b (1000) @{@}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
626 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
627 Foo<char>::Foo():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
628 function Foo<char>::Foo() called 0 returned 0% blocks executed 0%
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
629 #####: 7: Foo(): b (1000) @{@}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
630 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
631 Foo<int>::Foo():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
632 function Foo<int>::Foo() called 1 returned 100% blocks executed 100%
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
633 1: 7: Foo(): b (1000) @{@}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
634 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
635 2*: 8: void inc () @{ b++; @}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
636 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
637 Foo<char>::inc():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
638 function Foo<char>::inc() called 0 returned 0% blocks executed 0%
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
639 #####: 8: void inc () @{ b++; @}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
640 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
641 Foo<int>::inc():
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
642 function Foo<int>::inc() called 2 returned 100% blocks executed 100%
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
643 2: 8: void inc () @{ b++; @}
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
644 ------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
645 -: 9:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
646 -: 10: private:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
647 -: 11: int b;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
648 -: 12:@};
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
649 -: 13:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
650 -: 14:template class Foo<int>;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
651 -: 15:template class Foo<char>;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
652 -: 16:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
653 -: 17:int
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
654 function main called 1 returned 100% blocks executed 81%
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
655 1: 18:main (void)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
656 -: 19:@{
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
657 -: 20: int i, total;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
658 1: 21: Foo<int> counter;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
659 call 0 returned 100%
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
660 branch 1 taken 100% (fallthrough)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
661 branch 2 taken 0% (throw)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
662 -: 22:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
663 1: 23: counter.inc();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
664 call 0 returned 100%
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
665 branch 1 taken 100% (fallthrough)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
666 branch 2 taken 0% (throw)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
667 1: 24: counter.inc();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
668 call 0 returned 100%
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
669 branch 1 taken 100% (fallthrough)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
670 branch 2 taken 0% (throw)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
671 1: 25: total = 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
672 -: 26:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
673 11: 27: for (i = 0; i < 10; i++)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 branch 0 taken 91% (fallthrough)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 branch 1 taken 9%
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
676 10: 28: total += i;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
677 -: 29:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
678 1*: 30: int v = total > 100 ? 1 : 2;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
679 branch 0 taken 0% (fallthrough)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
680 branch 1 taken 100%
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
681 -: 31:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
682 1: 32: if (total != 45)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 branch 0 taken 0% (fallthrough)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 branch 1 taken 100%
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
685 #####: 33: printf ("Failure\n");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 call 0 never executed
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
687 branch 1 never executed
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
688 branch 2 never executed
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
689 -: 34: else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
690 1: 35: printf ("Success\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
691 call 0 returned 100%
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
692 branch 1 taken 100% (fallthrough)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
693 branch 2 taken 0% (throw)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
694 1: 36: return 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
695 -: 37:@}
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 @end smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 For each function, a line is printed showing how many times the function
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 is called, how many times it returns and what percentage of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 function's blocks were executed.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 For each basic block, a line is printed after the last line of the basic
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 block describing the branch or call that ends the basic block. There can
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 be multiple branches and calls listed for a single source line if there
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 are multiple basic blocks that end on that line. In this case, the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 branches and calls are each given a number. There is no simple way to map
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 these branches and calls back to source constructs. In general, though,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708 the lowest numbered branch or call will correspond to the leftmost construct
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 on the source line.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 For a branch, if it was executed at least once, then a percentage
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
712 indicating the number of times the branch was taken divided by the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
713 number of times the branch was executed will be printed. Otherwise, the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 message ``never executed'' is printed.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
715
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 For a call, if it was executed at least once, then a percentage
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
717 indicating the number of times the call returned divided by the number
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
718 of times the call was executed will be printed. This will usually be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 100%, but may be less for functions that call @code{exit} or @code{longjmp},
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 and thus may not return every time they are called.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
721
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 The execution counts are cumulative. If the example program were
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 executed again without removing the @file{.gcda} file, the count for the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 number of times each line in the source was executed would be added to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 the results of the previous run(s). This is potentially useful in
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 several ways. For example, it could be used to accumulate data over a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 number of program runs as part of a test verification suite, or to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 provide more accurate long-term information over a large number of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 program runs.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 The data in the @file{.gcda} files is saved immediately before the program
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 exits. For each source file compiled with @option{-fprofile-arcs}, the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 profiling code first attempts to read in an existing @file{.gcda} file; if
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 the file doesn't match the executable (differing number of basic block
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 counts) it will ignore the contents of the file. It then adds in the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 new execution counts and finally writes the data to the file.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 @node Gcov and Optimization
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 @section Using @command{gcov} with GCC Optimization
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 If you plan to use @command{gcov} to help optimize your code, you must
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 first compile your program with two special GCC options:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743 @samp{-fprofile-arcs -ftest-coverage}. Aside from that, you can use any
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 other GCC options; but if you want to prove that every single line
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 in your program was executed, you should not compile with optimization
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
746 at the same time. On some machines the optimizer can eliminate some
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 simple code lines by combining them with other lines. For example, code
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 like this:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 @smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 if (a != b)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
752 c = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 c = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 @end smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 @noindent
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 can be compiled into one instruction on some machines. In this case,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 there is no way for @command{gcov} to calculate separate execution counts
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 for each line because there isn't separate code for each line. Hence
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 the @command{gcov} output looks like this if you compiled the program with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 optimization:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 @smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 100: 12:if (a != b)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 100: 13: c = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 100: 14:else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 100: 15: c = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
769 @end smallexample
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 The output shows that this block of code, combined by optimization,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 executed 100 times. In one sense this result is correct, because there
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 was only one instruction representing all four of these lines. However,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
774 the output does not indicate how many times the result was 0 and how
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 many times the result was 1.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
777 Inlineable functions can create unexpected line counts. Line counts are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 shown for the source code of the inlineable function, but what is shown
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 depends on where the function is inlined, or if it is not inlined at all.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 If the function is not inlined, the compiler must emit an out of line
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 copy of the function, in any object file that needs it. If
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 @file{fileA.o} and @file{fileB.o} both contain out of line bodies of a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 particular inlineable function, they will also both contain coverage
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 counts for that function. When @file{fileA.o} and @file{fileB.o} are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 linked together, the linker will, on many systems, select one of those
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 out of line bodies for all calls to that function, and remove or ignore
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
788 the other. Unfortunately, it will not remove the coverage counters for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 the unused function body. Hence when instrumented, all but one use of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 that function will show zero counts.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 If the function is inlined in several places, the block structure in
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 each location might not be the same. For instance, a condition might
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 now be calculable at compile time in some instances. Because the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 coverage of all the uses of the inline function will be shown for the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 same source lines, the line counts themselves might seem inconsistent.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
797
111
kono
parents: 67
diff changeset
798 Long-running applications can use the @code{__gcov_reset} and @code{__gcov_dump}
kono
parents: 67
diff changeset
799 facilities to restrict profile collection to the program region of
kono
parents: 67
diff changeset
800 interest. Calling @code{__gcov_reset(void)} will clear all profile counters
kono
parents: 67
diff changeset
801 to zero, and calling @code{__gcov_dump(void)} will cause the profile information
kono
parents: 67
diff changeset
802 collected at that point to be dumped to @file{.gcda} output files.
kono
parents: 67
diff changeset
803 Instrumented applications use a static destructor with priority 99
kono
parents: 67
diff changeset
804 to invoke the @code{__gcov_dump} function. Thus @code{__gcov_dump}
kono
parents: 67
diff changeset
805 is executed after all user defined static destructors,
kono
parents: 67
diff changeset
806 as well as handlers registered with @code{atexit}.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
807 If an executable loads a dynamic shared object via dlopen functionality,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
808 @option{-Wl,--dynamic-list-data} is needed to dump all profile data.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
809
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
810 Profiling run-time library reports various errors related to profile
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
811 manipulation and profile saving. Errors are printed into standard error output
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
812 or @samp{GCOV_ERROR_FILE} file, if environment variable is used.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
813 In order to terminate immediately after an errors occurs
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
814 set @samp{GCOV_EXIT_AT_ERROR} environment variable.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
815 That can help users to find profile clashing which leads
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
816 to a misleading profile.
111
kono
parents: 67
diff changeset
817
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 @c man end
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
819
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 @node Gcov Data Files
111
kono
parents: 67
diff changeset
821 @section Brief Description of @command{gcov} Data Files
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 @command{gcov} uses two files for profiling. The names of these files
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
824 are derived from the original @emph{object} file by substituting the
111
kono
parents: 67
diff changeset
825 file suffix with either @file{.gcno}, or @file{.gcda}. The files
kono
parents: 67
diff changeset
826 contain coverage and profile data stored in a platform-independent format.
kono
parents: 67
diff changeset
827 The @file{.gcno} files are placed in the same directory as the object
kono
parents: 67
diff changeset
828 file. By default, the @file{.gcda} files are also stored in the same
kono
parents: 67
diff changeset
829 directory as the object file, but the GCC @option{-fprofile-dir} option
kono
parents: 67
diff changeset
830 may be used to store the @file{.gcda} files in a separate directory.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831
111
kono
parents: 67
diff changeset
832 The @file{.gcno} notes file is generated when the source file is compiled
kono
parents: 67
diff changeset
833 with the GCC @option{-ftest-coverage} option. It contains information to
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
834 reconstruct the basic block graphs and assign source line numbers to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 blocks.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836
111
kono
parents: 67
diff changeset
837 The @file{.gcda} count data file is generated when a program containing
kono
parents: 67
diff changeset
838 object files built with the GCC @option{-fprofile-arcs} option is executed.
kono
parents: 67
diff changeset
839 A separate @file{.gcda} file is created for each object file compiled with
kono
parents: 67
diff changeset
840 this option. It contains arc transition counts, value profile counts, and
kono
parents: 67
diff changeset
841 some summary information.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
842
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
843 It is not recommended to access the coverage files directly.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
844 Consumers should use the intermediate format that is provided
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
845 by @command{gcov} tool via @option{--intermediate-format} option.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
846
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 @node Cross-profiling
111
kono
parents: 67
diff changeset
848 @section Data File Relocation to Support Cross-Profiling
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849
111
kono
parents: 67
diff changeset
850 Running the program will cause profile output to be generated. For each
kono
parents: 67
diff changeset
851 source file compiled with @option{-fprofile-arcs}, an accompanying @file{.gcda}
kono
parents: 67
diff changeset
852 file will be placed in the object file directory. That implicitly requires
kono
parents: 67
diff changeset
853 running the program on the same system as it was built or having the same
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
854 absolute directory structure on the target system. The program will try
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855 to create the needed directory structure, if it is not already present.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
857 To support cross-profiling, a program compiled with @option{-fprofile-arcs}
111
kono
parents: 67
diff changeset
858 can relocate the data files based on two environment variables:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
859
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
860 @itemize @bullet
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861 @item
111
kono
parents: 67
diff changeset
862 GCOV_PREFIX contains the prefix to add to the absolute paths
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
863 in the object file. Prefix can be absolute, or relative. The
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
864 default is no prefix.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
866 @item
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
867 GCOV_PREFIX_STRIP indicates the how many initial directory names to strip off
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
868 the hardwired absolute paths. Default value is 0.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
869
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
870 @emph{Note:} If GCOV_PREFIX_STRIP is set without GCOV_PREFIX is undefined,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
871 then a relative path is made out of the hardwired absolute paths.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
872 @end itemize
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
873
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
874 For example, if the object file @file{/user/build/foo.o} was built with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
875 @option{-fprofile-arcs}, the final executable will try to create the data file
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
876 @file{/user/build/foo.gcda} when running on the target system. This will
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877 fail if the corresponding directory does not exist and it is unable to create
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 it. This can be overcome by, for example, setting the environment as
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
879 @samp{GCOV_PREFIX=/target/run} and @samp{GCOV_PREFIX_STRIP=1}. Such a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
880 setting will name the data file @file{/target/run/build/foo.gcda}.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
881
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
882 You must move the data files to the expected directory tree in order to
111
kono
parents: 67
diff changeset
883 use them for profile directed optimizations (@option{-fprofile-use}), or to
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884 use the @command{gcov} tool.