home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_200
/
259_01
/
profile.doc
< prev
next >
Wrap
Text File
|
1988-02-25
|
13KB
|
358 lines
PRF - An Application Profile Package
====================================
PRF is an application profile package which may be used to enhance
the performance of your 'C' language programs developed under MSDOS
on an IBM/PC or 100% compatible system.
In general, it is very desirable to have an application program
execute as fast as possible. After a program is written and tested
most programmers go back over the code "one more time" looking for
areas where the program can be made more efficient. Obviously,
improving the performance of an area of the program which is
executed many times will increase overall performance more than an
area which is seldom executed. However, in most large programs it
is very difficult to guess where the program is spending most of
its time. This is where PRF comes into play. PRF will execute
along with your program and check on the areas where most of the
time is being spent. This allows you to then go back an examine
these areas for performance improvements.
Utilities Included
------------------
The following utilities are included in this package:
TIMER.C A general purpose program timer. This utility
TIMER.EXE can be used without PRF simply to time the
execution of one of your programs. Running
TIMER on a program before and after making
modifications will tell you how much (if any)
performance improvement resulted from your
changes.
MAKEPRF.C A utility to build a PRF symbol file from the
MAKEPRF.EXE information contained in a .MAP file created
by your linker. This symbol file is then used
to monitor the execution of your program and
report the results.
PRFRPT.C A reporting utility which will read the output
PRFRPT.EXE of a profile session (a .PR1 file) and format
a report of the results.
CPROFILE.C The 'C' language portion of the PRF runtime
module. This module should be compiled and
placed in a library where it can automatically
be picked up as needed by your linker.
APROFILE.ASM The assembly language portion of the PRF
APROFILE.OBJ runtime module. This module should be placed
in a library where it can automatically be
picked up by your linker.
Preparing Your Source Code
--------------------------
Since the runtime portion of PRF is linked into your .EXE module,
there are several minor changes you must make to your source code
to run a profile session. As mentioned above, PRF obtains all the
information about your program from the .MAP file produced by the
linker. Functions in your code which are declared as "static" will
NOT be included in the .MAP and PRF will not know about them.
Therefore, when using PRF all functions in your code should be
declared public (i.e. not static). Having static modules in the
program you are running PRF with can distort the statistics for
those modules which are public. To avoid this, code all your
static routines as follows:
#define STATIC static
STATIC void my_func()
Then when you want to run PRF change the #define STATIC to remove
the "static" declaration as follows:
#define STATIC
Before running a profile session:
1) Function StartProfile("MYPROG"); should be called at the point
you want the profile operation to start. The parameter (MYPROG
in this example) should be the name of the .MAP file created by
your linker. In general, this will be the same root name as
that of the .EXE file.
2) Function EndProfile(); should be called at the point you wish
to halt the profile operation.
Usually StartProfile() will be called as the first statement in
main() and EndProfile() will be called as the last statement before
program termination.
After making these changes all modules of your program should be
re-compiled. If you desire line number statistics be sure to
include the switch to inform your compiler to generate line number
information in the .OBJ file. Once you've compiled all modules of
your application with "line numbers" link your program. Be sure
to use linker switches /MAP (and /LINE if you want line numbers) to
generate a .MAP file.
Sample Session - Microsoft C
----------------------------
The following sample session shows the steps required to profile an
application we will call MYPROG which consists of modules MYPROG.C,
MYUTIL.C, and MYINIT.C.
1) Edit MYPROG.C and add StartProfile("myprog"); as the first
statement in main(). Add EndProfile() as the last statement
in main().
2) Compile the programs:
cl /c /Zd myprog.c
cl /c /Zd myutil.c
cl /c /Zd myinit.c
3) Link the program producing a .MAP file (We are assuming that
the PRF code resides in library PRF.LIB):
link /map /line myprog myutil myinit,,,prf;
4) Create a profile symbol table file (this produces a .PRF file):
makeprf myprog
5) Run the program (this produces the .PR1 file):
myprog myparms
6) Read the .PR1 file and produce profile report:
prfrpt myprog
Sample Session - Borland Turbo C
--------------------------------
The following sample session shows the steps required to profile an
application we will call MYPROG which consists of modules MYPROG.C,
MYUTIL.C, and MYINIT.C.
1) Edit MYPROG.C and add StartProfile("myprog"); as the first
statement in main(). Add EndProfile() as the last statement
in main().
2) Compile the programs:
tcc -y myprog.c
tcc -y myutil.c
tcc -y myinit.c
3) Link the program producing a .MAP file (We are assuming that
the PRF code resides in library PRF.LIB):
tcc -ml myprog.obj myutil.obj myinit.obj prf.lib
4) Create a profile symbol table file (this produces a .PRF file):
makeprf myprog
5) Run the program (this produces the .PR1 file):
myprog myparms
6) Read the .PR1 file and produce profile report:
prfrpt myprog
Reading the PRF Report
----------------------
Following is a sample of the report produced by PRFRPT.EXE. Due
to the length of this particular report some portions have been
removed from this listing.
Segment: _TEXT Length: 18661 (48E5h)
Public Symbols Count Tot% Hit%
DGROUP@ 538 1.2 2.9 *
_ShowListBox 1 0.0 0.0
_ScrollWindow 1 0.0 0.0
_ShowInvertRect 1 0.0 0.0
_main 8 0.0 0.0
SCRCLEARRECT 11 0.0 0.1
SCRINVERTATTR 2254 5.1 12.2 ****
SCRINVERTBUFFER 2899 6.5 15.6 ******
_brk 2 0.0 0.0
_free 23 0.1 0.1
_getch 1 0.0 0.0
_getdate 4381 9.8 23.6 *********
_gettime 147 0.3 0.8
_int86 288 0.6 1.6
_int86x 861 1.9 4.6 *
_IOERROR 212 0.5 1.1
_LONGTOA 6 0.0 0.0
LXMUL@ 794 1.8 4.3 *
_malloc 20 0.0 0.1
_memcpy 2 0.0 0.0
_movedata 323 0.7 1.7
_movmem 3 0.0 0.0
_segread 218 0.5 1.2
_setvbuf 1 0.0 0.0
_time 4244 9.5 22.9 *********
_strcpy 4 0.0 0.0
_strlen 6 0.0 0.0
_dostounix 421 0.9 2.3
_VPRINTER 14 0.0 0.1
Line number statistics for module WINDEMO.C
Line Number Count Tot% Hit%
26 526 1.2 2.8 *
53 1 0.0 0.0
76 2 0.0 0.0
91 2 0.0 0.0
141 7 0.0 0.0
164 1 0.0 0.0
218 1 0.0 0.0
247 1 0.0 0.0
Line number statistics for module LISTBOX.C
Line Number Count Tot% Hit%
72 2 0.0 0.0
76 2 0.0 0.0
77 2 0.0 0.0
94 2 0.0 0.0
169 1 0.0 0.0
181 1 0.0 0.0
191 1 0.0 0.0
209 1 0.0 0.0
224 1 0.0 0.0
Line number statistics for module WIN.C
Line Number Count Tot% Hit%
63 4 0.0 0.0
65 18 0.0 0.1
67 4 0.0 0.0
68 4 0.0 0.0
83 6 0.0 0.0
85 2 0.0 0.0
122 3 0.0 0.0
124 3 0.0 0.0
126 3 0.0 0.0
129 3 0.0 0.0
131 5 0.0 0.0
132 3 0.0 0.0
256 1 0.0 0.0
280 1 0.0 0.0
284 3 0.0 0.0
Line number statistics for module SCRIO.C
Line Number Count Tot% Hit%
82 2 0.0 0.0
86 2 0.0 0.0
100 1 0.0 0.0
121 15 0.0 0.1
122 6 0.0 0.0
124 3 0.0 0.0
141 11 0.0 0.1
142 3 0.0 0.0
163 3 0.0 0.0
166 4 0.0 0.0
168 4 0.0 0.0
186 313 0.7 1.7
190 320 0.7 1.7
191 326 0.7 1.8
192 1008 2.3 5.4 **
193 287 0.6 1.5
213 2899 6.5 15.6 ******
231 14 0.0 0.1
21673 Hits in MS-DOS
2673 Hits in ROM BIOS
18531 Hits in Application Pgm
1738 Other hits
44615 Total hits recorded
The report produced by PRFRPT.EXE is contains a section devoted to
each code segment in your program. This section begins with the
name and length of the segment.
For each code segment a listing of all public symbols which were
found to be using time by PRF are listed. The public symbols are
reported as follows with a histogram of the "Hit%" shown to the
right of the statistics.
Public Symbols - The name of the public routine which
contained "hits".
Count - Total number of hits recorded for this
public routine.
Tot% - Percentage of time this routine used
relative to all of the hits recorded.
This includes hits that occurred outside
of the application program and are,
in general, out of the application
programmers control.
Hit% - Percentage of time this routine used
relative to the hits recorded within
the application code.
If the .MAP file included line number information, additional
statistics are generated for each source code module for which line
number information is found. The statistics for line numbers are the
same as those for public symbols with the exception that the actual
source code line number replaces the public symbol name.
How PRF Works
-------------
The runtime portion of PRF uses the clock timer interrupt to get control
of the system at frequent intervals and examines the CS:IP registers of
the interrupted code to record a "hit". Under normal conditions the
clock timer interrupt is invoked 18.2 times a second. In order to get
a better resolution of the running application, PRF speeds up the system
timer to produce interrupts 582.4 times per second. This frequency of
interrupts gives a much better view of the sections of the program which
are using time. As usual, however, there is a trade off involved here.
The more frequently your program is interrupted to "record a hit", the
slower (elapsed time) your program will run. You can increase or
decrease this interrupt frequency in module APROFILE.ASM by setting
the equates TIMER_INT_CNT and TIMER_INT_WORD. APROFILE.ASM contains
a table listing the valid values of these equates. Note that PRF calls
the ROM BIOS clock interrupt 18.2 times per second no matter how often
PRF is recording hits. This assures that your system clock remains
accurate and is not "speeded up" during a PRF session.
Development Compilers
---------------------
This code was developed and tested under the following compilers.
Borland Turbo-C V1.0
Microsoft Quick-C V1.0
Microsoft C V5.00
Microsoft C V4.00
Disclaimer
----------
This package has been released into the public domain by the author.
It is non-supported software and you use it at your own risk. I have
tested this package and to the best of my knowledge it contains no
errors. However, I do not guarantee that it is error free.
Comments, suggestions, questions, and constructive criticism are
welcomed by the author:
Bob Withers
649 Meadowbrook St.
Allen, Texas 75002