home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / o / oldprofile < prev    next >
Text File  |  1996-11-14  |  3KB  |  64 lines

  1. <TITLE>OldProfile Class -- Python library reference</TITLE>
  2. Next: <A HREF="../h/hotprofile_class" TYPE="Next">HotProfile Class</A>  
  3. Prev: <A HREF="../p/profiler_extensions" TYPE="Prev">Profiler Extensions</A>  
  4. Up: <A HREF="../p/profiler_extensions" TYPE="Up">Profiler Extensions</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H2>9.8.1. OldProfile Class</H2>
  7. The following derived profiler simulates the old style profiler,
  8. providing errant results on recursive functions. The reason for the
  9. usefulness of this profiler is that it runs faster (i.e., less
  10. overhead) than the old profiler.  It still creates all the caller
  11. stats, and is quite useful when there is <I>no</I> recursion in the
  12. user's code.  It is also a lot more accurate than the old profiler, as
  13. it does not charge all its overhead time to the user's code.
  14. <P>
  15. <UL COMPACT><CODE>class OldProfile(Profile):<P>
  16. <P>
  17.     def trace_dispatch_exception(self, frame, t):<P>
  18.         rt, rtt, rct, rfn, rframe, rcur = self.cur<P>
  19.         if rcur and not rframe is frame:<P>
  20.             return self.trace_dispatch_return(rframe, t)<P>
  21.         return 0<P>
  22. <P>
  23.     def trace_dispatch_call(self, frame, t):<P>
  24.         fn = `frame.f_code`<P>
  25. <P>
  26.         self.cur = (t, 0, 0, fn, frame, self.cur)<P>
  27.         if self.timings.has_key(fn):<P>
  28.             tt, ct, callers = self.timings[fn]<P>
  29.             self.timings[fn] = tt, ct, callers<P>
  30.         else:<P>
  31.             self.timings[fn] = 0, 0, {}<P>
  32.         return 1<P>
  33. <P>
  34.     def trace_dispatch_return(self, frame, t):<P>
  35.         rt, rtt, rct, rfn, frame, rcur = self.cur<P>
  36.         rtt = rtt + t<P>
  37.         sft = rtt + rct<P>
  38. <P>
  39.         pt, ptt, pct, pfn, pframe, pcur = rcur<P>
  40.         self.cur = pt, ptt+rt, pct+sft, pfn, pframe, pcur<P>
  41. <P>
  42.         tt, ct, callers = self.timings[rfn]<P>
  43.         if callers.has_key(pfn):<P>
  44.             callers[pfn] = callers[pfn] + 1<P>
  45.         else:<P>
  46.             callers[pfn] = 1<P>
  47.         self.timings[rfn] = tt+rtt, ct + sft, callers<P>
  48. <P>
  49.         return 1<P>
  50. <P>
  51.     def snapshot_stats(self):<P>
  52.         self.stats = {}<P>
  53.         for func in self.timings.keys():<P>
  54.             tt, ct, callers = self.timings[func]<P>
  55.             nor_func = self.func_normalize(func)<P>
  56.             nor_callers = {}<P>
  57.             nc = 0<P>
  58.             for func_caller in callers.keys():<P>
  59.                 nor_callers[self.func_normalize(func_caller)]=\<P>
  60.                       callers[func_caller]<P>
  61.                 nc = nc + callers[func_caller]<P>
  62.             self.stats[nor_func] = nc, nc, tt, ct, nor_callers<P>
  63. </CODE></UL>
  64.