diff options
| author | William Deegan <bill@baddogconsulting.com> | 2016-05-08 23:27:44 (GMT) |
|---|---|---|
| committer | William Deegan <bill@baddogconsulting.com> | 2016-05-08 23:27:44 (GMT) |
| commit | d86a8cf1f8e5aadca9bcd6b7481ab15eccc0530d (patch) | |
| tree | 521ddb1071569fa90100e11d7f03af13d5689aaf /src/engine/SCons/Debug.py | |
| parent | 98bb69c7c9e13ea57ae7e6e8db4740a4dd43ed16 (diff) | |
| parent | 6a37189174372c9c98c63ada58ab4352adf650e8 (diff) | |
| download | SCons-d86a8cf1f8e5aadca9bcd6b7481ab15eccc0530d.zip SCons-d86a8cf1f8e5aadca9bcd6b7481ab15eccc0530d.tar.gz SCons-d86a8cf1f8e5aadca9bcd6b7481ab15eccc0530d.tar.bz2 | |
merged
Diffstat (limited to 'src/engine/SCons/Debug.py')
| -rw-r--r-- | src/engine/SCons/Debug.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/engine/SCons/Debug.py b/src/engine/SCons/Debug.py index 9974039..9e520ff 100644 --- a/src/engine/SCons/Debug.py +++ b/src/engine/SCons/Debug.py @@ -1,7 +1,10 @@ """SCons.Debug Code for debugging SCons internal things. Shouldn't be -needed by most users. +needed by most users. Quick shortcuts: + +from SCons.Debug import caller_trace +caller_trace() """ @@ -34,6 +37,7 @@ import os import sys import time import weakref +import inspect # Global variable that gets set to 'True' by the Main script, # when the creation of class instances should get tracked. @@ -46,7 +50,12 @@ def logInstanceCreation(instance, name=None): name = instance.__class__.__name__ if name not in tracked_classes: tracked_classes[name] = [] - tracked_classes[name].append(weakref.ref(instance)) + if hasattr(instance, '__dict__'): + tracked_classes[name].append(weakref.ref(instance)) + else: + # weakref doesn't seem to work when the instance + # contains only slots... + tracked_classes[name].append(instance) def string_to_classes(s): if s == '*': @@ -66,7 +75,10 @@ def listLoggedInstances(classes, file=sys.stdout): for classname in string_to_classes(classes): file.write('\n%s:\n' % classname) for ref in tracked_classes[classname]: - obj = ref() + if inspect.isclass(ref): + obj = ref() + else: + obj = ref if obj is not None: file.write(' %s\n' % repr(obj)) @@ -128,8 +140,12 @@ def caller_stack(): caller_bases = {} caller_dicts = {} -# trace a caller's stack def caller_trace(back=0): + """ + Trace caller stack and save info into global dicts, which + are printed automatically at the end of SCons execution. + """ + global caller_bases, caller_dicts import traceback tb = traceback.extract_stack(limit=3+back) tb.reverse() |
