cpuprofile-fileformat.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <link rel="stylesheet" href="designstyle.css">
  5. <title>Google CPU Profiler Binary Data File Format</title>
  6. </HEAD>
  7. <BODY>
  8. <h1>Google CPU Profiler Binary Data File Format</h1>
  9. <p align=right>
  10. <i>Last modified
  11. <script type=text/javascript>
  12. var lm = new Date(document.lastModified);
  13. document.write(lm.toDateString());
  14. </script></i>
  15. </p>
  16. <p>This file documents the binary data file format produced by the
  17. Google CPU Profiler. For information about using the CPU Profiler,
  18. see <a href="cpuprofile.html">its user guide</a>.
  19. <p>The profiler source code, which generates files using this format, is at
  20. <code>src/profiler.cc</code></a>.
  21. <h2>CPU Profile Data File Structure</h2>
  22. <p>CPU profile data files each consist of four parts, in order:
  23. <ul>
  24. <li> Binary header
  25. <li> Binary profile records
  26. <li> Binary trailer
  27. <li> Text list of mapped objects
  28. </ul>
  29. <p>The binary data is expressed in terms of "slots." These are words
  30. large enough to hold the program's pointer type, i.e., for 32-bit
  31. programs they are 4 bytes in size, and for 64-bit programs they are 8
  32. bytes. They are stored in the profile data file in the native byte
  33. order (i.e., little-endian for x86 and x86_64).
  34. <h2>Binary Header</h2>
  35. <p>The binary header format is show below. Values written by the
  36. profiler, along with requirements currently enforced by the analysis
  37. tools, are shown in parentheses.
  38. <p>
  39. <table summary="Header Format"
  40. frame="box" rules="sides" cellpadding="5" width="50%">
  41. <tr>
  42. <th width="30%">slot</th>
  43. <th width="70%">data</th>
  44. </tr>
  45. <tr>
  46. <td>0</td>
  47. <td>header count (0; must be 0)</td>
  48. </tr>
  49. <tr>
  50. <td>1</td>
  51. <td>header slots after this one (3; must be &gt;= 3)</td>
  52. </tr>
  53. <tr>
  54. <td>2</td>
  55. <td>format version (0; must be 0)</td>
  56. </tr>
  57. <tr>
  58. <td>3</td>
  59. <td>sampling period, in microseconds</td>
  60. </tr>
  61. <tr>
  62. <td>4</td>
  63. <td>padding (0)</td>
  64. </tr>
  65. </table>
  66. <p>The headers currently generated for 32-bit and 64-bit little-endian
  67. (x86 and x86_64) profiles are shown below, for comparison.
  68. <p>
  69. <table summary="Header Example" frame="box" rules="sides" cellpadding="5">
  70. <tr>
  71. <th></th>
  72. <th>hdr count</th>
  73. <th>hdr words</th>
  74. <th>version</th>
  75. <th>sampling period</th>
  76. <th>pad</th>
  77. </tr>
  78. <tr>
  79. <td>32-bit or 64-bit (slots)</td>
  80. <td>0</td>
  81. <td>3</td>
  82. <td>0</td>
  83. <td>10000</td>
  84. <td>0</td>
  85. </tr>
  86. <tr>
  87. <td>32-bit (4-byte words in file)</td>
  88. <td><tt>0x00000</tt></td>
  89. <td><tt>0x00003</tt></td>
  90. <td><tt>0x00000</tt></td>
  91. <td><tt>0x02710</tt></td>
  92. <td><tt>0x00000</tt></td>
  93. </tr>
  94. <tr>
  95. <td>64-bit LE (4-byte words in file)</td>
  96. <td><tt>0x00000&nbsp;0x00000</tt></td>
  97. <td><tt>0x00003&nbsp;0x00000</tt></td>
  98. <td><tt>0x00000&nbsp;0x00000</tt></td>
  99. <td><tt>0x02710&nbsp;0x00000</tt></td>
  100. <td><tt>0x00000&nbsp;0x00000</tt></td>
  101. </tr>
  102. </table>
  103. <p>The contents are shown in terms of slots, and in terms of 4-byte
  104. words in the profile data file. The slot contents for 32-bit and
  105. 64-bit headers are identical. For 32-bit profiles, the 4-byte word
  106. view matches the slot view. For 64-bit profiles, each (8-byte) slot
  107. is shown as two 4-byte words, ordered as they would appear in the
  108. file.
  109. <p>The profiling tools examine the contents of the file and use the
  110. expected locations and values of the header words field to detect
  111. whether the file is 32-bit or 64-bit.
  112. <h2>Binary Profile Records</h2>
  113. <p>The binary profile record format is shown below.
  114. <p>
  115. <table summary="Profile Record Format"
  116. frame="box" rules="sides" cellpadding="5" width="50%">
  117. <tr>
  118. <th width="30%">slot</th>
  119. <th width="70%">data</th>
  120. </tr>
  121. <tr>
  122. <td>0</td>
  123. <td>sample count, must be &gt;= 1</td>
  124. </tr>
  125. <tr>
  126. <td>1</td>
  127. <td>number of call chain PCs (num_pcs), must be &gt;= 1</td>
  128. </tr>
  129. <tr>
  130. <td>2 .. (num_pcs + 1)</td>
  131. <td>call chain PCs, most-recently-called function first.
  132. </tr>
  133. </table>
  134. <p>The total length of a given record is 2 + num_pcs.
  135. <p>Note that multiple profile records can be emitted by the profiler
  136. having an identical call chain. In that case, analysis tools should
  137. sum the counts of all records having identical call chains.
  138. <p><b>Note:</b> Some profile analysis tools terminate if they see
  139. <em>any</em> profile record with a call chain with its first entry
  140. having the address 0. (This is similar to the binary trailer.)
  141. <h3>Example</h3>
  142. This example shows the slots contained in a sample profile record.
  143. <p>
  144. <table summary="Profile Record Example"
  145. frame="box" rules="sides" cellpadding="5">
  146. <tr>
  147. <td>5</td>
  148. <td>3</td>
  149. <td>0xa0000</td>
  150. <td>0xc0000</td>
  151. <td>0xe0000</td>
  152. </tr>
  153. </table>
  154. <p>In this example, 5 ticks were received at PC 0xa0000, whose
  155. function had been called by the function containing 0xc0000, which had
  156. been called from the function containing 0xe0000.
  157. <h2>Binary Trailer</h2>
  158. <p>The binary trailer consists of three slots of data with fixed
  159. values, shown below.
  160. <p>
  161. <table summary="Trailer Format"
  162. frame="box" rules="sides" cellpadding="5" width="50%">
  163. <tr>
  164. <th width="30%">slot</th>
  165. <th width="70%">value</th>
  166. </tr>
  167. <tr>
  168. <td>0</td>
  169. <td>0</td>
  170. </tr>
  171. <tr>
  172. <td>1</td>
  173. <td>1</td>
  174. </tr>
  175. <tr>
  176. <td>2</td>
  177. <td>0</td>
  178. </tr>
  179. </table>
  180. <p>Note that this is the same data that would contained in a profile
  181. record with sample count = 0, num_pcs = 1, and a one-element call
  182. chain containing the address 0.
  183. <h2>Text List of Mapped Objects</h2>
  184. <p>The binary data in the file is followed immediately by a list of
  185. mapped objects. This list consists of lines of text separated by
  186. newline characters.
  187. <p>Each line is one of the following types:
  188. <ul>
  189. <li>Build specifier, starting with "<tt>build=</tt>". For example:
  190. <pre> build=/path/to/binary</pre>
  191. Leading spaces on the line are ignored.
  192. <li>Mapping line from ProcMapsIterator::FormatLine. For example:
  193. <pre> 40000000-40015000 r-xp 00000000 03:01 12845071 /lib/ld-2.3.2.so</pre>
  194. The first address must start at the beginning of the line.
  195. </ul>
  196. <p>Unrecognized lines should be ignored by analysis tools.
  197. <p>When processing the paths see in mapping lines, occurrences of
  198. <tt>$build</tt> followed by a non-word character (i.e., characters
  199. other than underscore or alphanumeric characters), should be replaced
  200. by the path given on the last build specifier line.
  201. <hr>
  202. <address>Chris Demetriou<br>
  203. <!-- Created: Mon Aug 27 12:18:26 PDT 2007 -->
  204. <!-- hhmts start -->
  205. Last modified: Mon Aug 27 12:18:26 PDT 2007 (cgd)
  206. <!-- hhmts end -->
  207. </address>
  208. </BODY>
  209. </HTML>