contrib/benchmarks/revset.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 08 Jun 2017 01:38:48 +0100
changeset 32783 4483696dacee
parent 30406 cff0f5926797
child 43076 2372284d9457
permissions -rw-r--r--
profile: upgrade the "profile" context manager to a full class So far we have been able to use a simple decorator for this. However using the current context manager makes the scope of the profiling in dispatch constrainted and the time frame to decide to enable profiling quite limited (using "maybeprofile") This is the first step toward the ability to enable the profiling from within the profiling scope. eg:: with maybeprofiling(ui) as profiler: ... bar.foo(): ... if options['profile']: profiler.start() ... fooz() ... My target usecase is adding support for "--profile" to alias definitions with effect. These are to be used with "profiling.output=blackbox" to gather data about operation that get slow from time to time (eg: pull being minutes instead of seconds from time to time). Of course, in such case, the scope of the profiling would be smaller since profiler would be started after running extensions 'reposetup' (and other potentially costly logic), but these are not relevant for my target usecase (multiple second commits, multiple tens of seconds pull). Currently adding '--profile' to a command through alias requires to re-spin a Mercurial binary (using "!$HG" in alias), which as a significant performance impact, especially in context where startup performance is being worked on... An alternative approach would be to stop using the context manager in dispatch and move back to a try/finally setup.

# revset.py - asv revset benchmarks
#
# Copyright 2016 Logilab SA <contact@logilab.fr>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

'''ASV revset benchmarks generated from contrib/base-revsets.txt

Each revset benchmark is parameterized with variants (first, last, sort, ...)
'''

from __future__ import absolute_import

import os
import string
import sys

from . import basedir, perfbench

def createrevsetbenchmark(baseset, variants=None):
    if variants is None:
        # Default variants
        variants = ["plain", "first", "last", "sort", "sort+first",
                    "sort+last"]
    fname = "track_" + "_".join("".join([
        c if c in string.digits + string.letters else " "
        for c in baseset
    ]).split())

    def wrap(fname, baseset):
        @perfbench(name=baseset, params=[("variant", variants)])
        def f(perf, variant):
            revset = baseset
            if variant != "plain":
                for var in variant.split("+"):
                    revset = "%s(%s)" % (var, revset)
            return perf("perfrevset", revset)
        f.__name__ = fname
        return f
    return wrap(fname, baseset)

def initializerevsetbenchmarks():
    mod = sys.modules[__name__]
    with open(os.path.join(basedir, 'contrib', 'base-revsets.txt'),
              'rb') as fh:
        for line in fh:
            baseset = line.strip()
            if baseset and not baseset.startswith('#'):
                func = createrevsetbenchmark(baseset)
                setattr(mod, func.__name__, func)

initializerevsetbenchmarks()