diff options
author | Luca Falavigna <dktrkranz@debian.org> | 2010-06-15 09:21:32 +0000 |
---|---|---|
committer | Luca Falavigna <dktrkranz@debian.org> | 2010-06-15 09:21:32 +0000 |
commit | 07fc59e19636a4fc97a18b2038f3fe1c72a94000 (patch) | |
tree | 79d4a6239d81b2ccb4752d4f5ca25e0a7d3b4d4b /engine/SCons/Debug.py | |
parent | 7f642861f3946d4241cbd668de258293ba92767a (diff) | |
parent | 340d57481935334465037d97c0db1555b70c0eb1 (diff) |
Merge commit 'upstream/2.0.0'
Diffstat (limited to 'engine/SCons/Debug.py')
-rw-r--r-- | engine/SCons/Debug.py | 63 |
1 files changed, 23 insertions, 40 deletions
diff --git a/engine/SCons/Debug.py b/engine/SCons/Debug.py index afff44b..ec7dbbd 100644 --- a/engine/SCons/Debug.py +++ b/engine/SCons/Debug.py @@ -1,7 +1,6 @@ """SCons.Debug -Code for debugging SCons internal things. Not everything here is -guaranteed to work all the way back to Python 1.5.2, and shouldn't be +Code for debugging SCons internal things. Shouldn't be needed by most users. """ @@ -29,42 +28,31 @@ needed by most users. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Debug.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Debug.py 5023 2010/06/14 22:05:46 scons" import os -import string import sys import time - -# Recipe 14.10 from the Python Cookbook. -try: - import weakref -except ImportError: - def logInstanceCreation(instance, name=None): - pass -else: - def logInstanceCreation(instance, name=None): - if name is None: - name = instance.__class__.__name__ - if not tracked_classes.has_key(name): - tracked_classes[name] = [] - tracked_classes[name].append(weakref.ref(instance)) - - +import weakref tracked_classes = {} +def logInstanceCreation(instance, name=None): + if name is None: + name = instance.__class__.__name__ + if name not in tracked_classes: + tracked_classes[name] = [] + tracked_classes[name].append(weakref.ref(instance)) + def string_to_classes(s): if s == '*': - c = tracked_classes.keys() - c.sort() - return c + return sorted(tracked_classes.keys()) else: - return string.split(s) + return s.split() def fetchLoggedInstances(classes="*"): classnames = string_to_classes(classes) - return map(lambda cn: (cn, len(tracked_classes[cn])), classnames) + return [(cn, len(tracked_classes[cn])) for cn in classnames] def countLoggedInstances(classes, file=sys.stdout): for classname in string_to_classes(classes): @@ -94,8 +82,12 @@ if sys.platform[:5] == "linux": # Linux doesn't actually support memory usage stats from getrusage(). def memory(): mstr = open('/proc/self/stat').read() - mstr = string.split(mstr)[22] + mstr = mstr.split()[22] return int(mstr) +elif sys.platform[:6] == 'darwin': + #TODO really get memory stats for OS X + def memory(): + return 0 else: try: import resource @@ -149,21 +141,15 @@ def caller_trace(back=0): # print a single caller and its callers, if any def _dump_one_caller(key, file, level=0): - l = [] - for c,v in caller_dicts[key].items(): - l.append((-v,c)) - l.sort() leader = ' '*level - for v,c in l: + for v,c in sorted([(-v,c) for c,v in caller_dicts[key].items()]): file.write("%s %6d %s:%d(%s)\n" % ((leader,-v) + func_shorten(c[-3:]))) - if caller_dicts.has_key(c): + if c in caller_dicts: _dump_one_caller(c, file, level+1) # print each call tree def dump_caller_counts(file=sys.stdout): - keys = caller_bases.keys() - keys.sort() - for k in keys: + for k in sorted(caller_bases.keys()): file.write("Callers of %s:%d(%s), %d calls:\n" % (func_shorten(k) + (caller_bases[k],))) _dump_one_caller(k, file) @@ -175,15 +161,12 @@ shorten_list = [ ] if os.sep != '/': - def platformize(t): - return (string.replace(t[0], '/', os.sep), t[1]) - shorten_list = map(platformize, shorten_list) - del platformize + shorten_list = [(t[0].replace('/', os.sep), t[1]) for t in shorten_list] def func_shorten(func_tuple): f = func_tuple[0] for t in shorten_list: - i = string.find(f, t[0]) + i = f.find(t[0]) if i >= 0: if t[1]: i = i + len(t[0]) |