Profiling.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
  2. <html>
  3. <!-- Created on December 10, 2012 by texi2html 1.82
  4. texi2html was written by:
  5. Lionel Cons <[email protected]> (original author)
  6. Karl Berry <[email protected]>
  7. Olaf Bachmann <[email protected]>
  8. and many others.
  9. Maintained by: Many creative people.
  10. Send bugs and suggestions to <[email protected]>
  11. -->
  12. <head>
  13. <title>avram - a virtual machine code interpreter: 3.7 Profiling</title>
  14. <meta name="description" content="avram - a virtual machine code interpreter: 3.7 Profiling">
  15. <meta name="keywords" content="avram - a virtual machine code interpreter: 3.7 Profiling">
  16. <meta name="resource-type" content="document">
  17. <meta name="distribution" content="global">
  18. <meta name="Generator" content="texi2html 1.82">
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <style type="text/css">
  21. <!--
  22. a.summary-letter {text-decoration: none}
  23. blockquote.smallquotation {font-size: smaller}
  24. pre.display {font-family: serif}
  25. pre.format {font-family: serif}
  26. pre.menu-comment {font-family: serif}
  27. pre.menu-preformatted {font-family: serif}
  28. pre.smalldisplay {font-family: serif; font-size: smaller}
  29. pre.smallexample {font-size: smaller}
  30. pre.smallformat {font-family: serif; font-size: smaller}
  31. pre.smalllisp {font-size: smaller}
  32. span.roman {font-family:serif; font-weight:normal;}
  33. span.sansserif {font-family:sans-serif; font-weight:normal;}
  34. ul.toc {list-style: none}
  35. -->
  36. </style>
  37. </head>
  38. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  39. <a name="Profiling"></a>
  40. <table cellpadding="1" cellspacing="1" border="0">
  41. <tr><td valign="middle" align="left">[<a href="Error-Reporting.html#Error-Reporting" title="Previous section in reading order"> &lt; </a>]</td>
  42. <td valign="middle" align="left">[<a href="Emulation-Primitives.html#Emulation-Primitives" title="Next section in reading order"> &gt; </a>]</td>
  43. <td valign="middle" align="left"> &nbsp; </td>
  44. <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  45. <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Up section"> Up </a>]</td>
  46. <td valign="middle" align="left">[<a href="Character-Table.html#Character-Table" title="Next chapter"> &gt;&gt; </a>]</td>
  47. <td valign="middle" align="left"> &nbsp; </td>
  48. <td valign="middle" align="left"> &nbsp; </td>
  49. <td valign="middle" align="left"> &nbsp; </td>
  50. <td valign="middle" align="left"> &nbsp; </td>
  51. <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
  52. <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
  53. <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
  54. <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
  55. </tr></table>
  56. <hr size="1">
  57. <a name="Profiling-1"></a>
  58. <h2 class="section">3.7 Profiling</h2>
  59. <a name="index-profile_002eh"></a>
  60. <p>The functions declared in &lsquo;<tt>profile.h</tt>&rsquo; can be used for constructing
  61. and writing tables of run time statistics such as those mentioned in
  62. <a href="Files.html#Files">Files</a>, and <a href="Profile.html#Profile">Profile</a>. These functions maintain a database of
  63. structures, each recording the statistics for a particular virtual code
  64. fragment.
  65. </p>
  66. <p>Each structure in the database is identified by a unique key, which must
  67. be a list representing a character string. A pointer to such a structure
  68. <a name="index-score"></a>
  69. is declared to be of type <code>score</code>. For the most part, the data
  70. structure should be regarded as opaque by a client program, except for a
  71. field <code>reductions</code> of type <code>counter</code>, which may be modified
  72. arbitrarily by the client.
  73. </p>
  74. <p>The way these operations are used in the course of evaluating virtual
  75. code applications containing profile annotations is to add a structure
  76. to the database each time a new profiled code fragment is encountered,
  77. using the annotation as its key, and to increment the <code>reductions</code>
  78. <a name="index-annotations-1"></a>
  79. of the structure each time any constituent of the code gets a quantum of
  80. work done on it. Other ways of using these operations are left to the
  81. developer&rsquo;s discretion.
  82. </p>
  83. <dl>
  84. <dt><a name="index-avm_005fentries"></a><u>Function:</u> score <b>avm_entries</b><i> (list <var>team</var>, list *<var>message</var>, int *<var>fault</var>)</i></dt>
  85. <dd><p>This function retrieves or creates a data base entry given its key. The
  86. parameters have these interpretations.
  87. </p>
  88. <dl compact="compact">
  89. <dt> <code><var>team</var></code></dt>
  90. <dd><p>is a list representing a character string that uniquely identifies the
  91. database entry to be retrieved or created.
  92. </p></dd>
  93. <dt> <code><var>message</var></code></dt>
  94. <dd><p>is the address of a list known to the caller, which will be assigned a
  95. list representing an error message if any error occurs in the course of
  96. searching the database or creating a new entry.
  97. </p></dd>
  98. <dt> <code><var>fault</var></code></dt>
  99. <dd><p>is the address of an integer that will be set to a non-zero value if any
  100. error is caused by this function.
  101. </p></dd>
  102. </dl>
  103. <p>The pointer returned by this function is the address of the record whose
  104. key is given by the <code><var>team</var></code> parameter. If such a record is
  105. already in the database, its address is returned, but otherwise a new
  106. one is created whose address is then returned. The <code>reductions</code>
  107. field of a newly created entry will be zero.
  108. </p>
  109. <p>In the course of searching the database, the <code>avm_compare</code>
  110. function is used, so the associated lists may be modified as noted in
  111. <a href="Comparison.html#Comparison">Comparison</a>. It is not necessary for a client to include the header
  112. file &lsquo;<tt>compare.h</tt>&rsquo; or to call <code>avm_initialize_compare</code> in order
  113. to use the profile operations, because they are done automatically.
  114. </p>
  115. <p>If an error message is assigned to the list referenced by
  116. <code><var>message</var></code>, the integer referenced by <code><var>fault</var></code> will
  117. be set to a non-zero value. The form of the error message will be a list
  118. in which each item is a list of character representations as per
  119. <a href="Character-Table.html#Character-Table">Character Table</a>. It is the responsibility of the caller to dispose
  120. of the error message. Currently the only possible error is a memory
  121. overflow, which in this case is non-fatal.
  122. </p></dd></dl>
  123. <dl>
  124. <dt><a name="index-avm_005ftally"></a><u>Function:</u> void <b>avm_tally</b><i> (char *<var>filename</var>)</i></dt>
  125. <dd><p>This function makes a table of the results stored in the data base built
  126. by the <code>avm_entries</code> function. The argument is the address of a
  127. null terminated character string containing the name of the file in
  128. which the results will be written. A file is opened and the table is
  129. written in a self explanatory text format, with columns labeled
  130. &ldquo;reductions&rdquo; and &ldquo;invocations&rdquo; among others. The latter contains the
  131. number of times the associated key was accessed through
  132. <code>avm_entries</code>.
  133. </p>
  134. <p>The data written to the file should be taken with a grain of salt. It
  135. is computed using native integer and floating point arithmetic, with no
  136. checks made for overflow or roundoff error, and no guarantee of cross
  137. <a name="index-reductions"></a>
  138. platform portability. The number of &ldquo;reductions&rdquo; means whatever the
  139. developer of the client program wants it to mean.
  140. </p>
  141. <p>The following error messages are possible with this function, which will
  142. be written to standard error. None of them is fatal.
  143. <a name="index-can_0027t-write-5"></a>
  144. <a name="index-can_0027t-close-2"></a>
  145. <a name="index-invalid-profile-identifier-1"></a>
  146. </p>
  147. <ul>
  148. <li> <code><var>program-name</var>: can't write <var>filename</var></code>
  149. </li><li> <code><var>program-name</var>: can't write to <var>filename</var></code>
  150. </li><li> <code><var>program-name</var>: can't close <var>filename</var></code>
  151. </li><li> <code><var>program-name</var>: invalid profile identifier</code>
  152. </li></ul>
  153. <p>The last message is reported if any record in the database has a key
  154. that is not a list of valid character representations. The others are
  155. <a name="index-strerror-5"></a>
  156. accompanied by an explanation from the standard <code>strerror</code> function
  157. if possible.
  158. </p></dd></dl>
  159. <dl>
  160. <dt><a name="index-avm_005finitialize_005fprofile"></a><u>Function:</u> void <b>avm_initialize_profile</b><i> ()</i></dt>
  161. <dd><p>This function should be called before any of the other functions in this
  162. section in order to initialize the data base. Results are undefined if
  163. it is not called first.
  164. </p></dd></dl>
  165. <dl>
  166. <dt><a name="index-avm_005fcount_005fprofile"></a><u>Function:</u> void <b>avm_count_profile</b><i> ()</i></dt>
  167. <dd><p>This function can be called after the other functions in this section as
  168. a way of detecting memory leaks. If any storage remains unreclaimed that
  169. was created by the functions in this section, a warning message is
  170. written to standard error. If the <code>avm_count_lists</code> function is
  171. being used by the client program, it should be called after this one.
  172. </p></dd></dl>
  173. <hr size="1">
  174. <table cellpadding="1" cellspacing="1" border="0">
  175. <tr><td valign="middle" align="left">[<a href="Error-Reporting.html#Error-Reporting" title="Previous section in reading order"> &lt; </a>]</td>
  176. <td valign="middle" align="left">[<a href="Emulation-Primitives.html#Emulation-Primitives" title="Next section in reading order"> &gt; </a>]</td>
  177. <td valign="middle" align="left"> &nbsp; </td>
  178. <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  179. <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Up section"> Up </a>]</td>
  180. <td valign="middle" align="left">[<a href="Character-Table.html#Character-Table" title="Next chapter"> &gt;&gt; </a>]</td>
  181. <td valign="middle" align="left"> &nbsp; </td>
  182. <td valign="middle" align="left"> &nbsp; </td>
  183. <td valign="middle" align="left"> &nbsp; </td>
  184. <td valign="middle" align="left"> &nbsp; </td>
  185. <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
  186. <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
  187. <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
  188. <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
  189. </tr></table>
  190. <p>
  191. <font size="-1">
  192. This document was generated on <i>December 10, 2012</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 1.82</i></a>.
  193. </font>
  194. <br>
  195. </p>
  196. </body>
  197. </html>