home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / h / hotprofile next >
Text File  |  1996-11-14  |  2KB  |  48 lines

  1. <TITLE>HotProfile Class -- Python library reference</TITLE>
  2. Prev: <A HREF="../o/oldprofile_class" TYPE="Prev">OldProfile Class</A>  
  3. Up: <A HREF="../p/profiler_extensions" TYPE="Up">Profiler Extensions</A>  
  4. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  5. <H2>9.8.2. HotProfile Class</H2>
  6. This profiler is the fastest derived profile example.  It does not
  7. calculate caller-callee relationships, and does not calculate
  8. cumulative time under a function.  It only calculates time spent in a
  9. function, so it runs very quickly (re: very low overhead).  In truth,
  10. the basic profiler is so fast, that is probably not worth the savings
  11. to give up the data, but this class still provides a nice example.
  12. <P>
  13. <UL COMPACT><CODE>class HotProfile(Profile):<P>
  14. <P>
  15.     def trace_dispatch_exception(self, frame, t):<P>
  16.         rt, rtt, rfn, rframe, rcur = self.cur<P>
  17.         if rcur and not rframe is frame:<P>
  18.             return self.trace_dispatch_return(rframe, t)<P>
  19.         return 0<P>
  20. <P>
  21.     def trace_dispatch_call(self, frame, t):<P>
  22.         self.cur = (t, 0, frame, self.cur)<P>
  23.         return 1<P>
  24. <P>
  25.     def trace_dispatch_return(self, frame, t):<P>
  26.         rt, rtt, frame, rcur = self.cur<P>
  27. <P>
  28.         rfn = `frame.f_code`<P>
  29. <P>
  30.         pt, ptt, pframe, pcur = rcur<P>
  31.         self.cur = pt, ptt+rt, pframe, pcur<P>
  32. <P>
  33.         if self.timings.has_key(rfn):<P>
  34.             nc, tt = self.timings[rfn]<P>
  35.             self.timings[rfn] = nc + 1, rt + rtt + tt<P>
  36.         else:<P>
  37.             self.timings[rfn] =      1, rt + rtt<P>
  38. <P>
  39.         return 1<P>
  40. <P>
  41.     def snapshot_stats(self):<P>
  42.         self.stats = {}<P>
  43.         for func in self.timings.keys():<P>
  44.             nc, tt = self.timings[func]<P>
  45.             nor_func = self.func_normalize(func)<P>
  46.             self.stats[nor_func] = nc, nc, tt, 0, {}<P>
  47. </CODE></UL>
  48.