# This code is released into public domain.
+# Interesting parts are marked with:
+# DEBUG and beep(something)
__author__ = 'anatoly techtonik <email@example.com>'
+__license__ = 'Public Domain'
+DEBUG = False # enable to beep stuff
+ beep function does anything it wants with the message.
+ it is named so, because computers beep when they want.
+ and here it helps them to beep at interesting moments.
+ print 'beep:%s' % message
+ # feel free to monkeypatch beep for your own stuff.
+ # that's the debugging API of this module
"""container for xtrace module state"""
# [ ] check what will happen with depth when trace started deep inside and
# moved out (also check for Xdebug)
self.depth = 0 #: depth is reset on each run of start()
+ self.entrydepth = None #: stack depth at which the trace started
def function_trace_xdebug(self, frame, event, arg):
'''print function trace in default xdebug human-readable format
+ # --- handle the first event
+ if self.entrydepth == None:
+ # calculate entrypoint depth level
+ DEBUG and beep('entrydepth:%s' % self.entrydepth)
+ # [ ] make frame object a stack object, which is always
+ # inspectable, like len(stack) is an entrydepth,
+ # stack[-1] is the current frame
if event == 'call': # generated before any function call
funcname = frame.f_code.co_name
filename = self._strip_cwd(frame.f_code.co_filename)
+ # call from the root level
+ DEBUG and beep('root level call')
if funcname == '<module>':
module = inspect.getmodule(frame.f_code)