File-Format.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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: File Format</title>
  15. <meta name="description" content="GNU gprof: File Format">
  16. <meta name="keywords" content="GNU gprof: File Format">
  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="Details.html#Details" rel="up" title="Details">
  24. <link href="Internals.html#Internals" rel="next" title="Internals">
  25. <link href="Implementation.html#Implementation" rel="prev" title="Implementation">
  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="File-Format"></a>
  57. <div class="header">
  58. <p>
  59. Next: <a href="Internals.html#Internals" accesskey="n" rel="next">Internals</a>, Previous: <a href="Implementation.html#Implementation" accesskey="p" rel="prev">Implementation</a>, Up: <a href="Details.html#Details" accesskey="u" rel="up">Details</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  60. </div>
  61. <hr>
  62. <a name="Profiling-Data-File-Format"></a>
  63. <h3 class="section">9.2 Profiling Data File Format</h3>
  64. <p>The old BSD-derived file format used for profile data does not contain a
  65. magic cookie that allows to check whether a data file really is a
  66. <code>gprof</code> file. Furthermore, it does not provide a version number, thus
  67. rendering changes to the file format almost impossible. <small>GNU</small> <code>gprof</code>
  68. uses a new file format that provides these features. For backward
  69. compatibility, <small>GNU</small> <code>gprof</code> continues to support the old BSD-derived
  70. format, but not all features are supported with it. For example,
  71. basic-block execution counts cannot be accommodated by the old file
  72. format.
  73. </p>
  74. <p>The new file format is defined in header file <samp>gmon_out.h</samp>. It
  75. consists of a header containing the magic cookie and a version number,
  76. as well as some spare bytes available for future extensions. All data
  77. in a profile data file is in the native format of the target for which
  78. the profile was collected. <small>GNU</small> <code>gprof</code> adapts automatically
  79. to the byte-order in use.
  80. </p>
  81. <p>In the new file format, the header is followed by a sequence of
  82. records. Currently, there are three different record types: histogram
  83. records, call-graph arc records, and basic-block execution count
  84. records. Each file can contain any number of each record type. When
  85. reading a file, <small>GNU</small> <code>gprof</code> will ensure records of the same type are
  86. compatible with each other and compute the union of all records. For
  87. example, for basic-block execution counts, the union is simply the sum
  88. of all execution counts for each basic-block.
  89. </p>
  90. <a name="Histogram-Records"></a>
  91. <h4 class="subsection">9.2.1 Histogram Records</h4>
  92. <p>Histogram records consist of a header that is followed by an array of
  93. bins. The header contains the text-segment range that the histogram
  94. spans, the size of the histogram in bytes (unlike in the old BSD
  95. format, this does not include the size of the header), the rate of the
  96. profiling clock, and the physical dimension that the bin counts
  97. represent after being scaled by the profiling clock rate. The
  98. physical dimension is specified in two parts: a long name of up to 15
  99. characters and a single character abbreviation. For example, a
  100. histogram representing real-time would specify the long name as
  101. &ldquo;seconds&rdquo; and the abbreviation as &ldquo;s&rdquo;. This feature is useful for
  102. architectures that support performance monitor hardware (which,
  103. fortunately, is becoming increasingly common). For example, under DEC
  104. OSF/1, the &ldquo;uprofile&rdquo; command can be used to produce a histogram of,
  105. say, instruction cache misses. In this case, the dimension in the
  106. histogram header could be set to &ldquo;i-cache misses&rdquo; and the abbreviation
  107. could be set to &ldquo;1&rdquo; (because it is simply a count, not a physical
  108. dimension). Also, the profiling rate would have to be set to 1 in
  109. this case.
  110. </p>
  111. <p>Histogram bins are 16-bit numbers and each bin represent an equal
  112. amount of text-space. For example, if the text-segment is one
  113. thousand bytes long and if there are ten bins in the histogram, each
  114. bin represents one hundred bytes.
  115. </p>
  116. <a name="Call_002dGraph-Records"></a>
  117. <h4 class="subsection">9.2.2 Call-Graph Records</h4>
  118. <p>Call-graph records have a format that is identical to the one used in
  119. the BSD-derived file format. It consists of an arc in the call graph
  120. and a count indicating the number of times the arc was traversed
  121. during program execution. Arcs are specified by a pair of addresses:
  122. the first must be within caller&rsquo;s function and the second must be
  123. within the callee&rsquo;s function. When performing profiling at the
  124. function level, these addresses can point anywhere within the
  125. respective function. However, when profiling at the line-level, it is
  126. better if the addresses are as close to the call-site/entry-point as
  127. possible. This will ensure that the line-level call-graph is able to
  128. identify exactly which line of source code performed calls to a
  129. function.
  130. </p>
  131. <a name="Basic_002dBlock-Execution-Count-Records"></a>
  132. <h4 class="subsection">9.2.3 Basic-Block Execution Count Records</h4>
  133. <p>Basic-block execution count records consist of a header followed by a
  134. sequence of address/count pairs. The header simply specifies the
  135. length of the sequence. In an address/count pair, the address
  136. identifies a basic-block and the count specifies the number of times
  137. that basic-block was executed. Any address within the basic-address can
  138. be used.
  139. </p>
  140. <hr>
  141. <div class="header">
  142. <p>
  143. Next: <a href="Internals.html#Internals" accesskey="n" rel="next">Internals</a>, Previous: <a href="Implementation.html#Implementation" accesskey="p" rel="prev">Implementation</a>, Up: <a href="Details.html#Details" accesskey="u" rel="up">Details</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  144. </div>
  145. </body>
  146. </html>