[Python-checkins] CVS: python/dist/src/Lib profile.py,1.33,1.34
Tim Peters
tim_one@users.sourceforge.net
Fri, 05 Oct 2001 16:15:13 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv28558/python/Lib
Modified Files:
profile.py
Log Message:
The fix to profile semantics broke the miserable but advertised way to
derive Profile subclasses. This patch repairs that, restoring
negative tuple indices. Yuck? You bet.
Index: profile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/profile.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** profile.py 2001/10/04 00:58:24 1.33
--- profile.py 2001/10/05 23:15:10 1.34
***************
*** 110,128 ****
used to write into the frames local dictionary!!) Derived classes
can change the definition of some entries, as long as they leave
! [3:] intact.
! [0] = Time that needs to be charged to the parent frame's function.
! It is used so that a function call will not have to access the
! timing data for the parent frame.
! [1] = Total time spent in this frame's function, excluding time in
! subfunctions
! [2] = Cumulative time spent in this frame's function, including time in
! all subfunctions to this frame (but excluding this frame!).
! [3] = Name of the function that corresponds to this frame.
! [4] = Actual frame that we correspond to (used to sync exception handling)
! [5] = Our parent 6-tuple (corresponds to frame.f_back)
Timing data for each function is stored as a 5-tuple in the dictionary
! self.timings[]. The index is always the name stored in self.cur[4].
The following are the definitions of the members:
--- 110,129 ----
used to write into the frames local dictionary!!) Derived classes
can change the definition of some entries, as long as they leave
! [-2:] intact (frame and previous tuple). In case an internal error is
! detected, the -3 element is used as the function name.
! [ 0] = Time that needs to be charged to the parent frame's function.
! It is used so that a function call will not have to access the
! timing data for the parent frame.
! [ 1] = Total time spent in this frame's function, excluding time in
! subfunctions
! [ 2] = Cumulative time spent in this frame's function, including time in
! all subfunctions to this frame.
! [-3] = Name of the function that corresponds to this frame.
! [-2] = Actual frame that we correspond to (used to sync exception handling)
! [-1] = Our parent 6-tuple (corresponds to frame.f_back)
Timing data for each function is stored as a 5-tuple in the dictionary
! self.timings[]. The index is always the name stored in self.cur[-3].
The following are the definitions of the members:
***************
*** 249,253 ****
def trace_dispatch_call(self, frame, t):
! if self.cur and frame.f_back is not self.cur[4]:
rt, rtt, rct, rfn, rframe, rcur = self.cur
if not isinstance(rframe, Profile.fake_frame):
--- 250,254 ----
def trace_dispatch_call(self, frame, t):
! if self.cur and frame.f_back is not self.cur[-2]:
rt, rtt, rct, rfn, rframe, rcur = self.cur
if not isinstance(rframe, Profile.fake_frame):
***************
*** 255,262 ****
print rframe, rframe.f_back
print frame, frame.f_back
! raise "Bad call", self.cur[3]
self.trace_dispatch_return(rframe, 0)
! if self.cur and frame.f_back is not self.cur[4]:
! raise "Bad call[2]", self.cur[3]
fcode = frame.f_code
fn = (fcode.co_filename, fcode.co_firstlineno, fcode.co_name)
--- 256,263 ----
print rframe, rframe.f_back
print frame, frame.f_back
! raise "Bad call", self.cur[-3]
self.trace_dispatch_return(rframe, 0)
! if self.cur and frame.f_back is not self.cur[-2]:
! raise "Bad call[2]", self.cur[-3]
fcode = frame.f_code
fn = (fcode.co_filename, fcode.co_firstlineno, fcode.co_name)
***************
*** 271,279 ****
def trace_dispatch_return(self, frame, t):
! if frame is not self.cur[4]:
! if frame is self.cur[4].f_back:
! self.trace_dispatch_return(self.cur[4], 0)
else:
! raise "Bad return", self.cur[3]
# Prefix "r" means part of the Returning or exiting frame
--- 272,280 ----
def trace_dispatch_return(self, frame, t):
! if frame is not self.cur[-2]:
! if frame is self.cur[-2].f_back:
! self.trace_dispatch_return(self.cur[-2], 0)
else:
! raise "Bad return", self.cur[-3]
# Prefix "r" means part of the Returning or exiting frame
***************
*** 318,322 ****
def set_cmd(self, cmd):
! if self.cur[5]: return # already set
self.cmd = cmd
self.simulate_call(cmd)
--- 319,323 ----
def set_cmd(self, cmd):
! if self.cur[-1]: return # already set
self.cmd = cmd
self.simulate_call(cmd)
***************
*** 340,344 ****
code = self.fake_code('profile', 0, name)
if self.cur:
! pframe = self.cur[4]
else:
pframe = None
--- 341,345 ----
code = self.fake_code('profile', 0, name)
if self.cur:
! pframe = self.cur[-2]
else:
pframe = None
***************
*** 353,360 ****
get_time = self.get_time
t = get_time() - self.t
! while self.cur[5]:
# We *can* cause assertion errors here if
# dispatch_trace_return checks for a frame match!
! a = self.dispatch['return'](self, self.cur[4], t)
t = 0
self.t = get_time() - t
--- 354,361 ----
get_time = self.get_time
t = get_time() - self.t
! while self.cur[-1]:
# We *can* cause assertion errors here if
# dispatch_trace_return checks for a frame match!
! a = self.dispatch['return'](self, self.cur[-2], t)
t = 0
self.t = get_time() - t