home *** CD-ROM | disk | FTP | other *** search
- <TITLE>Profiler Extensions -- Python library reference</TITLE>
- Prev: <A HREF="../c/calibration" TYPE="Prev">Calibration</A>
- Up: <A HREF="../t/the_python_profiler" TYPE="Up">The Python Profiler</A>
- Top: <A HREF="../t/top" TYPE="Top">Top</A>
- <H1>9.8. Extensions --- Deriving Better Profilers</H1>
- The <CODE>Profile</CODE> class of module <CODE>profile</CODE> was written so that
- derived classes could be developed to extend the profiler. Rather
- than describing all the details of such an effort, I'll just present
- the following two examples of derived classes that can be used to do
- profiling. If the reader is an avid Python programmer, then it should
- be possible to use these as a model and create similar (and perchance
- better) profile classes.
- <P>
- If all you want to do is change how the timer is called, or which
- timer function is used, then the basic class has an option for that in
- the constructor for the class. Consider passing the name of a
- function to call into the constructor:
- <P>
- <UL COMPACT><CODE> pr = profile.Profile(your_time_func)<P>
- </CODE></UL>
- The resulting profiler will call <CODE>your_time_func()</CODE> instead of
- <CODE>os.times()</CODE>. The function should return either a single number
- or a list of numbers (like what <CODE>os.times()</CODE> returns). If the
- function returns a single time number, or the list of returned numbers
- has length 2, then you will get an especially fast version of the
- dispatch routine.
- <P>
- Be warned that you <I>should</I> calibrate the profiler class for the
- timer function that you choose. For most machines, a timer that
- returns a lone integer value will provide the best results in terms of
- low overhead during profiling. (os.times is <I>pretty</I> bad, 'cause
- it returns a tuple of floating point values, so all arithmetic is
- floating point in the profiler!). If you want to substitute a
- better timer in the cleanest fashion, you should derive a class, and
- simply put in the replacement dispatch method that better handles your
- timer call, along with the appropriate calibration constant :-).
- <P>
- <H2>Menu</H2><DL COMPACT>
- <DT><A HREF="../o/oldprofile_class" TYPE=Menu>OldProfile Class</A>
- <DD><DT><A HREF="../h/hotprofile_class" TYPE=Menu>HotProfile Class</A>
- <DD></DL>
-