home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / pascal / PROFILER.ZIP / PROFILE.DOC < prev   
Encoding:
Text File  |  1987-01-02  |  8.8 KB  |  177 lines

  1.  
  2.        EXECUTION PROFILER    --by Ralph G. Brickner
  3.  
  4.      Taken from PC Tech Journal, Nov/86 by Geoff Mitchell, Big Blue & Cousins
  5.      Document by Geoff Mitchell
  6.  
  7. This is a rather nice profiler and since the full source code is included
  8. you can customize it.  If you want a full explanation of all the ins and outs,
  9. you should get a copy of the article.
  10.  
  11. If you should get the magazine, you will find a few changes in the assembly
  12. language coding.  This is because the version in the magazine generated phase
  13. errors when I assembled it with MASM 3.0.  Brickner used the IBM Macro assembler
  14. version 1.0 which may account for the difference.  In any case, I found it
  15. necessary to re-arrange the subroutines.
  16.  
  17. TURBO version 3.0 was the Pascal compiler used.  The Pascal source is 
  18. unchanged except to place the statement  LowVideo; in the first display
  19. procedure.
  20.  
  21. The package consists of the following files:
  22.  
  23. PROFILE.BAT
  24. PRF.COM
  25. LISTPRF.COM
  26. PRF.ASM
  27. LISTPRF.PAS
  28.  
  29.  
  30. There are a few items which you need to know in order to operate the program 
  31. without the magazine as a reference. 
  32.  
  33. 1.  The first three files above must be in your default directory as well
  34.      as the program you wish to profile.
  35.  
  36. 2.  There must be enough room left over in that directory (or that disk
  37.     drive) for the program you wish to profile to be copied.
  38.  
  39.     If you look at PROFILE.BAT, you will see that the first thing it does
  40.     is copy your test program into a file called SUBJECT.COM.  It does not
  41.     matter if your program has an .EXE extension.  SUBJECT.COM is then run
  42.     from within PRF.COM and deleted by PROFILE.BAT when it is finished.
  43.  
  44. 3.  A further examination of PROFILE.BAT indicates that you can pass up to
  45.     two paramters for your test program.  For instance, if you wish to
  46.     profile the DOS program COMP.COM and have it work on the files TEST1.TXT
  47.     in Drive B and TEST2.TXT in Drive C, then put COMP.COM and the three
  48.     profiler files in Drive A and enter the command:
  49.  
  50.     A> PROFILE COMP.COM B:TEST1.TXT C:TEST2.TXT
  51.  
  52.     since the echo is on, you can watch the progress of events.  You will not
  53.     be able to profile a program with three or more parameters.
  54.  
  55. 4.  The profiler consists of two parts:
  56.  
  57.         A. PRF.COM is the actual profiler, what Brickner calls the kernel.
  58.  
  59.         PRF.COM loads and executes the program to be profiled.  While that
  60.     program is running, it uses the timer interrupt to gather the locations 
  61.     your code spends its time and store them in memory. It does this by 
  62.     copying into a RAM buffer the contents of the CS and IP registers from the 
  63.     stack where they are pushed by INT 8 (the timer interrupt) which in a 
  64.     normal PC is invoked 18.2 times per second . 
  65.  
  66.         The buffer set aside in memory to store this information is 60K. A
  67.     little arithmetic should prove that you can store 15,000 double words (the 
  68.     space required by CS:IP) in 60K which at 18.2 samples per second should 
  69.     take 844 seconds. This is the limit of PRF.COM in its default 
  70.     configuration. 
  71.  
  72.         You can change these default settings, however.
  73.  
  74.         The constant TABLE_SIZE is the first equate in PRF.ASM and can be 
  75.      changed from 0F00H (60K) to whatever memory you think you can afford.
  76.  
  77.         The constant NUMBER_OF_TICKS is the second equate.  It is set at 1.  
  78.      For small programs, you can increase this which has the effect of 
  79.      speeding up the clock so you take more samples per second.  As you speed 
  80.      up the system clock, there is some degradation of performance of the 
  81.      program you are executing as more and more processer time is spent 
  82.      running the profiler.
  83.  
  84.         If you mulitply the sampling rate ten times by equating 
  85.      NUMBER_OF_TICKS to 10, then you would be able to run a program for 
  86.      approximately 844/10 seconds before filling your data buffer.  The 
  87.      relation is only approximate due to the time overhead of running the 
  88.      profiler.
  89.  
  90.         If you speed up the sampling by a factor of 500, time is split more or
  91.      less evenly between the profiler and the program it is running.
  92.  
  93.         You should bear in mind that many operations of the disk controllers are
  94.      timing loop dependent, so changing the clock rate can have unpredictable 
  95.      results in some applications. 
  96.  
  97.         Changing these equates requires assembling, linking and converting to 
  98.      binary PRF.ASM.  If you should go through the hassle, it might be worth 
  99.      your while to have one version with the clock sped up 10 times, another 
  100.      50 times, and another 100 times in addition to the one you have received 
  101.      in which the clock is not sped up at all. 
  102.  
  103.         If you wish to slow the sampling down for truly long-running programs,
  104.      it should be fairly easy to change the sampling routine to take a
  105.      sample on every other clock tick, or every tenth one, or what have you.
  106.  
  107.         B. LISTPRF.COM
  108.  
  109.         This program simply displays the information gathered by PRF.COM.
  110.      The coding is a little tricky in places and it does have a few bugs when 
  111.      you start pushing it to its limits.  TurboPascal programmers might like 
  112.      to play around with it a bit and do some fixups. 
  113.  
  114.         The first screen is pretty well self-explanatory.  If you should have 
  115.      changed the clock rate, however, you will find that the elapsed time 
  116.      displayed will have been increased by the factor of the speed-up.  Among
  117.      other things, this screen displays all the code segments accessed by the 
  118.      tested program with the number of samples in each.  These segments are 
  119.      numbered from one up.  You should note the numbers of the ones you are 
  120.      interested in because once you leave this screen, you cannot get back to 
  121.      it and access the information contained therein.  Another fix perhaps?
  122.  
  123.         The next screen displays a histogram of the information contained in 
  124.      the first screen.  It is labelled Segment Histogram.  If you answer 'y' 
  125.      to the print prompt, it will dump it to your printer as well.
  126.  
  127.         You are then prompted for a particular segment.  After inputting a 
  128.      segment number, you are prompted for 'number of bins desired (< = 2048)'. 
  129.      This is where things get interesting.  What the program does is subtract 
  130.      the minimum offset from maximum offset of your code in that segment and
  131.      divides the result by the 'number of bins' you input in order to
  132.      create a sampling interval.  It then prints out a histogram of the number 
  133.      of hits in each bin.  It also gives you the opportunity to forgo 
  134.      displaying empty bins. 
  135.  
  136.         Each line of the histogram starts with an offset into the specified 
  137.      segment followed by some figure which is the width in bytes of the bins 
  138.      as you specify them.  The program loops so you can go through the 
  139.      procedure several times specifying different numbers of bins which  has 
  140.      the effect of varying the distance from which you see the data.  
  141.  
  142.         By increasing the number of bins, you reduce their width and so space 
  143.      the hits out.  In many programs, it should be possible to track the 
  144.      execution of particular instructions down to their exact addresses.
  145.                       ------------------------
  146.  
  147.                       General Comments.
  148.  
  149.          The main problem with this program is that the sampling cannot be 
  150. turned on or off.  You have to sample an entire program, not just the 
  151. particular part in which you happen to be interested. 
  152.  
  153.         A means does exist to change this.  PRF.ASM checks a flag (ACCUM_FLAG) 
  154. to see if it should accumulate data or not.  To implement turning sampling on 
  155. and off, PRF.COM and SUBJECT.COM must agree on a location for the flag so that 
  156. SUBJECT may set it and PRF read it.  A relatively safe place to put it would 
  157. be in the area used by the BASIC interpreter at 0000:0128.  Using relative 
  158. addressing could create problems.
  159.  
  160.         Obviously, it is not possible to do this without access to the source 
  161. code of the program being profiled; but that should be no problem with 
  162. programs you are developing yourself.
  163.  
  164.         A second improvement would be to utilize DOS memory management 
  165. functions to eliminate the pre-initialized 60K memory buffer.  This should not
  166. be too hard to do and would have the effect of cutting the size of PRF.COM 
  167. from 63K to 3K thereby saving alot of disk space and loading time.
  168.  
  169.         A third problem with this program is that it cannot be used to profile
  170. resident programs.  It is difficult to see how that can be rectified.  If you
  171. should try to profile a resident program, it will do a profile of the
  172. installation O.K. but as soon as the DOS terminate and stay resident function
  173. is called, control will be handed back to PRF.COM and the profiler will go
  174. into its display phase.
  175.  
  176.  
  177.