diff options
author | Dirk Baechle <dl9obn@darc.de> | 2013-10-25 00:00:04 (GMT) |
---|---|---|
committer | Dirk Baechle <dl9obn@darc.de> | 2013-10-25 00:00:04 (GMT) |
commit | 2be0f31b80087974b5e6d53e12542637636a2253 (patch) | |
tree | 0a66e71ac007288dc76949e6169218aea00e5ad0 /src | |
parent | d48a4a49d3ad33311dcefa86377b005b06c285a7 (diff) | |
download | SCons-2be0f31b80087974b5e6d53e12542637636a2253.zip SCons-2be0f31b80087974b5e6d53e12542637636a2253.tar.gz SCons-2be0f31b80087974b5e6d53e12542637636a2253.tar.bz2 |
- now counting instances only when requested via --debug=count
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES.txt | 2 | ||||
-rw-r--r-- | src/engine/SCons/Action.py | 11 | ||||
-rw-r--r-- | src/engine/SCons/Builder.py | 7 | ||||
-rw-r--r-- | src/engine/SCons/Debug.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/Environment.py | 9 | ||||
-rw-r--r-- | src/engine/SCons/Executor.py | 5 | ||||
-rw-r--r-- | src/engine/SCons/Node/FS.py | 11 | ||||
-rw-r--r-- | src/engine/SCons/Node/__init__.py | 3 | ||||
-rw-r--r-- | src/engine/SCons/Script/Main.py | 5 |
9 files changed, 36 insertions, 21 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 50a27dc..b0d2d3c 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -30,6 +30,8 @@ RELEASE 2.3.1.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE From Dirk Baechle: - Update bootstrap.py so it can be used from any dir, to run SCons from a source (non-installed) dir. + - Count statistics of instances are now collected only when + the --debug=count command-line option is used (#2922). From Gary Oberbrunner: - Test harness: fail_test() can now print a message to help debugging. diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index c1eef75..82b8fb9 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -109,6 +109,7 @@ import re import sys import subprocess +import SCons.Debug from SCons.Debug import logInstanceCreation import SCons.Errors import SCons.Executor @@ -698,7 +699,7 @@ class CommandAction(_ActionAction): # factory above does). cmd will be passed to # Environment.subst_list() for substituting environment # variables. - if __debug__: logInstanceCreation(self, 'Action.CommandAction') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Action.CommandAction') _ActionAction.__init__(self, **kw) if is_List(cmd): @@ -855,7 +856,7 @@ class CommandAction(_ActionAction): class CommandGeneratorAction(ActionBase): """Class for command-generator actions.""" def __init__(self, generator, kw): - if __debug__: logInstanceCreation(self, 'Action.CommandGeneratorAction') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Action.CommandGeneratorAction') self.generator = generator self.gen_kw = kw self.varlist = kw.get('varlist', ()) @@ -944,7 +945,7 @@ class CommandGeneratorAction(ActionBase): class LazyAction(CommandGeneratorAction, CommandAction): def __init__(self, var, kw): - if __debug__: logInstanceCreation(self, 'Action.LazyAction') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Action.LazyAction') #FUTURE CommandAction.__init__(self, '${'+var+'}', **kw) CommandAction.__init__(self, '${'+var+'}', **kw) self.var = SCons.Util.to_String(var) @@ -986,7 +987,7 @@ class FunctionAction(_ActionAction): """Class for Python function actions.""" def __init__(self, execfunction, kw): - if __debug__: logInstanceCreation(self, 'Action.FunctionAction') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Action.FunctionAction') self.execfunction = execfunction try: @@ -1108,7 +1109,7 @@ class FunctionAction(_ActionAction): class ListAction(ActionBase): """Class for lists of other actions.""" def __init__(self, actionlist): - if __debug__: logInstanceCreation(self, 'Action.ListAction') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Action.ListAction') def list_of_actions(x): if isinstance(x, ActionBase): return x diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 6dc9e17..ed7650a 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -102,6 +102,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import collections import SCons.Action +import SCons.Debug from SCons.Debug import logInstanceCreation from SCons.Errors import InternalError, UserError import SCons.Executor @@ -225,7 +226,7 @@ class OverrideWarner(collections.UserDict): """ def __init__(self, dict): collections.UserDict.__init__(self, dict) - if __debug__: logInstanceCreation(self, 'Builder.OverrideWarner') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Builder.OverrideWarner') self.already_warned = None def warn(self): if self.already_warned: @@ -376,7 +377,7 @@ class BuilderBase(object): src_builder = None, ensure_suffix = False, **overrides): - if __debug__: logInstanceCreation(self, 'Builder.BuilderBase') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Builder.BuilderBase') self._memo = {} self.action = action self.multi = multi @@ -847,7 +848,7 @@ class CompositeBuilder(SCons.Util.Proxy): """ def __init__(self, builder, cmdgen): - if __debug__: logInstanceCreation(self, 'Builder.CompositeBuilder') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Builder.CompositeBuilder') SCons.Util.Proxy.__init__(self, builder) # cmdgen should always be an instance of DictCmdGenerator. diff --git a/src/engine/SCons/Debug.py b/src/engine/SCons/Debug.py index 1c0c638..9974039 100644 --- a/src/engine/SCons/Debug.py +++ b/src/engine/SCons/Debug.py @@ -35,6 +35,10 @@ import sys import time import weakref +# Global variable that gets set to 'True' by the Main script, +# when the creation of class instances should get tracked. +track_instances = False +# List of currently tracked classes tracked_classes = {} def logInstanceCreation(instance, name=None): diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 55a8206..ca5df58 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -43,6 +43,7 @@ from collections import UserDict import SCons.Action import SCons.Builder +import SCons.Debug from SCons.Debug import logInstanceCreation import SCons.Defaults import SCons.Errors @@ -370,7 +371,7 @@ class SubstitutionEnvironment(object): def __init__(self, **kw): """Initialization of an underlying SubstitutionEnvironment class. """ - if __debug__: logInstanceCreation(self, 'Environment.SubstitutionEnvironment') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Environment.SubstitutionEnvironment') self.fs = SCons.Node.FS.get_default_fs() self.ans = SCons.Node.Alias.default_ans self.lookup_list = SCons.Node.arg2nodes_lookups @@ -931,7 +932,7 @@ class Base(SubstitutionEnvironment): initialize things in a very specific order that doesn't work with the much simpler base class initialization. """ - if __debug__: logInstanceCreation(self, 'Environment.Base') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Environment.Base') self._memo = {} self.fs = SCons.Node.FS.get_default_fs() self.ans = SCons.Node.Alias.default_ans @@ -1414,7 +1415,7 @@ class Base(SubstitutionEnvironment): # Finally, apply any flags to be merged in if parse_flags: clone.MergeFlags(parse_flags) - if __debug__: logInstanceCreation(self, 'Environment.EnvironmentClone') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Environment.EnvironmentClone') return clone def Copy(self, *args, **kw): @@ -2270,7 +2271,7 @@ class OverrideEnvironment(Base): """ def __init__(self, subject, overrides={}): - if __debug__: logInstanceCreation(self, 'Environment.OverrideEnvironment') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Environment.OverrideEnvironment') self.__dict__['__subject'] = subject self.__dict__['overrides'] = overrides diff --git a/src/engine/SCons/Executor.py b/src/engine/SCons/Executor.py index 6f2489b..7875537 100644 --- a/src/engine/SCons/Executor.py +++ b/src/engine/SCons/Executor.py @@ -31,6 +31,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import collections +import SCons.Debug from SCons.Debug import logInstanceCreation import SCons.Errors import SCons.Memoize @@ -123,7 +124,7 @@ class Executor(object): def __init__(self, action, env=None, overridelist=[{}], targets=[], sources=[], builder_kw={}): - if __debug__: logInstanceCreation(self, 'Executor.Executor') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Executor.Executor') self.set_action_list(action) self.pre_actions = [] self.post_actions = [] @@ -575,7 +576,7 @@ class Null(object): going to worry about unit tests for this--at least for now. """ def __init__(self, *args, **kw): - if __debug__: logInstanceCreation(self, 'Executor.Null') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Executor.Null') self.batches = [Batch(kw['targets'][:], [])] def get_build_env(self): return get_NullEnvironment() diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index 4381697..18400e8 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -44,6 +44,7 @@ import time import codecs import SCons.Action +import SCons.Debug from SCons.Debug import logInstanceCreation import SCons.Errors import SCons.Memoize @@ -581,7 +582,7 @@ class Base(SCons.Node.Node): our relative and absolute paths, identify our parent directory, and indicate that this node should use signatures.""" - if __debug__: logInstanceCreation(self, 'Node.FS.Base') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Node.FS.Base') SCons.Node.Node.__init__(self) # Filenames and paths are probably reused and are intern'ed to @@ -1111,7 +1112,7 @@ class FS(LocalFS): The path argument must be a valid absolute path. """ - if __debug__: logInstanceCreation(self, 'Node.FS') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Node.FS') self._memo = {} @@ -1445,7 +1446,7 @@ class Dir(Base): BuildInfo = DirBuildInfo def __init__(self, name, directory, fs): - if __debug__: logInstanceCreation(self, 'Node.FS.Dir') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Node.FS.Dir') Base.__init__(self, name, directory, fs) self._morph() @@ -2113,7 +2114,7 @@ class RootDir(Dir): this directory. """ def __init__(self, drive, fs): - if __debug__: logInstanceCreation(self, 'Node.FS.RootDir') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Node.FS.RootDir') # We're going to be our own parent directory (".." entry and .dir # attribute) so we have to set up some values so Base.__init__() # won't gag won't it calls some of our methods. @@ -2361,7 +2362,7 @@ class File(Base): "Directory %s found where file expected.") def __init__(self, name, directory, fs): - if __debug__: logInstanceCreation(self, 'Node.FS.File') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Node.FS.File') Base.__init__(self, name, directory, fs) self._morph() diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index 992284d..c114281 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -47,6 +47,7 @@ import collections import copy from itertools import chain +import SCons.Debug from SCons.Debug import logInstanceCreation import SCons.Executor import SCons.Memoize @@ -183,7 +184,7 @@ class Node(object): pass def __init__(self): - if __debug__: logInstanceCreation(self, 'Node.Node') + if SCons.Debug.track_instances: logInstanceCreation(self, 'Node.Node') # Note that we no longer explicitly initialize a self.builder # attribute to None here. That's because the self.builder # attribute may be created on-the-fly later by a subclass (the diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index 837c103..9083b8e 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -622,7 +622,7 @@ def _set_debug_values(options): debug_values = options.debug if "count" in debug_values: - # All of the object counts are within "if __debug__:" blocks, + # All of the object counts are within "if track_instances:" blocks, # which get stripped when running optimized (with python -O or # from compiled *.pyo files). Provide a warning if __debug__ is # stripped, so it doesn't just look like --debug=count is broken. @@ -630,6 +630,7 @@ def _set_debug_values(options): if __debug__: enable_count = True if enable_count: count_stats.enable(sys.stdout) + SCons.Debug.track_instances = True else: msg = "--debug=count is not supported when running SCons\n" + \ "\twith the python -O option or optimized (.pyo) modules." @@ -644,6 +645,8 @@ def _set_debug_values(options): if "memory" in debug_values: memory_stats.enable(sys.stdout) print_objects = ("objects" in debug_values) + if print_objects: + SCons.Debug.track_instances = True if "presub" in debug_values: SCons.Action.print_actions_presub = 1 if "stacktrace" in debug_values: |