How-do-I_003f.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the gprof profiler of the GNU system.
  4. Copyright (C) 1988-2017 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3
  7. or any later version published by the Free Software Foundation;
  8. with no Invariant Sections, with no Front-Cover Texts, and with no
  9. Back-Cover Texts. A copy of the license is included in the
  10. section entitled "GNU Free Documentation License".
  11. -->
  12. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <title>GNU gprof: How do I?</title>
  15. <meta name="description" content="GNU gprof: How do I?">
  16. <meta name="keywords" content="GNU gprof: How do I?">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  23. <link href="index.html#Top" rel="up" title="Top">
  24. <link href="Incompatibilities.html#Incompatibilities" rel="next" title="Incompatibilities">
  25. <link href="Assumptions.html#Assumptions" rel="prev" title="Assumptions">
  26. <style type="text/css">
  27. <!--
  28. a.summary-letter {text-decoration: none}
  29. blockquote.smallquotation {font-size: smaller}
  30. div.display {margin-left: 3.2em}
  31. div.example {margin-left: 3.2em}
  32. div.indentedblock {margin-left: 3.2em}
  33. div.lisp {margin-left: 3.2em}
  34. div.smalldisplay {margin-left: 3.2em}
  35. div.smallexample {margin-left: 3.2em}
  36. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  37. div.smalllisp {margin-left: 3.2em}
  38. kbd {font-style:oblique}
  39. pre.display {font-family: inherit}
  40. pre.format {font-family: inherit}
  41. pre.menu-comment {font-family: serif}
  42. pre.menu-preformatted {font-family: serif}
  43. pre.smalldisplay {font-family: inherit; font-size: smaller}
  44. pre.smallexample {font-size: smaller}
  45. pre.smallformat {font-family: inherit; font-size: smaller}
  46. pre.smalllisp {font-size: smaller}
  47. span.nocodebreak {white-space:nowrap}
  48. span.nolinebreak {white-space:nowrap}
  49. span.roman {font-family:serif; font-weight:normal}
  50. span.sansserif {font-family:sans-serif; font-weight:normal}
  51. ul.no-bullet {list-style: none}
  52. -->
  53. </style>
  54. </head>
  55. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  56. <a name="How-do-I_003f"></a>
  57. <div class="header">
  58. <p>
  59. Next: <a href="Incompatibilities.html#Incompatibilities" accesskey="n" rel="next">Incompatibilities</a>, Previous: <a href="Inaccuracy.html#Inaccuracy" accesskey="p" rel="prev">Inaccuracy</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  60. </div>
  61. <hr>
  62. <a name="Answers-to-Common-Questions"></a>
  63. <h2 class="chapter">7 Answers to Common Questions</h2>
  64. <dl compact="compact">
  65. <dt>How can I get more exact information about hot spots in my program?</dt>
  66. <dd>
  67. <p>Looking at the per-line call counts only tells part of the story.
  68. Because <code>gprof</code> can only report call times and counts by function,
  69. the best way to get finer-grained information on where the program
  70. is spending its time is to re-factor large functions into sequences
  71. of calls to smaller ones. Beware however that this can introduce
  72. artificial hot spots since compiling with &lsquo;<samp>-pg</samp>&rsquo; adds a significant
  73. overhead to function calls. An alternative solution is to use a
  74. non-intrusive profiler, e.g. oprofile.
  75. </p>
  76. </dd>
  77. <dt>How do I find which lines in my program were executed the most times?</dt>
  78. <dd>
  79. <p>Use the <code>gcov</code> program.
  80. </p>
  81. </dd>
  82. <dt>How do I find which lines in my program called a particular function?</dt>
  83. <dd>
  84. <p>Use &lsquo;<samp>gprof -l</samp>&rsquo; and lookup the function in the call graph.
  85. The callers will be broken down by function and line number.
  86. </p>
  87. </dd>
  88. <dt>How do I analyze a program that runs for less than a second?</dt>
  89. <dd>
  90. <p>Try using a shell script like this one:
  91. </p>
  92. <div class="example">
  93. <pre class="example">for i in `seq 1 100`; do
  94. fastprog
  95. mv gmon.out gmon.out.$i
  96. done
  97. gprof -s fastprog gmon.out.*
  98. gprof fastprog gmon.sum
  99. </pre></div>
  100. <p>If your program is completely deterministic, all the call counts
  101. will be simple multiples of 100 (i.e., a function called once in
  102. each run will appear with a call count of 100).
  103. </p>
  104. </dd>
  105. </dl>
  106. </body>
  107. </html>