Browse Source

removed .py from compact StackTrace, added recordCreationStack

Darren Ranalli 19 years ago
parent
commit
14722c112b
1 changed files with 17 additions and 1 deletions
  1. 17 1
      direct/src/showbase/PythonUtil.py

+ 17 - 1
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