home *** CD-ROM | disk | FTP | other *** search
- <TITLE>OldProfile Class -- Python library reference</TITLE>
- Next: <A HREF="../h/hotprofile_class" TYPE="Next">HotProfile Class</A>
- Prev: <A HREF="../p/profiler_extensions" TYPE="Prev">Profiler Extensions</A>
- Up: <A HREF="../p/profiler_extensions" TYPE="Up">Profiler Extensions</A>
- Top: <A HREF="../t/top" TYPE="Top">Top</A>
- <H2>9.8.1. OldProfile Class</H2>
- The following derived profiler simulates the old style profiler,
- providing errant results on recursive functions. The reason for the
- usefulness of this profiler is that it runs faster (i.e., less
- overhead) than the old profiler. It still creates all the caller
- stats, and is quite useful when there is <I>no</I> recursion in the
- user's code. It is also a lot more accurate than the old profiler, as
- it does not charge all its overhead time to the user's code.
- <P>
- <UL COMPACT><CODE>class OldProfile(Profile):<P>
- <P>
- def trace_dispatch_exception(self, frame, t):<P>
- rt, rtt, rct, rfn, rframe, rcur = self.cur<P>
- if rcur and not rframe is frame:<P>
- return self.trace_dispatch_return(rframe, t)<P>
- return 0<P>
- <P>
- def trace_dispatch_call(self, frame, t):<P>
- fn = `frame.f_code`<P>
- <P>
- self.cur = (t, 0, 0, fn, frame, self.cur)<P>
- if self.timings.has_key(fn):<P>
- tt, ct, callers = self.timings[fn]<P>
- self.timings[fn] = tt, ct, callers<P>
- else:<P>
- self.timings[fn] = 0, 0, {}<P>
- return 1<P>
- <P>
- def trace_dispatch_return(self, frame, t):<P>
- rt, rtt, rct, rfn, frame, rcur = self.cur<P>
- rtt = rtt + t<P>
- sft = rtt + rct<P>
- <P>
- pt, ptt, pct, pfn, pframe, pcur = rcur<P>
- self.cur = pt, ptt+rt, pct+sft, pfn, pframe, pcur<P>
- <P>
- tt, ct, callers = self.timings[rfn]<P>
- if callers.has_key(pfn):<P>
- callers[pfn] = callers[pfn] + 1<P>
- else:<P>
- callers[pfn] = 1<P>
- self.timings[rfn] = tt+rtt, ct + sft, callers<P>
- <P>
- return 1<P>
- <P>
- def snapshot_stats(self):<P>
- self.stats = {}<P>
- for func in self.timings.keys():<P>
- tt, ct, callers = self.timings[func]<P>
- nor_func = self.func_normalize(func)<P>
- nor_callers = {}<P>
- nc = 0<P>
- for func_caller in callers.keys():<P>
- nor_callers[self.func_normalize(func_caller)]=\<P>
- callers[func_caller]<P>
- nc = nc + callers[func_caller]<P>
- self.stats[nor_func] = nc, nc, tt, ct, nor_callers<P>
- </CODE></UL>
-