comparison gcc/doc/gcov.texi @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 @c Copyright (C) 1996-2018 Free Software Foundation, Inc. 1 @c Copyright (C) 1996-2020 Free Software Foundation, Inc.
2 @c This is part of the GCC manual. 2 @c This is part of the GCC manual.
3 @c For copying conditions, see the file gcc.texi. 3 @c For copying conditions, see the file gcc.texi.
4 4
5 @ignore 5 @ignore
6 @c man begin COPYRIGHT 6 @c man begin COPYRIGHT
7 Copyright @copyright{} 1996-2018 Free Software Foundation, Inc. 7 Copyright @copyright{} 1996-2020 Free Software Foundation, Inc.
8 8
9 Permission is granted to copy, distribute and/or modify this document 9 Permission is granted to copy, distribute and/or modify this document
10 under the terms of the GNU Free Documentation License, Version 1.3 or 10 under the terms of the GNU Free Documentation License, Version 1.3 or
11 any later version published by the Free Software Foundation; with the 11 any later version published by the Free Software Foundation; with the
12 Invariant Sections being ``GNU General Public License'' and ``Funding 12 Invariant Sections being ``GNU General Public License'' and ``Funding
122 [@option{-a}|@option{--all-blocks}] 122 [@option{-a}|@option{--all-blocks}]
123 [@option{-b}|@option{--branch-probabilities}] 123 [@option{-b}|@option{--branch-probabilities}]
124 [@option{-c}|@option{--branch-counts}] 124 [@option{-c}|@option{--branch-counts}]
125 [@option{-d}|@option{--display-progress}] 125 [@option{-d}|@option{--display-progress}]
126 [@option{-f}|@option{--function-summaries}] 126 [@option{-f}|@option{--function-summaries}]
127 [@option{-i}|@option{--intermediate-format}] 127 [@option{-i}|@option{--json-format}]
128 [@option{-j}|@option{--human-readable}] 128 [@option{-j}|@option{--human-readable}]
129 [@option{-k}|@option{--use-colors}] 129 [@option{-k}|@option{--use-colors}]
130 [@option{-l}|@option{--long-file-names}] 130 [@option{-l}|@option{--long-file-names}]
131 [@option{-m}|@option{--demangled-names}] 131 [@option{-m}|@option{--demangled-names}]
132 [@option{-n}|@option{--no-output}] 132 [@option{-n}|@option{--no-output}]
179 @itemx --help 179 @itemx --help
180 Display help about using @command{gcov} (on the standard output), and 180 Display help about using @command{gcov} (on the standard output), and
181 exit without doing any further processing. 181 exit without doing any further processing.
182 182
183 @item -i 183 @item -i
184 @itemx --intermediate-format 184 @itemx --json-format
185 Output gcov file in an easy-to-parse intermediate text format that can 185 Output gcov file in an easy-to-parse JSON intermediate format
186 be used by @command{lcov} or other tools. The output is a single 186 which does not require source code for generation. The JSON
187 @file{.gcov} file per @file{.gcda} file. No source code is required. 187 file is compressed with gzip compression algorithm
188 188 and the files have @file{.gcov.json.gz} extension.
189 The format of the intermediate @file{.gcov} file is plain text with 189
190 one entry per line 190 Structure of the JSON is following:
191 191
192 @smallexample 192 @smallexample
193 version:@var{gcc_version} 193 @{
194 cwd:@var{working_directory} 194 "current_working_directory": @var{current_working_directory},
195 file:@var{source_file_name} 195 "data_file": @var{data_file},
196 function:@var{start_line_number},@var{end_line_number},@var{execution_count},@var{function_name} 196 "format_version": @var{format_version},
197 lcount:@var{line number},@var{execution_count},@var{has_unexecuted_block} 197 "gcc_version": @var{gcc_version}
198 branch:@var{line_number},@var{branch_coverage_type} 198 "files": [@var{file}]
199 199 @}
200 Where the @var{branch_coverage_type} is 200 @end smallexample
201 notexec (Branch not executed) 201
202 taken (Branch executed and taken) 202 Fields of the root element have following semantics:
203 nottaken (Branch executed, but not taken) 203
204 @end smallexample 204 @itemize @bullet
205 205 @item
206 There can be multiple @var{file} entries in an intermediate gcov 206 @var{current_working_directory}: working directory where
207 file. All entries following a @var{file} pertain to that source file 207 a compilation unit was compiled
208 until the next @var{file} entry. If there are multiple functions that 208
209 start on a single line, then corresponding lcount is repeated multiple 209 @item
210 times. 210 @var{data_file}: name of the data file (GCDA)
211 211
212 Here is a sample when @option{-i} is used in conjunction with @option{-b} option: 212 @item
213 213 @var{format_version}: semantic version of the format
214 @smallexample 214
215 version: 8.1.0 20180103 215 @item
216 cwd:/home/gcc/testcase 216 @var{gcc_version}: version of the GCC compiler
217 file:tmp.cpp 217 @end itemize
218 function:7,7,0,_ZN3FooIcEC2Ev 218
219 function:7,7,1,_ZN3FooIiEC2Ev 219 Each @var{file} has the following form:
220 function:8,8,0,_ZN3FooIcE3incEv 220
221 function:8,8,2,_ZN3FooIiE3incEv 221 @smallexample
222 function:18,37,1,main 222 @{
223 lcount:7,0,1 223 "file": @var{file_name},
224 lcount:7,1,0 224 "functions": [@var{function}],
225 lcount:8,0,1 225 "lines": [@var{line}]
226 lcount:8,2,0 226 @}
227 lcount:18,1,0 227 @end smallexample
228 lcount:21,1,0 228
229 branch:21,taken 229 Fields of the @var{file} element have following semantics:
230 branch:21,nottaken 230
231 lcount:23,1,0 231 @itemize @bullet
232 branch:23,taken 232 @item
233 branch:23,nottaken 233 @var{file_name}: name of the source file
234 lcount:24,1,0 234 @end itemize
235 branch:24,taken 235
236 branch:24,nottaken 236 Each @var{function} has the following form:
237 lcount:25,1,0 237
238 lcount:27,11,0 238 @smallexample
239 branch:27,taken 239 @{
240 branch:27,taken 240 "blocks": @var{blocks},
241 lcount:28,10,0 241 "blocks_executed": @var{blocks_executed},
242 lcount:30,1,1 242 "demangled_name": "@var{demangled_name},
243 branch:30,nottaken 243 "end_column": @var{end_column},
244 branch:30,taken 244 "end_line": @var{end_line},
245 lcount:32,1,0 245 "execution_count": @var{execution_count},
246 branch:32,nottaken 246 "name": @var{name},
247 branch:32,taken 247 "start_column": @var{start_column}
248 lcount:33,0,1 248 "start_line": @var{start_line}
249 branch:33,notexec 249 @}
250 branch:33,notexec 250 @end smallexample
251 lcount:35,1,0 251
252 branch:35,taken 252 Fields of the @var{function} element have following semantics:
253 branch:35,nottaken 253
254 lcount:36,1,0 254 @itemize @bullet
255 @end smallexample 255 @item
256 @var{blocks}: number of blocks that are in the function
257
258 @item
259 @var{blocks_executed}: number of executed blocks of the function
260
261 @item
262 @var{demangled_name}: demangled name of the function
263
264 @item
265 @var{end_column}: column in the source file where the function ends
266
267 @item
268 @var{end_line}: line in the source file where the function ends
269
270 @item
271 @var{execution_count}: number of executions of the function
272
273 @item
274 @var{name}: name of the function
275
276 @item
277 @var{start_column}: column in the source file where the function begins
278
279 @item
280 @var{start_line}: line in the source file where the function begins
281 @end itemize
282
283 Note that line numbers and column numbers number from 1. In the current
284 implementation, @var{start_line} and @var{start_column} do not include
285 any template parameters and the leading return type but that
286 this is likely to be fixed in the future.
287
288 Each @var{line} has the following form:
289
290 @smallexample
291 @{
292 "branches": [@var{branch}],
293 "count": @var{count},
294 "line_number": @var{line_number},
295 "unexecuted_block": @var{unexecuted_block}
296 "function_name": @var{function_name},
297 @}
298 @end smallexample
299
300 Branches are present only with @var{-b} option.
301 Fields of the @var{line} element have following semantics:
302
303 @itemize @bullet
304 @item
305 @var{count}: number of executions of the line
306
307 @item
308 @var{line_number}: line number
309
310 @item
311 @var{unexecuted_block}: flag whether the line contains an unexecuted block
312 (not all statements on the line are executed)
313
314 @item
315 @var{function_name}: a name of a function this @var{line} belongs to
316 (for a line with an inlined statements can be not set)
317 @end itemize
318
319 Each @var{branch} has the following form:
320
321 @smallexample
322 @{
323 "count": @var{count},
324 "fallthrough": @var{fallthrough},
325 "throw": @var{throw}
326 @}
327 @end smallexample
328
329 Fields of the @var{branch} element have following semantics:
330
331 @itemize @bullet
332 @item
333 @var{count}: number of executions of the branch
334
335 @item
336 @var{fallthrough}: true when the branch is a fall through branch
337
338 @item
339 @var{throw}: true when the branch is an exceptional branch
340 @end itemize
256 341
257 @item -j 342 @item -j
258 @itemx --human-readable 343 @itemx --human-readable
259 Write counts in human readable format (like 24.6k). 344 Write counts in human readable format (like 24.6k).
260 345
344 @itemx --verbose 429 @itemx --verbose
345 Print verbose informations related to basic blocks and arcs. 430 Print verbose informations related to basic blocks and arcs.
346 431
347 @item -x 432 @item -x
348 @itemx --hash-filenames 433 @itemx --hash-filenames
349 By default, gcov uses the full pathname of the source files to create 434 When using @var{--preserve-paths},
435 gcov uses the full pathname of the source files to create
350 an output filename. This can lead to long filenames that can overflow 436 an output filename. This can lead to long filenames that can overflow
351 filesystem limits. This option creates names of the form 437 filesystem limits. This option creates names of the form
352 @file{@var{source-file}##@var{md5}.gcov}, 438 @file{@var{source-file}##@var{md5}.gcov},
353 where the @var{source-file} component is the final filename part and 439 where the @var{source-file} component is the final filename part and
354 the @var{md5} component is calculated from the full mangled name that 440 the @var{md5} component is calculated from the full mangled name that
355 would have been used otherwise. 441 would have been used otherwise. The option is an alternative
442 to the @var{--preserve-paths} on systems which have a filesystem limit.
356 443
357 @end table 444 @end table
358 445
359 @command{gcov} should be run with the current directory the same as that 446 @command{gcov} should be run with the current directory the same as that
360 when you invoked the compiler. Otherwise it will not be able to locate 447 when you invoked the compiler. Otherwise it will not be able to locate
421 When printing percentages, 0% and 100% are only printed when the values 508 When printing percentages, 0% and 100% are only printed when the values
422 are @emph{exactly} 0% and 100% respectively. Other values which would 509 are @emph{exactly} 0% and 100% respectively. Other values which would
423 conventionally be rounded to 0% or 100% are instead printed as the 510 conventionally be rounded to 0% or 100% are instead printed as the
424 nearest non-boundary value. 511 nearest non-boundary value.
425 512
426 When using @command{gcov}, you must first compile your program with two 513 When using @command{gcov}, you must first compile your program
427 special GCC options: @samp{-fprofile-arcs -ftest-coverage}. 514 with a special GCC option @samp{--coverage}.
428 This tells the compiler to generate additional information needed by 515 This tells the compiler to generate additional information needed by
429 gcov (basically a flow graph of the program) and also includes 516 gcov (basically a flow graph of the program) and also includes
430 additional code in the object files for generating the extra profiling 517 additional code in the object files for generating the extra profiling
431 information needed by gcov. These additional files are placed in the 518 information needed by gcov. These additional files are placed in the
432 directory where the object file is located. 519 directory where the object file is located.
439 will now produce a listing of the code along with frequency of execution 526 will now produce a listing of the code along with frequency of execution
440 for each line. For example, if your program is called @file{tmp.cpp}, this 527 for each line. For example, if your program is called @file{tmp.cpp}, this
441 is what you see when you use the basic @command{gcov} facility: 528 is what you see when you use the basic @command{gcov} facility:
442 529
443 @smallexample 530 @smallexample
444 $ g++ -fprofile-arcs -ftest-coverage tmp.cpp 531 $ g++ --coverage tmp.cpp
445 $ a.out 532 $ a.out
446 $ gcov tmp.cpp -m 533 $ gcov tmp.cpp -m
447 File 'tmp.cpp' 534 File 'tmp.cpp'
448 Lines executed:92.86% of 14 535 Lines executed:92.86% of 14
449 Creating 'tmp.cpp.gcov' 536 Creating 'tmp.cpp.gcov'
737 824
738 @node Gcov and Optimization 825 @node Gcov and Optimization
739 @section Using @command{gcov} with GCC Optimization 826 @section Using @command{gcov} with GCC Optimization
740 827
741 If you plan to use @command{gcov} to help optimize your code, you must 828 If you plan to use @command{gcov} to help optimize your code, you must
742 first compile your program with two special GCC options: 829 first compile your program with a special GCC option
743 @samp{-fprofile-arcs -ftest-coverage}. Aside from that, you can use any 830 @samp{--coverage}. Aside from that, you can use any
744 other GCC options; but if you want to prove that every single line 831 other GCC options; but if you want to prove that every single line
745 in your program was executed, you should not compile with optimization 832 in your program was executed, you should not compile with optimization
746 at the same time. On some machines the optimizer can eliminate some 833 at the same time. On some machines the optimizer can eliminate some
747 simple code lines by combining them with other lines. For example, code 834 simple code lines by combining them with other lines. For example, code
748 like this: 835 like this:
840 this option. It contains arc transition counts, value profile counts, and 927 this option. It contains arc transition counts, value profile counts, and
841 some summary information. 928 some summary information.
842 929
843 It is not recommended to access the coverage files directly. 930 It is not recommended to access the coverage files directly.
844 Consumers should use the intermediate format that is provided 931 Consumers should use the intermediate format that is provided
845 by @command{gcov} tool via @option{--intermediate-format} option. 932 by @command{gcov} tool via @option{--json-format} option.
846 933
847 @node Cross-profiling 934 @node Cross-profiling
848 @section Data File Relocation to Support Cross-Profiling 935 @section Data File Relocation to Support Cross-Profiling
849 936
850 Running the program will cause profile output to be generated. For each 937 Running the program will cause profile output to be generated. For each