Profiling.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <html lang="en">
  2. <head>
  3. <title>Profiling - avram - a virtual machine code interpreter</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="avram - a virtual machine code interpreter">
  6. <meta name="generator" content="makeinfo 4.13">
  7. <link title="Top" rel="start" href="index.html#Top">
  8. <link rel="up" href="Library-Reference.html#Library-Reference" title="Library Reference">
  9. <link rel="prev" href="Error-Reporting.html#Error-Reporting" title="Error Reporting">
  10. <link rel="next" href="Emulation-Primitives.html#Emulation-Primitives" title="Emulation Primitives">
  11. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  12. <meta http-equiv="Content-Style-Type" content="text/css">
  13. <style type="text/css"><!--
  14. pre.display { font-family:inherit }
  15. pre.format { font-family:inherit }
  16. pre.smalldisplay { font-family:inherit; font-size:smaller }
  17. pre.smallformat { font-family:inherit; font-size:smaller }
  18. pre.smallexample { font-size:smaller }
  19. pre.smalllisp { font-size:smaller }
  20. span.sc { font-variant:small-caps }
  21. span.roman { font-family:serif; font-weight:normal; }
  22. span.sansserif { font-family:sans-serif; font-weight:normal; }
  23. --></style>
  24. </head>
  25. <body>
  26. <div class="node">
  27. <a name="Profiling"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="Emulation-Primitives.html#Emulation-Primitives">Emulation Primitives</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="Error-Reporting.html#Error-Reporting">Error Reporting</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="Library-Reference.html#Library-Reference">Library Reference</a>
  32. <hr>
  33. </div>
  34. <h3 class="section">3.7 Profiling</h3>
  35. <p><a name="index-g_t_0040file_007bprofile_002eh_007d-616"></a>The functions declared in <samp><span class="file">profile.h</span></samp> can be used for constructing
  36. and writing tables of run time statistics such as those mentioned in
  37. <a href="Files.html#Files">Files</a>, and <a href="Profile.html#Profile">Profile</a>. These functions maintain a database of
  38. structures, each recording the statistics for a particular virtual code
  39. fragment.
  40. <p>Each structure in the database is identified by a unique key, which must
  41. be a list representing a character string. A pointer to such a structure
  42. <a name="index-g_t_0040code_007bscore_007d-617"></a>is declared to be of type <code>score</code>. For the most part, the data
  43. structure should be regarded as opaque by a client program, except for a
  44. field <code>reductions</code> of type <code>counter</code>, which may be modified
  45. arbitrarily by the client.
  46. <p>The way these operations are used in the course of evaluating virtual
  47. code applications containing profile annotations is to add a structure
  48. to the database each time a new profiled code fragment is encountered,
  49. using the annotation as its key, and to increment the <code>reductions</code>
  50. <a name="index-annotations-618"></a>of the structure each time any constituent of the code gets a quantum of
  51. work done on it. Other ways of using these operations are left to the
  52. developer's discretion.
  53. <div class="defun">
  54. &mdash; Function: score <b>avm_entries</b> (<var>list team, list *message, int *fault</var>)<var><a name="index-avm_005fentries-619"></a></var><br>
  55. <blockquote><p>This function retrieves or creates a data base entry given its key. The
  56. parameters have these interpretations.
  57. <dl>
  58. <dt><var>team</var><dd>is a list representing a character string that uniquely identifies the
  59. database entry to be retrieved or created.
  60. <br><dt><var>message</var><dd>is the address of a list known to the caller, which will be assigned a
  61. list representing an error message if any error occurs in the course of
  62. searching the database or creating a new entry.
  63. <br><dt><var>fault</var><dd>is the address of an integer that will be set to a non-zero value if any
  64. error is caused by this function.
  65. </dl>
  66. <p>The pointer returned by this function is the address of the record whose
  67. key is given by the <var>team</var> parameter. If such a record is
  68. already in the database, its address is returned, but otherwise a new
  69. one is created whose address is then returned. The <code>reductions</code>
  70. field of a newly created entry will be zero.
  71. <p>In the course of searching the database, the <code>avm_compare</code>
  72. function is used, so the associated lists may be modified as noted in
  73. <a href="Comparison.html#Comparison">Comparison</a>. It is not necessary for a client to include the header
  74. file <samp><span class="file">compare.h</span></samp> or to call <code>avm_initialize_compare</code> in order
  75. to use the profile operations, because they are done automatically.
  76. <p>If an error message is assigned to the list referenced by
  77. <var>message</var>, the integer referenced by <var>fault</var> will
  78. be set to a non-zero value. The form of the error message will be a list
  79. in which each item is a list of character representations as per
  80. <a href="Character-Table.html#Character-Table">Character Table</a>. It is the responsibility of the caller to dispose
  81. of the error message. Currently the only possible error is a memory
  82. overflow, which in this case is non-fatal.
  83. </p></blockquote></div>
  84. <div class="defun">
  85. &mdash; Function: void <b>avm_tally</b> (<var>char *filename</var>)<var><a name="index-avm_005ftally-620"></a></var><br>
  86. <blockquote><p>This function makes a table of the results stored in the data base built
  87. by the <code>avm_entries</code> function. The argument is the address of a
  88. null terminated character string containing the name of the file in
  89. which the results will be written. A file is opened and the table is
  90. written in a self explanatory text format, with columns labeled
  91. &ldquo;reductions&rdquo; and &ldquo;invocations&rdquo; among others. The latter contains the
  92. number of times the associated key was accessed through
  93. <code>avm_entries</code>.
  94. <p>The data written to the file should be taken with a grain of salt. It
  95. is computed using native integer and floating point arithmetic, with no
  96. checks made for overflow or roundoff error, and no guarantee of cross
  97. <a name="index-reductions-621"></a>platform portability. The number of &ldquo;reductions&rdquo; means whatever the
  98. developer of the client program wants it to mean.
  99. <p>The following error messages are possible with this function, which will
  100. be written to standard error. None of them is fatal.
  101. <a name="index-g_t_0040code_007bcan_0027t-write_007d-622"></a><a name="index-g_t_0040code_007bcan_0027t-close_007d-623"></a><a name="index-g_t_0040code_007binvalid-profile-identifier_007d-624"></a>
  102. <ul>
  103. <li><var>program-name</var><code>: can't write </code><var>filename</var>
  104. <li><var>program-name</var><code>: can't write to </code><var>filename</var>
  105. <li><var>program-name</var><code>: can't close </code><var>filename</var>
  106. <li><var>program-name</var><code>: invalid profile identifier</code>
  107. </ul>
  108. <p>The last message is reported if any record in the database has a key
  109. that is not a list of valid character representations. The others are
  110. <a name="index-g_t_0040code_007bstrerror_007d-625"></a>accompanied by an explanation from the standard <code>strerror</code> function
  111. if possible.
  112. </p></blockquote></div>
  113. <div class="defun">
  114. &mdash; Function: void <b>avm_initialize_profile</b> ()<var><a name="index-avm_005finitialize_005fprofile-626"></a></var><br>
  115. <blockquote><p>This function should be called before any of the other functions in this
  116. section in order to initialize the data base. Results are undefined if
  117. it is not called first.
  118. </p></blockquote></div>
  119. <div class="defun">
  120. &mdash; Function: void <b>avm_count_profile</b> ()<var><a name="index-avm_005fcount_005fprofile-627"></a></var><br>
  121. <blockquote><p>This function can be called after the other functions in this section as
  122. a way of detecting memory leaks. If any storage remains unreclaimed that
  123. was created by the functions in this section, a warning message is
  124. written to standard error. If the <code>avm_count_lists</code> function is
  125. being used by the client program, it should be called after this one.
  126. </p></blockquote></div>
  127. </body></html>