# HG changeset patch # User Nicolas Dumazet # Date 2009-04-08 12:19:41 # Node ID 4f3fdfaa38740ce3188f95e012888fcca9b16fa5 # Parent 1c2cf2e5dc9b99d1eb24b6a63fbd5d5effc6cd76 profiling: Adding profiling.output config variable If specified, outputs profiling data to the said file. Prints to stderr by default diff --git a/doc/hgrc.5.txt b/doc/hgrc.5.txt --- a/doc/hgrc.5.txt +++ b/doc/hgrc.5.txt @@ -538,6 +538,18 @@ paths:: Optional. Directory or URL to use when pushing if no destination is specified. +[[profiling]] +profiling:: + Specifies profiling format and file output. + In this section description, 'profiling data' stands for the raw data + collected during profiling, while 'profiling report' stands for a + statistical text report generated from the profiling data. + The profiling is done using lsprof. + output;; + File path where profiling data or report should be saved. + If the file exists, it is replaced. + Default: None, data is printed on stderr + [[server]] server:: Controls generic server settings. diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -379,6 +379,15 @@ def _runcommand(ui, options, cmd, cmdfun raise error.ParseError(cmd, _("invalid arguments")) if options['profile']: + output = ui.config('profiling', 'output') + + if output: + path = os.path.expanduser(output) + path = ui.expandpath(path) + ostream = open(path, 'wb') + else: + ostream = sys.stderr + try: from mercurial import lsprof except ImportError: @@ -393,6 +402,9 @@ def _runcommand(ui, options, cmd, cmdfun p.disable() stats = lsprof.Stats(p.getstats()) stats.sort() - stats.pprint(top=10, file=sys.stderr, climit=5) + stats.pprint(top=10, file=ostream, climit=5) + + if output: + ostream.close() else: return checkargs() diff --git a/tests/test-profile b/tests/test-profile --- a/tests/test-profile +++ b/tests/test-profile @@ -3,7 +3,16 @@ echo % test --time hg --time help -q help 2>&1 | grep Time > /dev/null || echo --time failed +hg init a +cd a + echo % test --profile if "$TESTDIR/hghave" -q lsprof; then - hg --profile help -q help 2>&1 | grep CallCount > /dev/null || echo --profile failed + hg --profile st 2>../out || echo --profile failed + grep CallCount < ../out > /dev/null || echo wrong --profile + + hg --profile --config profiling.output=../out st 2>&1 \ + || echo --profile + output to file failed + grep CallCount < ../out > /dev/null \ + || echo wrong --profile output when saving to a file fi