Add a --profile=file option.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 12 Mar 2002 20:42:17 +0000 (20:42 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 12 Mar 2002 20:42:17 +0000 (20:42 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@292 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/CHANGES.txt
src/engine/SCons/Script/__init__.py
test/option--profile.py [new file with mode: 0644]

index 1991cc7763f25279b2d8b0e8e02dc9fbdd2f758e..6e4b72b4d23a44dc5ccbfc15cb8b2d6b624df6b6 100644 (file)
@@ -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
index 07465a6b8bc5f5100283760ebe4cc45adb5e8b3f..b7f1e8b3b63bc0c9666512103e0c7f97128f7362 100644 (file)
@@ -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.
index 0be6653042a7b4615ff8f8601856713e74e72b51..5472e1091d2bb4293722bf9b73bec0a085814ffa 100644 (file)
@@ -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 (file)
index 0000000..4b8fd37
--- /dev/null
@@ -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()
+