home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
p
/
python
/
pyhtmldoc
/
h
/
hotprofile
next >
Wrap
Text File
|
1996-11-14
|
2KB
|
48 lines
<TITLE>HotProfile Class -- Python library reference</TITLE>
Prev: <A HREF="../o/oldprofile_class" TYPE="Prev">OldProfile Class</A>
Up: <A HREF="../p/profiler_extensions" TYPE="Up">Profiler Extensions</A>
Top: <A HREF="../t/top" TYPE="Top">Top</A>
<H2>9.8.2. HotProfile Class</H2>
This profiler is the fastest derived profile example. It does not
calculate caller-callee relationships, and does not calculate
cumulative time under a function. It only calculates time spent in a
function, so it runs very quickly (re: very low overhead). In truth,
the basic profiler is so fast, that is probably not worth the savings
to give up the data, but this class still provides a nice example.
<P>
<UL COMPACT><CODE>class HotProfile(Profile):<P>
<P>
def trace_dispatch_exception(self, frame, t):<P>
rt, rtt, 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>
self.cur = (t, 0, frame, self.cur)<P>
return 1<P>
<P>
def trace_dispatch_return(self, frame, t):<P>
rt, rtt, frame, rcur = self.cur<P>
<P>
rfn = `frame.f_code`<P>
<P>
pt, ptt, pframe, pcur = rcur<P>
self.cur = pt, ptt+rt, pframe, pcur<P>
<P>
if self.timings.has_key(rfn):<P>
nc, tt = self.timings[rfn]<P>
self.timings[rfn] = nc + 1, rt + rtt + tt<P>
else:<P>
self.timings[rfn] = 1, rt + rtt<P>
<P>
return 1<P>
<P>
def snapshot_stats(self):<P>
self.stats = {}<P>
for func in self.timings.keys():<P>
nc, tt = self.timings[func]<P>
nor_func = self.func_normalize(func)<P>
self.stats[nor_func] = nc, nc, tt, 0, {}<P>
</CODE></UL>