[Python-checkins] CVS: python/dist/src/Doc/lib libprofile.tex,1.32,1.33
Fred L. Drake
fdrake@users.sourceforge.net
Thu, 07 Jun 2001 22:04:22 -0700
Update of /cvsroot/python/python/dist/src/Doc/lib
In directory usw-pr-cvs1:/tmp/cvs-serv30817/lib
Modified Files:
libprofile.tex
Log Message:
In the section on extending the profiler, add some additional discussion
about setting up the dispatch table, and update the OldProfile and
HotProfile classes to the current implementations, showing the adjusted
construction for the dispatch table.
Index: libprofile.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libprofile.tex,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -r1.32 -r1.33
*** libprofile.tex 2001/04/13 14:34:58 1.32
--- libprofile.tex 2001/06/08 05:04:19 1.33
***************
*** 656,667 ****
returns a lone integer value will provide the best results in terms of
low overhead during profiling. (\function{os.times()} is
! \emph{pretty} 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 :-).
\subsection{OldProfile Class \label{profile-old}}
--- 656,695 ----
returns a lone integer value will provide the best results in terms of
low overhead during profiling. (\function{os.times()} is
! \emph{pretty} bad, as 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.
+ Note that subclasses which override any of the
+ \method{trace_dispatch_call()}, \method{trace_dispatch_exception()},
+ or \method{trace_dispatch_return()} methods also need to specify a
+ dispatch table as well. The table, named \member{dispatch}, should
+ have the three keys \code{'call'}, \code{'exception'}, and
+ \code{'return'}, each giving the function of the corresponding
+ handler. Note that best performance is achieved by using the
+ \emph{function} objects for the handlers and not bound methods. This
+ is preferred since calling a simple function object executes less code
+ in the runtime than calling either bound or unbound methods. For
+ example, if the derived profiler overrides only one method, the
+ \member{dispatch} table can be built like this:
+ \begin{verbatim}
+ from profile import Profile
+
+ class MyProfiler(Profile):
+ def trace_dispath_call(self, frame, t):
+ # do something interesting here
+ ...
+
+ dispatch = {
+ 'call': trace_dispatch_call,
+ 'exception': Profile.__dict__['trace_dispatch_exception'],
+ 'return': Profile.__dict__['trace_dispatch_return'],
+ }
+ \end{verbatim}
+
+
\subsection{OldProfile Class \label{profile-old}}
***************
*** 685,689 ****
def trace_dispatch_call(self, frame, t):
fn = `frame.f_code`
!
self.cur = (t, 0, 0, fn, frame, self.cur)
if self.timings.has_key(fn):
--- 713,717 ----
def trace_dispatch_call(self, frame, t):
fn = `frame.f_code`
!
self.cur = (t, 0, 0, fn, frame, self.cur)
if self.timings.has_key(fn):
***************
*** 711,714 ****
--- 739,747 ----
return 1
+ dispatch = {
+ "call": trace_dispatch_call,
+ "exception": trace_dispatch_exception,
+ "return": trace_dispatch_return,
+ }
def snapshot_stats(self):
***************
*** 716,729 ****
for func in self.timings.keys():
tt, ct, callers = self.timings[func]
! nor_func = self.func_normalize(func)
! nor_callers = {}
nc = 0
for func_caller in callers.keys():
- nor_callers[self.func_normalize(func_caller)] = \
- callers[func_caller]
nc = nc + callers[func_caller]
! self.stats[nor_func] = nc, nc, tt, ct, nor_callers
\end{verbatim}
\subsection{HotProfile Class \label{profile-HotProfile}}
--- 749,760 ----
for func in self.timings.keys():
tt, ct, callers = self.timings[func]
! callers = callers.copy()
nc = 0
for func_caller in callers.keys():
nc = nc + callers[func_caller]
! self.stats[func] = nc, nc, tt, ct, callers
\end{verbatim}
+
\subsection{HotProfile Class \label{profile-HotProfile}}
***************
*** 764,767 ****
--- 795,803 ----
return 1
+ dispatch = {
+ "call": trace_dispatch_call,
+ "exception": trace_dispatch_exception,
+ "return": trace_dispatch_return,
+ }
def snapshot_stats(self):
***************
*** 769,773 ****
for func in self.timings.keys():
nc, tt = self.timings[func]
! nor_func = self.func_normalize(func)
! self.stats[nor_func] = nc, nc, tt, 0, {}
\end{verbatim}
--- 805,808 ----
for func in self.timings.keys():
nc, tt = self.timings[func]
! self.stats[func] = nc, nc, tt, 0, {}
\end{verbatim}