[PATCH 2 of 2] perf: add an option to profile the benchmark section
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Thu May 23 10:31:03 EDT 2019
On 5/23/19 3:14 PM, Martin von Zweigbergk wrote:
>
>
> On Wed, May 22, 2019, 07:49 Pierre-Yves David
> <pierre-yves.david at ens-lyon.org <mailto:pierre-yves.david at ens-lyon.org>>
> wrote:
>
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at octobus.net
> <mailto:pierre-yves.david at octobus.net>>
> # Date 1558445208 -7200
> # Tue May 21 15:26:48 2019 +0200
> # Node ID b5c316b4248f3add425313ac0f443c8888706b79
> # Parent 8553423d79608bd5d144456448509bdf98c6df11
> # EXP-Topic perf-profile
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> # hg pull
> https://bitbucket.org/octobus/mercurial-devel/ -r b5c316b4248f
> perf: add an option to profile the benchmark section
>
> Running a perf command with --profile gather data for the whole command
> execution, including setup and cleanup. This can significantly alter
> the data.
>
> To work around this we introduce a new option, it trigger the
> profiling of only one
> iteration of the benchmarked section.
>
> diff --git a/contrib/perf.py b/contrib/perf.py
> --- a/contrib/perf.py
> +++ b/contrib/perf.py
> @@ -18,6 +18,10 @@ Configurations
> ``pre-run``
> number of run to perform before starting measurement.
>
> +``profile-benchmark``
> + Enable profiling for the benchmarked section.
> + (The first iteration is benchmarked)
> +
> ``run-limits``
> Control the number of runs each benchmark will perform. The
> option value
> should be a list of `<time>-<numberofrun>` pairs. After each run the
> @@ -109,6 +113,10 @@ try:
> except ImportError:
> pass
>
> +try:
> + from mercurial import profiling
> +except ImportError:
> + profiling = None
>
> def identity(a):
> return a
> @@ -246,6 +254,9 @@ try:
> configitem(b'perf', b'pre-run',
> default=mercurial.configitems.dynamicdefault,
> )
> + configitem(b'perf', b'profile-benchmark',
> + default=mercurial.configitems.dynamicdefault,
> + )
> configitem(b'perf', b'run-limits',
> default=mercurial.configitems.dynamicdefault,
> )
> @@ -257,6 +268,13 @@ def getlen(ui):
> return lambda x: 1
> return len
>
> +class noop(object):
> + """dummy context manager"""
> + def __enter__(self):
> + pass
> + def __exit__(self, *args):
> + pass
> +
>
>
> Could this be replaced by util.nullcontextmanager()?
It could, but that would make the commands less compatible with older
version (who don't have `util.nullcontextmanager`), and we care about
such compatibility in perf.py
--
Pierre-Yves David
More information about the Mercurial-devel
mailing list