home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / profile / profile.doc < prev    next >
Text File  |  1987-03-30  |  7KB  |  175 lines

  1.  
  2.  
  3. Atari ST Profiler
  4. -----------------
  5.  
  6. Written by David Rowley
  7.  
  8. What is a Profiler ?
  9. --------------------
  10.  
  11. A Profiler is a program that monitors the execution of another program
  12. and writes out an analysis of where the program being monitored spends
  13. most of its execution time.  The report states what percentage of the
  14. total execution time is taken up by each individual routine.  This enables
  15. the programmer to improve the performance of the program much more
  16. efficiently, by concentrating on optimizing the routine(s) that account for
  17. the largest percentage of the total execution time.
  18.  
  19. How does it work ?
  20. ------------------
  21.  
  22. Profiling a program can be broken down into three parts: preparation,
  23. execution, and report generation.
  24.  
  25. The preparation consists of reading in the symbol table of the executable
  26. to be profiled.  This profiler recognizes the standard DRI/Alcyon format
  27. symbol table, as well as the Mark Williams symbol table format.  In
  28. both formats, each symbol has a value associated with it, which represents
  29. the offset from the beginning of the program to where that symbol is
  30. located.  Thus, the symbols values are the addresses of the symbols relative
  31. to the load address of the program to be profiled.
  32.  
  33. The symbol table is then sorted by value, lowest to highest, and those
  34. symbols that do not refer to routines within the program (data and
  35. block-storage symbols) are thrown away.
  36.  
  37. The profiler then starts the second phase of profiling: execution.
  38. First of all, we must load the program into memory.  This is done
  39. by using the Pexec() system call in 'LOAD-NO-GO' mode.  This loads
  40. the program, but does not execute it, and returns the address of
  41. where the program was loaded.
  42.  
  43. The profiler then starts up an interrupt, using the Xbtimer() facility.
  44. The frequency of the interrupt is user-definable through the 'f=NNN'
  45. option.  The program is then executed using the Pexec() call again,
  46. this time using the 'JUST-GO' mode.  The program then executes normally,
  47. except that at regular intervals the Xbtimer() interrupt goes off.
  48.  
  49. When an interrupt occurs, the program counter is pushed on the stack
  50. by the ST.  The interrupt routine grabs the value of the PC off the
  51. stack and sees whether or not it falls within the address range of
  52. the program being run (it may not, it could be that execution was
  53. interrupted while running code in the ROMS).  If the value is within
  54. the range of the program, the address is made relative to the
  55. start of the program (as returned by the initial Pexec()) and the
  56. value is then looked up in the symbol table, using a binary search.
  57. The symbol that corresponds to the relative address has it's count
  58. incremented, and the interrupt routine returns.
  59.  
  60. This process continues until the program terminates normally.  When
  61. execution finishes, it is time for the third phase: report generation.
  62.  
  63. The report generation phase consists of sorting the symbol table
  64. according to the number of times the symbol was found during execution
  65. from most frequent to least.  This number is then divided by the 
  66. total number of interrupts that occured within the program being
  67. profiled to get the percentage of time spent in each routine.  A simple
  68. table is then printed which shows the symbol name, the number of times
  69. the PC was found there, and the percentage of time that represents.
  70. A barchart is also printed, which shows the relative percentages in
  71. graphic form.
  72.  
  73. The report is written to the file 'profile.out' unless otherwise specified
  74. by the 'o=file' option.
  75.  
  76.  
  77. The options are as follows:
  78.  
  79.     f=NNNN        Specifies the number of samples per second.  Value
  80.             may be between 50 and 1500.  The default is 250
  81.             samples per second.
  82.  
  83.     p=NN        Specifies the cutoff percentage.  The profile summary
  84.             generated will only list the top 'NN' percent of the
  85.             symbols.
  86.  
  87.     +v/-v        Use the VBLANK interrupt instead of Xbtimer.  This
  88.             is used if the application program to be profiled
  89.             makes use of the Xbtimer() interrupt.  Default is
  90.             '-v'.
  91.  
  92.     +b/-b        Print out a barchart to the right of the normal
  93.             summary.  Default is '+b'.
  94.  
  95.     +z/-z        Include in the summary the symbols which were never
  96.             'hit' by the interrupt routine.  Default is '-z'.
  97.  
  98.     o=filename    Write the profile to 'filename'.  The default is
  99.             'profile.out'
  100.  
  101.     x=sym        In addition to the regular summary, print out a
  102.             detailed summary of the symbol 'sym'.  The symbol's
  103.             address space is divided into a set of smaller
  104.             intervals, the number of intervals being specified
  105.             by the 'i=NNN' option.
  106.  
  107.     i=NNN        Set the number of intervals to be used in the
  108.             profiling of the symbol specified in the 'x=sym'
  109.             option.  The default is 'i=25'.
  110.  
  111. For example, the program below:
  112.  
  113. /*
  114.  * Profile test program - Hi ho, Hi ho !
  115.  */
  116.  
  117. main()
  118. {
  119.     dopey(), grumpy(), doc(), sleepy(),
  120.     bashful(), happy(), sneezy();
  121. }
  122.  
  123. dopey()   { long i; for( i=0; i<100000L; i++ ); }
  124. grumpy()  { long i; for( i=0; i<200000L; i++ ); }
  125. doc()     { long i; for( i=0; i<100000L; i++ ); }
  126. sleepy()  { long i; for( i=0; i<400000L; i++ ); }
  127. bashful() { long i; for( i=0; i<100000L; i++ ); }
  128. happy()   { long i; for( i=0; i<200000L; i++ ); }
  129. sneezy()  { long i; for( i=0; i<100000L; i++ ); }
  130.  
  131. Produces the output:
  132.  
  133. Profile of 'DWARFS.PRG '
  134.  
  135. There are 82 symbols
  136.  
  137. Samples in appl:     2621  (98.06 %)
  138. Samples in sys :       53  ( 1.98 %)
  139.  
  140. Num. of samples:     2674
  141.  
  142. Run lasted 2167 clock ticks (10 seconds)
  143. Samples per second: 247.29
  144. Cutoff at 95 percent
  145.  
  146. +-----+------------+---------+---------+-----------------------------------+
  147. |   # |   Symbol   |  Count  | Percent |             Barchart              |
  148. +-----+------------+---------+---------+-----------------------------------+
  149. |   1 |    _sleepy |     874 |   33.39 |***********************************|
  150. |   2 |     _happy |     436 |   16.68 |*****************                  |
  151. |   3 |    _grumpy |     435 |   16.64 |*****************                  |
  152. |   4 |       _doc |     220 |    8.39 |********                           |
  153. |   5 |    _sneezy |     220 |    8.39 |********                           |
  154. |   6 |   _bashful |     217 |    8.28 |********                           |
  155. |   7 |     _dopey |     217 |    8.28 |********                           |
  156. +-----+------------+---------+---------+-----------------------------------+
  157.  
  158.  
  159. End of profile
  160.  
  161.  
  162. If you have any questions, comments or suggestions, please forward them
  163. to me at:
  164.  
  165. UUCP: ...utzoo!watmath!looking!david
  166.  
  167.  
  168. Enjoy !
  169.  
  170. David Rowley
  171. Looking Glass Software
  172. Home of ALICE: The Personal Pascal
  173. Waterloo, Ontario
  174. (519) 884-7473
  175.