'Bad return' profiler assertion error in python 2.2, worked in <=2.1
Matthew Mueller
donut at SaPzAsMtarnet.com
Thu Jan 10 17:15:37 EST 2002
I've written a profiler helper script a while ago,
(http://www.azstarnet.com/~donut/programs/index_s.html#pyprof)
and it doesn't fully work in python2.2.
The script has 2 methods of invocation: (assuming blah.py has #! for
python2.2)
standard: pyprof [opts] blah.py
env-var: PYPROF=[opts] blah.py
The first method works in 2.2 (not suprising, since it just boils down
to a standard Profile.run call). But the second doesn't. It does do
some "magic" in order to get the profiler call stack to the right
level so that everything works out when you try to print the stats on
atexit.
The main function for type 2 looks like:
def force_profile(argv):
"""force profiling, do output at python exit
Usually this function will not be called directly, but by pyprof_auto
being imported while the PYPROF environment variable is set.
argv -- parsed by parseargs to set which output options to use
"""
try: raise Exception
except:
fr=sys.exc_info()[2].tb_frame
stacklevel=-1
while fr!=None:
stacklevel=stacklevel+1
fr=fr.f_back
# ... <registers atexit handler here, snipped to conserve space>
args,_f_profkw=parseargs(argv)
_f_prof=_f_profkw.get('Profiler',profile.Profile)()
_f_prof.set_cmd('<force_profile>')
for i in range(0,stacklevel):
_f_prof.simulate_call('<force_profile>')
sys.setprofile(_f_prof.dispatcher)
when run in python2.2, it generates:
Traceback (most recent call last):
File "/usr/lib/python2.2/site.py", line 315, in ?
import sitecustomize
File "/usr/local/lib/python2.2/site-packages/sitecustomize.py", line 1, in ?
import pyprof_auto #if PYPROF is set, profile automatically.
File "/usr/local/lib/python2.2/site-packages/pyprof_auto.py", line 30, in ?
pyprof.force_profile(os.environ['PYPROF'])
File "/usr/local/lib/python2.2/site-packages/pyprof.py", line 291, in force_profile
sys.setprofile(_f_prof.dispatcher)
File "/usr/lib/python2.2/profile.py", line 214, in trace_dispatch_i
if self.dispatch[event](self, frame,t):
File "/usr/lib/python2.2/profile.py", line 280, in trace_dispatch_return
assert frame is self.cur[-2].f_back, ("Bad return", self.cur[-3])
AssertionError: ('Bad return', ('profile', 0, '<force_profile>'))
I assume this has to do with how I'm stuffing the stack with
simulate_call, but it worked in older python and I don't see anything
obvious about how I should change it to work with 2.2..
--
Matthew Mueller
Remove S P A M to reply.
More information about the Python-list
mailing list