From: stevenknight Date: Tue, 12 Mar 2002 20:42:17 +0000 (+0000) Subject: Add a --profile=file option. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4f4a9b05e10f479bbde82c48e3bb60c599f72378;p=scons.git Add a --profile=file option. git-svn-id: http://scons.tigris.org/svn/scons/trunk@292 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 1991cc77..6e4b72b4 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -446,6 +446,13 @@ any out-of-date target files, but do not execute the commands. .\" scons -p -q .\" .EE +.TP +.RI --profile= file +Run SCons under the Python profile +and save the results in the specified +.IR file . +The results may be analyzed using the Python +pstats module. .TP -q, --question Do not run any commands, or print anything. Just return an exit diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 07465a6b..b7f1e8b3 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -35,6 +35,8 @@ RELEASE 0.06 - - Fixed an exception when CPPPATH or LIBPATH is a null string. (Bug reported by Richard Kiss.) + - Add a --profile=FILE option to make profiling SCons easier. + From Steve Leblanc: - Add support for the -U option. diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index 0be66530..5472e109 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -511,6 +511,15 @@ def options_init(): short = 'p', 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) + + Option(func = opt_profile, + long = ['profile'], arg = 'FILE', + help = "Profile SCons and put results in FILE.") + def opt_q(opt, arg): global task_class task_class = QuestionTask diff --git a/test/option--profile.py b/test/option--profile.py new file mode 100644 index 00000000..4b8fd37b --- /dev/null +++ b/test/option--profile.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# +# Copyright (c) 2001, 2002 Steven Knight +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import pstats +import string +import StringIO +import sys + +import TestSCons + +test = TestSCons.TestSCons() + +scons_prof = test.workpath('scons.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() +