home *** CD-ROM | disk | FTP | other *** search
-
- Execution time profiler for C programs running under RISCOS 2.00
- ================================================================
- (version 1.00, 04-06-1990)
-
- With the -p[x] option Archimedes C programmers are able to see
- during program execution how often a function is called. This is
- an usefull feature when optimising your code.
-
- But sometimes it isn't enough to know how often a function is
- called. More interesting is how much time is spend in one
- particular function. The function which uses most time is a
- candidate for optimising.
-
- Unfortunately the Norcroft C 3.00 compiler hasn't a facility to
- do execution time profiling, so I had to write it myself.
-
-
- How to install it?
- ==================
-
- Define in your source file where 'main' is defined:
-
- #define EXPRO 1
-
- and include then
-
- #include "h.exprofle"
-
- Now call as soon as possible in 'main':
-
- exprofle_init("filename");
-
- With filename is the file where the execution time profiling
- information is written to at the end of program execution.
-
- Compile without the -ff option to include functionnames in the
- code.
-
- After compilation link with the o.exprolib library as the first
- library specified.
-
-
- How does it work?
- =================
-
- After calling 'exprofle_init()' the following happens:
- - check if running under RISCOS 2.00.
- - check if FPEmulator is present and if get its start and end
- address.
- - search for all functionnames and save pointers to them.
- - intercept the undefined instruction vector with a routine
- that saves the return address.
- - register an OS_CallEvery function which is called every 1/100
- of a second.
- - register an atexit function.
-
- Now the program is interrupted every 1/100 of a second and the
- return address is binary searched in an array of functionname
- pointers. When the address interval is found a counter for that
- function is incremented.
- It is possible that the return address lies outside the program
- code, i.e. the program is executing some OS routine.
- When the program uses floating point arithmetic the return
- address could be in the FPEmulator module as well. In that case
- the counter for the fpemulator is incremented, and because we've
- intercepted the undefined instruction vector we know the address
- from where the fpemulator is called. Now this address is binary
- searched in the functionpointer array (in this way we can see how
- much of the total time is spent with floating point calculations
- and at the same time have correct profile values for every
- function).
- In all other cases we increment the 'greaterthan' entry.
-
- When the program exits through 'exit' the execution time
- profiling data will be written to the output file.
-
- The execution time profiling will be correct in most cases but
- you have to be prepared to get some strange results. These
- errors are due to the fact that the libraries (Stubs, Ansilib,
- RISC_OSlib) are compiled with the -ff option to prevent function
- name inclusion.
-
- When your program contains pieces of assembly you have to look
- after the following points:
- - give the code AREA the name: C$$code
- - include functionnames as shown below:
-
- foo_X
- DCB "foo", 0
- ALIGN
- foo_Y
- DCD &ff000000 + foo_Y - foo_X
-
- EXPORT foo
- foo
- ect.
-
-
- If the program is running under the WIMP environment the
- functions: wimp_poll, wimp_pollidle,
- wimp_save_fp_state_on_poll and wimp_corrupt_fp_state_on_poll
- are rewritten to prevent the interruption of other tasks.
- So when linking, o.exprolib has to be earlier in the list of
- libraries than o.RISC_OSlib.
-
-
- Comments or bug reports may be send to:
- =======================================
-
- Ferdinand Oeinck
- Javalaan 25
- 9715 GP Groningen
- The Netherlands
- tel. ++31(0)50 732202
-
-
- ------------------------------------------------------------------------------
- Added by Paul Moore 02/06/91:
-
- Changes introduced for inclusion in my Utils library
- ====================================================
-
- 1. All internal functions have been renamed, with a prefix of "_profile" in
- place of the previous "expro". This is just cosmetic, and based on my
- belief that the names of functions not available to the user should start
- with an underscore. I also modified the layout of the resulting report
- slightly.
-
- 2. Both time profiles (as implemented by the author) and count profiles (as
- built into the C library) are now handled by the same library.
-
- 3. To include profiling, you now need the following:
-
- /* if undefined, profile_init() expands to nothing */
- #define PROFILE
- #include "Profile.h"
-
- and then, at the start of main(), call profile_init(filename,type), where
- filename is the name of the file to which profiling statistics will be
- written ("", or an unwritable file, gives stderr), and type is one of the
- two constants Profile_Time and Profile_Count (defined in Profile.h).
-
- 4. For time profiling, the profiling library (part of my Utils library) must
- be included in the link command line, PRIOR to Risc_OSLib, as some of the
- standard functions are redefined. No special compiler options are required.
-
- For count profiling, the source files to be profiled must be compiled with
- the -p (function level) or -px (basic block level) compiler option. The
- object must be linked with both the profiling library and AnsiLib (for the
- _mapstore() functions), but it is still possible to link in Stubs in order
- to use the shared C library. There is no ordering restriction on the
- libraries in this case.
-
- 5. To include C-style function headers in assembler code (as described
- by Ferdinand, when discussing how to get profiling for assembler functions)
- I have written an ObjAsm macro, which does it all for you. See the
- definition of macro Func, in the source file Asm.ProfileAsm. Feel free
- to copy and use this, if you think it may be helpful.
-
- Thanks to Ferdinand for this library. I take no credit for any of the good
- ideas in here, but if there are any bugs, you can probably blame me for those.
-
- Paul Moore,
- 10, Mulberry Rise,
- Firdale Park,
- Northwich,
- Cheshire
- CW8 4UQ
- England
-
- E-Mail: pmoore@cix.compulink.co.uk
- or pmoore%cix@ukc.ac.uk
-
- ------------------------------------------------------------------------------
-