From: stevenknight Date: Fri, 5 Apr 2002 03:28:51 +0000 (+0000) Subject: Fix various problems with --profile (Anthony Roach) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=32626e17c2b31537b9fd2ef5c0ca60666eca9ec1;p=scons.git Fix various problems with --profile (Anthony Roach) git-svn-id: http://scons.tigris.org/svn/scons/trunk@320 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index 143fa19e..126eb6b9 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -156,6 +156,7 @@ print_dtree = 0 climb_up = 0 target_top = None exit_status = 0 # exit status, assume success by default +profiling = 0 # utility functions @@ -530,9 +531,12 @@ def options_init(): help = "Print internal environments/objects.") def opt_profile(opt, arg): - sys.argv = filter(lambda x: x[0:10] != "--profile=", sys.argv) - import profile - profile.run('SCons.Script.main()', arg) + global profiling + if not profiling: + profiling = 1 + import profile + profile.run('SCons.Script.main()', arg) + sys.exit(exit_status) Option(func = opt_profile, long = ['profile'], arg = 'FILE', diff --git a/test/option--profile.py b/test/option--profile.py index 4b8fd37b..6d7efe4b 100644 --- a/test/option--profile.py +++ b/test/option--profile.py @@ -53,5 +53,27 @@ test.fail_test(string.find(s, 'option_v') == -1) test.fail_test(string.find(s, 'SCons.Script.main()') == -1) test.fail_test(string.find(s, 'getopt.py') == -1) + +scons_prof = test.workpath('scons2.prof') + +test.run(arguments = "--profile %s -v " % scons_prof) +test.fail_test(string.find(test.stdout(), 'SCons by ') == -1) +test.fail_test(string.find(test.stdout(), 'Copyright') == -1) + +stats = pstats.Stats(scons_prof) +stats.sort_stats('time') + +sys.stdout = StringIO.StringIO() + +stats.strip_dirs().print_stats() + +s = sys.stdout.getvalue() + +test.fail_test(string.find(s, '__init__.py') == -1) +test.fail_test(string.find(s, 'option_v') == -1) +test.fail_test(string.find(s, 'SCons.Script.main()') == -1) +test.fail_test(string.find(s, 'getopt.py') == -1) + + test.pass_test()