⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gcov-and-optimization.html

📁 自己收集的linux入门到学懂高级编程书集 包括linux程序设计第三版
💻 HTML
字号:
<html lang="en"><head><title>Using the GNU Compiler Collection (GCC)</title><meta http-equiv="Content-Type" content="text/html"><meta name="description" content="Using the GNU Compiler Collection (GCC)"><meta name="generator" content="makeinfo 4.6"><!--Copyright &copy; 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.   <p>Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2 orany later version published by the Free Software Foundation; with theInvariant Sections being "GNU General Public License" and "FundingFree Software", the Front-Cover texts being (a) (see below), and withthe Back-Cover Texts being (b) (see below).  A copy of the license isincluded in the section entitled "GNU Free Documentation License".   <p>(a) The FSF's Front-Cover Text is:   <p>A GNU Manual   <p>(b) The FSF's Back-Cover Text is:   <p>You have freedom to copy and modify this GNU Manual, like GNU     software.  Copies published by the Free Software Foundation raise     funds for GNU development.--><meta http-equiv="Content-Style-Type" content="text/css"><style type="text/css"><!--  pre.display { font-family:inherit }  pre.format  { font-family:inherit }  pre.smalldisplay { font-family:inherit; font-size:smaller }  pre.smallformat  { font-family:inherit; font-size:smaller }  pre.smallexample { font-size:smaller }  pre.smalllisp    { font-size:smaller }--></style></head><body><div class="node"><p>Node:&nbsp;<a name="Gcov%20and%20Optimization">Gcov and Optimization</a>,Next:&nbsp;<a rel="next" accesskey="n" href="Gcov-Data-Files.html#Gcov%20Data%20Files">Gcov Data Files</a>,Previous:&nbsp;<a rel="previous" accesskey="p" href="Invoking-Gcov.html#Invoking%20Gcov">Invoking Gcov</a>,Up:&nbsp;<a rel="up" accesskey="u" href="Gcov.html#Gcov">Gcov</a><hr><br></div><h3 class="section">Using <code>gcov</code> with GCC Optimization</h3><p>If you plan to use <code>gcov</code> to help optimize your code, you mustfirst compile your program with two special GCC options:<code>-fprofile-arcs -ftest-coverage</code>.  Aside from that, you can use anyother GCC options; but if you want to prove that every single linein your program was executed, you should not compile with optimizationat the same time.  On some machines the optimizer can eliminate somesimple code lines by combining them with other lines.  For example, codelike this:<pre class="smallexample">     if (a != b)       c = 1;     else       c = 0;     </pre><p>can be compiled into one instruction on some machines.  In this case,there is no way for <code>gcov</code> to calculate separate execution countsfor each line because there isn't separate code for each line.  Hencethe <code>gcov</code> output looks like this if you compiled the program withoptimization:<pre class="smallexample">           100:   12:if (a != b)           100:   13:  c = 1;           100:   14:else           100:   15:  c = 0;     </pre>   <p>The output shows that this block of code, combined by optimization,executed 100 times.  In one sense this result is correct, because therewas only one instruction representing all four of these lines.  However,the output does not indicate how many times the result was 0 and howmany times the result was 1.   <p>Inlineable functions can create unexpected line counts.  Line counts areshown for the source code of the inlineable function, but what is showndepends on where the function is inlined, or if it is not inlined at all.   <p>If the function is not inlined, the compiler must emit an out of linecopy of the function, in any object file that needs it.  If<code>fileA.o</code> and <code>fileB.o</code> both contain out of line bodies of aparticular inlineable function, they will also both contain coveragecounts for that function.  When <code>fileA.o</code> and <code>fileB.o</code> arelinked together, the linker will, on many systems, select one of thoseout of line bodies for all calls to that function, and remove or ignorethe other.  Unfortunately, it will not remove the coverage counters forthe unused function body.  Hence when instrumented, all but one use ofthat function will show zero counts.   <p>If the function is inlined in several places, the block structure ineach location might not be the same.  For instance, a condition mightnow be calculable at compile time in some instances.  Because thecoverage of all the uses of the inline function will be shown for thesame source lines, the line counts themselves might seem inconsistent.   </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -