From 14722c112bbce6b1a0b7676bf76111c7e3e3ea1c Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Thu, 16 Nov 2006 04:44:28 +0000 Subject: [PATCH] removed .py from compact StackTrace, added recordCreationStack --- direct/src/showbase/PythonUtil.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index cac0c7c4b4..769f4b46f1 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -128,7 +128,7 @@ class StackTrace: r = '' comma = ',' for filename, lineNum, funcName, text in self.trace: - r += '%s.%s:%s%s' % (filename[filename.rfind('\\')+1:], funcName, lineNum, comma) + r += '%s.%s:%s%s' % (filename[:filename.rfind('.py')][filename.rfind('\\')+1:], funcName, lineNum, comma) if len(r): r = r[:-len(comma)] return r @@ -2496,6 +2496,22 @@ def exceptionLogged(f): _exceptionLogged.__doc__ = f.__doc__ return _exceptionLogged +# class 'decorator' that records the stack at the time of creation +# be careful with this, it creates a StackTrace, and that can take a +# lot of CPU +def recordCreationStack(cls): + if not hasattr(cls, '__init__'): + raise 'recordCreationStack: class \'%s\' must define __init__' % cls.__name__ + cls.__moved_init__ = cls.__init__ + def __recordCreationStack_init__(self, *args, **kArgs): + self._creationStackTrace = StackTrace() + return self.__moved_init__(*args, **kArgs) + def getCreationStackTrace(self): + return self._creationStackTrace + cls.__init__ = __recordCreationStack_init__ + cls.getCreationStackTrace = getCreationStackTrace + return cls + import __builtin__ __builtin__.Functor = Functor __builtin__.Stack = Stack