home *** CD-ROM | disk | FTP | other *** search
-
-
- Atari ST Profiler
- -----------------
-
- Written by David Rowley
-
- What is a Profiler ?
- --------------------
-
- A Profiler is a program that monitors the execution of another program
- and writes out an analysis of where the program being monitored spends
- most of its execution time. The report states what percentage of the
- total execution time is taken up by each individual routine. This enables
- the programmer to improve the performance of the program much more
- efficiently, by concentrating on optimizing the routine(s) that account for
- the largest percentage of the total execution time.
-
- How does it work ?
- ------------------
-
- Profiling a program can be broken down into three parts: preparation,
- execution, and report generation.
-
- The preparation consists of reading in the symbol table of the executable
- to be profiled. This profiler recognizes the standard DRI/Alcyon format
- symbol table, as well as the Mark Williams symbol table format. In
- both formats, each symbol has a value associated with it, which represents
- the offset from the beginning of the program to where that symbol is
- located. Thus, the symbols values are the addresses of the symbols relative
- to the load address of the program to be profiled.
-
- The symbol table is then sorted by value, lowest to highest, and those
- symbols that do not refer to routines within the program (data and
- block-storage symbols) are thrown away.
-
- The profiler then starts the second phase of profiling: execution.
- First of all, we must load the program into memory. This is done
- by using the Pexec() system call in 'LOAD-NO-GO' mode. This loads
- the program, but does not execute it, and returns the address of
- where the program was loaded.
-
- The profiler then starts up an interrupt, using the Xbtimer() facility.
- The frequency of the interrupt is user-definable through the 'f=NNN'
- option. The program is then executed using the Pexec() call again,
- this time using the 'JUST-GO' mode. The program then executes normally,
- except that at regular intervals the Xbtimer() interrupt goes off.
-
- When an interrupt occurs, the program counter is pushed on the stack
- by the ST. The interrupt routine grabs the value of the PC off the
- stack and sees whether or not it falls within the address range of
- the program being run (it may not, it could be that execution was
- interrupted while running code in the ROMS). If the value is within
- the range of the program, the address is made relative to the
- start of the program (as returned by the initial Pexec()) and the
- value is then looked up in the symbol table, using a binary search.
- The symbol that corresponds to the relative address has it's count
- incremented, and the interrupt routine returns.
-
- This process continues until the program terminates normally. When
- execution finishes, it is time for the third phase: report generation.
-
- The report generation phase consists of sorting the symbol table
- according to the number of times the symbol was found during execution
- from most frequent to least. This number is then divided by the
- total number of interrupts that occured within the program being
- profiled to get the percentage of time spent in each routine. A simple
- table is then printed which shows the symbol name, the number of times
- the PC was found there, and the percentage of time that represents.
- A barchart is also printed, which shows the relative percentages in
- graphic form.
-
- The report is written to the file 'profile.out' unless otherwise specified
- by the 'o=file' option.
-
-
- The options are as follows:
-
- f=NNNN Specifies the number of samples per second. Value
- may be between 50 and 1500. The default is 250
- samples per second.
-
- p=NN Specifies the cutoff percentage. The profile summary
- generated will only list the top 'NN' percent of the
- symbols.
-
- +v/-v Use the VBLANK interrupt instead of Xbtimer. This
- is used if the application program to be profiled
- makes use of the Xbtimer() interrupt. Default is
- '-v'.
-
- +b/-b Print out a barchart to the right of the normal
- summary. Default is '+b'.
-
- +z/-z Include in the summary the symbols which were never
- 'hit' by the interrupt routine. Default is '-z'.
-
- o=filename Write the profile to 'filename'. The default is
- 'profile.out'
-
- x=sym In addition to the regular summary, print out a
- detailed summary of the symbol 'sym'. The symbol's
- address space is divided into a set of smaller
- intervals, the number of intervals being specified
- by the 'i=NNN' option.
-
- i=NNN Set the number of intervals to be used in the
- profiling of the symbol specified in the 'x=sym'
- option. The default is 'i=25'.
-
- For example, the program below:
-
- /*
- * Profile test program - Hi ho, Hi ho !
- */
-
- main()
- {
- dopey(), grumpy(), doc(), sleepy(),
- bashful(), happy(), sneezy();
- }
-
- dopey() { long i; for( i=0; i<100000L; i++ ); }
- grumpy() { long i; for( i=0; i<200000L; i++ ); }
- doc() { long i; for( i=0; i<100000L; i++ ); }
- sleepy() { long i; for( i=0; i<400000L; i++ ); }
- bashful() { long i; for( i=0; i<100000L; i++ ); }
- happy() { long i; for( i=0; i<200000L; i++ ); }
- sneezy() { long i; for( i=0; i<100000L; i++ ); }
-
- Produces the output:
-
- Profile of 'DWARFS.PRG '
-
- There are 82 symbols
-
- Samples in appl: 2621 (98.06 %)
- Samples in sys : 53 ( 1.98 %)
-
- Num. of samples: 2674
-
- Run lasted 2167 clock ticks (10 seconds)
- Samples per second: 247.29
- Cutoff at 95 percent
-
- +-----+------------+---------+---------+-----------------------------------+
- | # | Symbol | Count | Percent | Barchart |
- +-----+------------+---------+---------+-----------------------------------+
- | 1 | _sleepy | 874 | 33.39 |***********************************|
- | 2 | _happy | 436 | 16.68 |***************** |
- | 3 | _grumpy | 435 | 16.64 |***************** |
- | 4 | _doc | 220 | 8.39 |******** |
- | 5 | _sneezy | 220 | 8.39 |******** |
- | 6 | _bashful | 217 | 8.28 |******** |
- | 7 | _dopey | 217 | 8.28 |******** |
- +-----+------------+---------+---------+-----------------------------------+
-
-
- End of profile
-
-
- If you have any questions, comments or suggestions, please forward them
- to me at:
-
- UUCP: ...utzoo!watmath!looking!david
-
-
- Enjoy !
-
- David Rowley
- Looking Glass Software
- Home of ALICE: The Personal Pascal
- Waterloo, Ontario
- (519) 884-7473
-