Mercurial > hg-stable
changeset 8022:4f3fdfaa3874
profiling: Adding profiling.output config variable
If specified, outputs profiling data to the said file.
Prints to stderr by default
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Wed, 08 Apr 2009 14:19:41 +0200 |
parents | 1c2cf2e5dc9b |
children | fd9debb3ea1b |
files | doc/hgrc.5.txt mercurial/dispatch.py tests/test-profile |
diffstat | 3 files changed, 35 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/hgrc.5.txt Wed Apr 08 14:18:20 2009 +0200 +++ b/doc/hgrc.5.txt Wed Apr 08 14:19:41 2009 +0200 @@ -538,6 +538,18 @@ 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.
--- a/mercurial/dispatch.py Wed Apr 08 14:18:20 2009 +0200 +++ b/mercurial/dispatch.py Wed Apr 08 14:19:41 2009 +0200 @@ -379,6 +379,15 @@ 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 @@ 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()
--- a/tests/test-profile Wed Apr 08 14:18:20 2009 +0200 +++ b/tests/test-profile Wed Apr 08 14:19:41 2009 +0200 @@ -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