[XML-SIG] Expat and the Python Profiler

Alexandre Alexandre.Fayolle@logilab.fr
Fri, 16 Aug 2002 16:32:10 +0200


Hello,

We're having problems profiling python programs using Expat. 

We traced the problem to the call_with_frame function in pyexpat.c. 

This function creates a new frame and assignes it to the thread's frame.
The profiler gets confused because this frame is neither the parent nor
grandparent frame of the current frame, and we get the following
traceback:

  Fixmlreader.IncrementalParser.parse(self,
source)lus/sax/expatreader.py", line
  File "/home/syt/lib/python2.2/site-packages/_xmlplus/sax/xmlreader.py", line
123, in parse
    self.feed(buffer)
  File "/home/syt/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py",
line 207, in feed
    self._parser.Parse(data, isFinal)
  File "/home/syt/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py",
line 283, in start_element
    def start_element(self, name, attrs):
  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 260, in trace_dispatch_call
    assert rframe.f_back is frame.f_back, ("Bad call", rfn,
AssertionError: ('Bad call', ('/home/syt/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py', 196,'feed'), <frame object at 0x815e65c>, <frame object at 0x8189fac>,<frame object at 0x819a2ac>, <frame object at 0x819af7c>)

The Frame created by pyexpat is unknown to the profiler when the
callback function is executed. 

This looks like a recent change in pyexpat  (to avoid dumping core when an 
exception is raised in a callback maybe?), but not being able to profile
code is really annoying. 

So the first question is: is this a feature of expat, or a bug in the
profiler? Do you have any suggestion?
 
Alexandre Fayolle
-- 
LOGILAB, Paris (France).
http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org
Narval, the first software agent available as free software (GPL).