2008-11-13 21:52:03 +03:00
|
|
|
# perf.py - performance test routines
|
2009-06-21 18:45:47 +04:00
|
|
|
'''helper extension to measure performance'''
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2016-07-05 01:25:51 +03:00
|
|
|
# "historical portability" policy of perf.py:
|
|
|
|
#
|
|
|
|
# We have to do:
|
|
|
|
# - make perf.py "loadable" with as wide Mercurial version as possible
|
|
|
|
# This doesn't mean that perf commands work correctly with that Mercurial.
|
|
|
|
# BTW, perf.py itself has been available since 1.1 (or eb240755386d).
|
|
|
|
# - make historical perf command work correctly with as wide Mercurial
|
|
|
|
# version as possible
|
|
|
|
#
|
|
|
|
# We have to do, if possible with reasonable cost:
|
|
|
|
# - make recent perf command for historical feature work correctly
|
|
|
|
# with early Mercurial
|
|
|
|
#
|
|
|
|
# We don't have to do:
|
|
|
|
# - make perf command for recent feature work correctly with early
|
|
|
|
# Mercurial
|
|
|
|
|
2016-03-16 01:42:16 +03:00
|
|
|
from __future__ import absolute_import
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
import functools
|
2017-03-14 04:16:42 +03:00
|
|
|
import gc
|
2016-03-16 01:42:16 +03:00
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
from mercurial import (
|
2016-11-06 09:41:52 +03:00
|
|
|
bdiff,
|
2016-09-24 22:22:30 +03:00
|
|
|
changegroup,
|
2016-03-16 01:42:16 +03:00
|
|
|
cmdutil,
|
|
|
|
commands,
|
|
|
|
copies,
|
|
|
|
error,
|
perf: use locally defined revlog option list for Mercurial earlier than 3.7
Before this patch, referring commands.debugrevlogopts prevents perf.py
from being loaded by Mercurial earlier than 3.7 (or 1a89336e03aa),
because it isn't available in such Mercurial, even though
cmdutil.openrevlog(), a user of these options, has been available
since 1.9 (or f32fd7cab084).
In addition to it, there are some code paths for Mercurial earlier
than 3.7. For example, setting "_prereadsize" attribute in perfindex()
and perfnodelookup() is effective only with hg earlier than 1.8 (or
1299f0c14572).
But just "using locally defined revlog option list" might cause
unexpected behavior at runtime. If --dir option is specified to
cmdutil.openrevlog() of Mercurial earlier than 3.5 (or e3ab0b30c05e),
it is silently ignored without any warning or so.
============ ============ ===== ===============
debugrevlogopts
hg version openrevlog() --dir of commands
============ ============ ===== ===============
3.7 or later o o o
3.5 or later o o x
1.9 or later o x x
earlier x x x
============ ============ ===== ===============
Therefore, this patch does:
- use locally defined option list, if commands.debugrevlogopts isn't
available (for Mercurial earlier than 3.7)
- wrap cmdutil.openrevlog(), if it is ambiguous whether
cmdutil.openrevlog() can recognize --dir option correctly
(for Mercurial earlier than 3.5)
This wrapper function aborts execution, if:
- --dir option is specified, and
- localrepository doesn't have "dirlog" attribute, which indicates
that localrepository has a function for '--dir'
BTW, extensions.wrapfunction() has been available since 1.1 (or
56ba0b824b91), and this seems old enough for "historical
portability" of perf.py, which has been available since 1.1 (or
bca5e7427e89).
2016-07-05 01:25:51 +03:00
|
|
|
extensions,
|
2016-03-16 01:42:16 +03:00
|
|
|
mdiff,
|
|
|
|
merge,
|
|
|
|
util,
|
|
|
|
)
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2016-05-20 03:47:35 +03:00
|
|
|
# for "historical portability":
|
|
|
|
# try to import modules separately (in dict order), and ignore
|
|
|
|
# failure, because these aren't available with early Mercurial
|
|
|
|
try:
|
|
|
|
from mercurial import branchmap # since 2.5 (or bcee63733aad)
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
from mercurial import obsolete # since 2.3 (or ad0d6c2b3279)
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
from mercurial import repoview # since 2.5 (or 3a6ddacb7198)
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
from mercurial import scmutil # since 1.9 (or 8b252e826c68)
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2016-07-05 01:25:51 +03:00
|
|
|
# for "historical portability":
|
|
|
|
# define util.safehasattr forcibly, because util.safehasattr has been
|
|
|
|
# available since 1.9.3 (or 94b200a11cf7)
|
|
|
|
_undefined = object()
|
|
|
|
def safehasattr(thing, attr):
|
|
|
|
return getattr(thing, attr, _undefined) is not _undefined
|
|
|
|
setattr(util, 'safehasattr', safehasattr)
|
|
|
|
|
2017-04-06 15:41:42 +03:00
|
|
|
# for "historical portability":
|
|
|
|
# define util.timer forcibly, because util.timer has been available
|
|
|
|
# since ae5d60bb70c9
|
|
|
|
if safehasattr(time, 'perf_counter'):
|
|
|
|
util.timer = time.perf_counter
|
|
|
|
elif os.name == 'nt':
|
|
|
|
util.timer = time.clock
|
|
|
|
else:
|
|
|
|
util.timer = time.time
|
|
|
|
|
2016-07-05 01:25:51 +03:00
|
|
|
# for "historical portability":
|
|
|
|
# use locally defined empty option list, if formatteropts isn't
|
|
|
|
# available, because commands.formatteropts has been available since
|
|
|
|
# 3.2 (or 7a7eed5176a4), even though formatting itself has been
|
|
|
|
# available since 2.2 (or ae5f92e154d3)
|
|
|
|
formatteropts = getattr(commands, "formatteropts", [])
|
perf: use locally defined revlog option list for Mercurial earlier than 3.7
Before this patch, referring commands.debugrevlogopts prevents perf.py
from being loaded by Mercurial earlier than 3.7 (or 1a89336e03aa),
because it isn't available in such Mercurial, even though
cmdutil.openrevlog(), a user of these options, has been available
since 1.9 (or f32fd7cab084).
In addition to it, there are some code paths for Mercurial earlier
than 3.7. For example, setting "_prereadsize" attribute in perfindex()
and perfnodelookup() is effective only with hg earlier than 1.8 (or
1299f0c14572).
But just "using locally defined revlog option list" might cause
unexpected behavior at runtime. If --dir option is specified to
cmdutil.openrevlog() of Mercurial earlier than 3.5 (or e3ab0b30c05e),
it is silently ignored without any warning or so.
============ ============ ===== ===============
debugrevlogopts
hg version openrevlog() --dir of commands
============ ============ ===== ===============
3.7 or later o o o
3.5 or later o o x
1.9 or later o x x
earlier x x x
============ ============ ===== ===============
Therefore, this patch does:
- use locally defined option list, if commands.debugrevlogopts isn't
available (for Mercurial earlier than 3.7)
- wrap cmdutil.openrevlog(), if it is ambiguous whether
cmdutil.openrevlog() can recognize --dir option correctly
(for Mercurial earlier than 3.5)
This wrapper function aborts execution, if:
- --dir option is specified, and
- localrepository doesn't have "dirlog" attribute, which indicates
that localrepository has a function for '--dir'
BTW, extensions.wrapfunction() has been available since 1.1 (or
56ba0b824b91), and this seems old enough for "historical
portability" of perf.py, which has been available since 1.1 (or
bca5e7427e89).
2016-07-05 01:25:51 +03:00
|
|
|
|
|
|
|
# for "historical portability":
|
|
|
|
# use locally defined option list, if debugrevlogopts isn't available,
|
|
|
|
# because commands.debugrevlogopts has been available since 3.7 (or
|
|
|
|
# 5606f7d0d063), even though cmdutil.openrevlog() has been available
|
|
|
|
# since 1.9 (or a79fea6b3e77).
|
|
|
|
revlogopts = getattr(commands, "debugrevlogopts", [
|
|
|
|
('c', 'changelog', False, ('open changelog')),
|
|
|
|
('m', 'manifest', False, ('open manifest')),
|
|
|
|
('', 'dir', False, ('open directory manifest')),
|
|
|
|
])
|
2015-06-10 01:18:47 +03:00
|
|
|
|
2013-01-04 22:20:51 +04:00
|
|
|
cmdtable = {}
|
2016-07-05 01:25:51 +03:00
|
|
|
|
|
|
|
# for "historical portability":
|
|
|
|
# define parsealiases locally, because cmdutil.parsealiases has been
|
|
|
|
# available since 1.5 (or 6252852b4332)
|
|
|
|
def parsealiases(cmd):
|
|
|
|
return cmd.lstrip("^").split("|")
|
|
|
|
|
|
|
|
if safehasattr(cmdutil, 'command'):
|
|
|
|
import inspect
|
|
|
|
command = cmdutil.command(cmdtable)
|
|
|
|
if 'norepo' not in inspect.getargspec(command)[0]:
|
|
|
|
# for "historical portability":
|
|
|
|
# wrap original cmdutil.command, because "norepo" option has
|
|
|
|
# been available since 3.1 (or 75a96326cecb)
|
|
|
|
_command = command
|
|
|
|
def command(name, options=(), synopsis=None, norepo=False):
|
|
|
|
if norepo:
|
|
|
|
commands.norepo += ' %s' % ' '.join(parsealiases(name))
|
|
|
|
return _command(name, list(options), synopsis)
|
|
|
|
else:
|
|
|
|
# for "historical portability":
|
|
|
|
# define "@command" annotation locally, because cmdutil.command
|
|
|
|
# has been available since 1.9 (or 2daa5179e73f)
|
|
|
|
def command(name, options=(), synopsis=None, norepo=False):
|
|
|
|
def decorator(func):
|
|
|
|
if synopsis:
|
|
|
|
cmdtable[name] = func, list(options), synopsis
|
|
|
|
else:
|
|
|
|
cmdtable[name] = func, list(options)
|
|
|
|
if norepo:
|
|
|
|
commands.norepo += ' %s' % ' '.join(parsealiases(name))
|
|
|
|
return func
|
|
|
|
return decorator
|
2013-01-04 22:20:51 +04:00
|
|
|
|
2015-12-04 22:05:32 +03:00
|
|
|
def getlen(ui):
|
|
|
|
if ui.configbool("perf", "stub"):
|
|
|
|
return lambda x: 1
|
|
|
|
return len
|
|
|
|
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
def gettimer(ui, opts=None):
|
|
|
|
"""return a timer function and formatter: (timer, formatter)
|
|
|
|
|
2015-12-04 20:41:02 +03:00
|
|
|
This function exists to gather the creation of formatter in a single
|
|
|
|
place instead of duplicating it in all performance commands."""
|
2015-01-11 06:13:10 +03:00
|
|
|
|
|
|
|
# enforce an idle period before execution to counteract power management
|
2015-07-18 22:16:36 +03:00
|
|
|
# experimental config: perf.presleep
|
perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
Before this patch, using ui.configint() prevents perf.py from
measuring performance with Mercurial earlier than 1.9 (or
12e7e9fbf243), because ui.configint() isn't available in such
Mercurial, even though there are some code paths for Mercurial earlier
than 1.9 in perf.py.
For example, setting "_prereadsize" attribute in perfindex() and
perfnodelookup() is effective only with hg earlier than 1.8 (or
1299f0c14572).
This patch replaces ui.configint() invocations by newly introduced
getint().
This patch also adds check-perf-code.py an extra check entry to detect
direct usage of ui.configint() in perf.py.
BTW, this patch doesn't choose adding configint() method at runtime by
replacing ui.__class__ like below, even though this is the recommended
way to modern Mercurial extensions.
def uisetup(ui):
if not util.safehasattr(ui, 'configint'):
class uiwrap(ui.__class__):
def configint(self, section, name, ....):
....
ui.__class__ = uiwrap
Because changes to ui.__class__ by uisetup() of loaded extension have
been propagated since 1.6.1 (or 07a6e7bd0cc1), the recommended way
above doesn't work as expected with Mercurial earlier than it.
2016-10-08 19:03:19 +03:00
|
|
|
time.sleep(getint(ui, "perf", "presleep", 1))
|
2015-01-11 06:13:10 +03:00
|
|
|
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
if opts is None:
|
|
|
|
opts = {}
|
2016-11-15 18:10:57 +03:00
|
|
|
# redirect all to stderr unless buffer api is in use
|
|
|
|
if not ui._buffers:
|
|
|
|
ui = ui.copy()
|
|
|
|
uifout = safeattrsetter(ui, 'fout', ignoremissing=True)
|
|
|
|
if uifout:
|
|
|
|
# for "historical portability":
|
|
|
|
# ui.fout/ferr have been available since 1.9 (or 4e1ccd4c2b6d)
|
|
|
|
uifout.set(ui.ferr)
|
2016-10-08 19:03:18 +03:00
|
|
|
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
# get a formatter
|
2016-10-08 19:03:18 +03:00
|
|
|
uiformatter = getattr(ui, 'formatter', None)
|
|
|
|
if uiformatter:
|
|
|
|
fm = uiformatter('perf', opts)
|
|
|
|
else:
|
|
|
|
# for "historical portability":
|
|
|
|
# define formatter locally, because ui.formatter has been
|
|
|
|
# available since 2.2 (or ae5f92e154d3)
|
|
|
|
from mercurial import node
|
|
|
|
class defaultformatter(object):
|
|
|
|
"""Minimized composition of baseformatter and plainformatter
|
|
|
|
"""
|
|
|
|
def __init__(self, ui, topic, opts):
|
|
|
|
self._ui = ui
|
|
|
|
if ui.debugflag:
|
|
|
|
self.hexfunc = node.hex
|
|
|
|
else:
|
|
|
|
self.hexfunc = node.short
|
|
|
|
def __nonzero__(self):
|
|
|
|
return False
|
2017-03-13 22:40:14 +03:00
|
|
|
__bool__ = __nonzero__
|
2016-10-08 19:03:18 +03:00
|
|
|
def startitem(self):
|
|
|
|
pass
|
|
|
|
def data(self, **data):
|
|
|
|
pass
|
|
|
|
def write(self, fields, deftext, *fielddata, **opts):
|
|
|
|
self._ui.write(deftext % fielddata, **opts)
|
|
|
|
def condwrite(self, cond, fields, deftext, *fielddata, **opts):
|
|
|
|
if cond:
|
|
|
|
self._ui.write(deftext % fielddata, **opts)
|
|
|
|
def plain(self, text, **opts):
|
|
|
|
self._ui.write(text, **opts)
|
|
|
|
def end(self):
|
|
|
|
pass
|
|
|
|
fm = defaultformatter(ui, 'perf', opts)
|
|
|
|
|
2015-12-04 20:41:30 +03:00
|
|
|
# stub function, runs code only once instead of in a loop
|
|
|
|
# experimental config: perf.stub
|
|
|
|
if ui.configbool("perf", "stub"):
|
|
|
|
return functools.partial(stub_timer, fm), fm
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
return functools.partial(_timer, fm), fm
|
|
|
|
|
2015-12-04 20:41:30 +03:00
|
|
|
def stub_timer(fm, func, title=None):
|
|
|
|
func()
|
|
|
|
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
def _timer(fm, func, title=None):
|
2017-03-14 04:16:42 +03:00
|
|
|
gc.collect()
|
2008-11-13 21:52:03 +03:00
|
|
|
results = []
|
2017-02-16 00:17:39 +03:00
|
|
|
begin = util.timer()
|
2008-11-13 21:52:03 +03:00
|
|
|
count = 0
|
2011-06-01 14:38:46 +04:00
|
|
|
while True:
|
2008-11-13 21:52:03 +03:00
|
|
|
ostart = os.times()
|
2017-02-16 00:17:39 +03:00
|
|
|
cstart = util.timer()
|
2008-11-13 21:52:03 +03:00
|
|
|
r = func()
|
2017-02-16 00:17:39 +03:00
|
|
|
cstop = util.timer()
|
2008-11-13 21:52:03 +03:00
|
|
|
ostop = os.times()
|
|
|
|
count += 1
|
|
|
|
a, b = ostart, ostop
|
|
|
|
results.append((cstop - cstart, b[0] - a[0], b[1]-a[1]))
|
|
|
|
if cstop - begin > 3 and count >= 100:
|
|
|
|
break
|
|
|
|
if cstop - begin > 10 and count >= 3:
|
|
|
|
break
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
|
|
|
|
fm.startitem()
|
|
|
|
|
2009-11-11 19:02:00 +03:00
|
|
|
if title:
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.write('title', '! %s\n', title)
|
2008-11-13 21:52:03 +03:00
|
|
|
if r:
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.write('result', '! result: %s\n', r)
|
2008-11-13 21:52:03 +03:00
|
|
|
m = min(results)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.plain('!')
|
|
|
|
fm.write('wall', ' wall %f', m[0])
|
|
|
|
fm.write('comb', ' comb %f', m[1] + m[2])
|
|
|
|
fm.write('user', ' user %f', m[1])
|
|
|
|
fm.write('sys', ' sys %f', m[2])
|
|
|
|
fm.write('count', ' (best of %d)', count)
|
|
|
|
fm.plain('\n')
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2016-10-08 19:03:16 +03:00
|
|
|
# utilities for historical portability
|
|
|
|
|
perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
Before this patch, using ui.configint() prevents perf.py from
measuring performance with Mercurial earlier than 1.9 (or
12e7e9fbf243), because ui.configint() isn't available in such
Mercurial, even though there are some code paths for Mercurial earlier
than 1.9 in perf.py.
For example, setting "_prereadsize" attribute in perfindex() and
perfnodelookup() is effective only with hg earlier than 1.8 (or
1299f0c14572).
This patch replaces ui.configint() invocations by newly introduced
getint().
This patch also adds check-perf-code.py an extra check entry to detect
direct usage of ui.configint() in perf.py.
BTW, this patch doesn't choose adding configint() method at runtime by
replacing ui.__class__ like below, even though this is the recommended
way to modern Mercurial extensions.
def uisetup(ui):
if not util.safehasattr(ui, 'configint'):
class uiwrap(ui.__class__):
def configint(self, section, name, ....):
....
ui.__class__ = uiwrap
Because changes to ui.__class__ by uisetup() of loaded extension have
been propagated since 1.6.1 (or 07a6e7bd0cc1), the recommended way
above doesn't work as expected with Mercurial earlier than it.
2016-10-08 19:03:19 +03:00
|
|
|
def getint(ui, section, name, default):
|
|
|
|
# for "historical portability":
|
|
|
|
# ui.configint has been available since 1.9 (or fa2b596db182)
|
|
|
|
v = ui.config(section, name, None)
|
|
|
|
if v is None:
|
|
|
|
return default
|
|
|
|
try:
|
|
|
|
return int(v)
|
|
|
|
except ValueError:
|
|
|
|
raise error.ConfigError(("%s.%s is not an integer ('%s')")
|
|
|
|
% (section, name, v))
|
|
|
|
|
2016-10-08 19:03:16 +03:00
|
|
|
def safeattrsetter(obj, name, ignoremissing=False):
|
|
|
|
"""Ensure that 'obj' has 'name' attribute before subsequent setattr
|
|
|
|
|
|
|
|
This function is aborted, if 'obj' doesn't have 'name' attribute
|
|
|
|
at runtime. This avoids overlooking removal of an attribute, which
|
|
|
|
breaks assumption of performance measurement, in the future.
|
|
|
|
|
|
|
|
This function returns the object to (1) assign a new value, and
|
|
|
|
(2) restore an original value to the attribute.
|
|
|
|
|
|
|
|
If 'ignoremissing' is true, missing 'name' attribute doesn't cause
|
|
|
|
abortion, and this function returns None. This is useful to
|
|
|
|
examine an attribute, which isn't ensured in all Mercurial
|
|
|
|
versions.
|
|
|
|
"""
|
|
|
|
if not util.safehasattr(obj, name):
|
|
|
|
if ignoremissing:
|
|
|
|
return None
|
|
|
|
raise error.Abort(("missing attribute %s of %s might break assumption"
|
|
|
|
" of performance measurement") % (name, obj))
|
|
|
|
|
|
|
|
origvalue = getattr(obj, name)
|
|
|
|
class attrutil(object):
|
|
|
|
def set(self, newvalue):
|
|
|
|
setattr(obj, name, newvalue)
|
|
|
|
def restore(self):
|
|
|
|
setattr(obj, name, origvalue)
|
|
|
|
|
|
|
|
return attrutil()
|
|
|
|
|
2016-10-08 19:03:17 +03:00
|
|
|
# utilities to examine each internal API changes
|
|
|
|
|
|
|
|
def getbranchmapsubsettable():
|
|
|
|
# for "historical portability":
|
|
|
|
# subsettable is defined in:
|
|
|
|
# - branchmap since 2.9 (or 175c6fd8cacc)
|
|
|
|
# - repoview since 2.5 (or 59a9f18d4587)
|
|
|
|
for mod in (branchmap, repoview):
|
|
|
|
subsettable = getattr(mod, 'subsettable', None)
|
|
|
|
if subsettable:
|
|
|
|
return subsettable
|
|
|
|
|
|
|
|
# bisecting in bcee63733aad::59a9f18d4587 can reach here (both
|
|
|
|
# branchmap and repoview modules exist, but subsettable attribute
|
|
|
|
# doesn't)
|
|
|
|
raise error.Abort(("perfbranchmap not available with this Mercurial"),
|
|
|
|
hint="use 2.5 or later")
|
|
|
|
|
2016-10-08 19:03:18 +03:00
|
|
|
def getsvfs(repo):
|
|
|
|
"""Return appropriate object to access files under .hg/store
|
|
|
|
"""
|
|
|
|
# for "historical portability":
|
|
|
|
# repo.svfs has been available since 2.3 (or 7034365089bf)
|
|
|
|
svfs = getattr(repo, 'svfs', None)
|
|
|
|
if svfs:
|
|
|
|
return svfs
|
|
|
|
else:
|
|
|
|
return getattr(repo, 'sopener')
|
|
|
|
|
|
|
|
def getvfs(repo):
|
|
|
|
"""Return appropriate object to access files under .hg
|
|
|
|
"""
|
|
|
|
# for "historical portability":
|
|
|
|
# repo.vfs has been available since 2.3 (or 7034365089bf)
|
|
|
|
vfs = getattr(repo, 'vfs', None)
|
|
|
|
if vfs:
|
|
|
|
return vfs
|
|
|
|
else:
|
|
|
|
return getattr(repo, 'opener')
|
|
|
|
|
perf: make perftags clear tags cache correctly
Before this patch, "hg perftags" command doesn't measure performance
of "repo.tags()" correctly, because it doesn't clear tags cache
correctly.
a043ed82a5cd replaced repo._tags with repo._tagscache, but didn't
change the code path to clear tags cache in perftags() at that time.
BTW, full history of "tags cache" is:
- b8d757d45f24 (or 0.6) introduced repo.tagscache as the first "tags cache"
- 4cbf51c74e8c (or 1.4) replaced repo.tagscache with repo._tags
- a043ed82a5cd (or 2.0) replaced repo._tags with repo._tagscache
- 04c204f1ed65 (or 2.5) made repo._tagscache filteredpropertycache
To make perftags clear tags cache correctly, and to increase
"historical portability" of perftags, this patch examines existence of
attributes in repo object, and guess appropriate procedure to clear
tags cache.
To avoid examining existence of attributes at each repetition, this
patch makes repocleartagscachefunc() return the function, which
actually clears tags cache.
mozilla-central repo (85 tags on 308365 revs) with each Mercurial
version between before and after this patch.
==== ========= =========
ver before after
==== ========= =========
1.9 0.476062 0.466464
------- *1 -------
2.0 0.346309 0.458327
2.1 0.343106 0.454489
------- *2 -------
2.2 0.069790 0.071263
2.3 0.067829 0.069340
2.4 0.068075 0.069573
------- *3 -------
2.5 0.021896 0.022406
2.6 0.021900 0.022374
2.7 0.021883 0.022379
2.8 0.021949 0.022327
2.9 0.021877 0.022330
3.0 0.021860 0.022314
3.1 0.021869 0.022669
3.2 0.021831 0.022668
3.3 0.021809 0.022691
3.4 0.021861 0.022916
3.5 0.019335 0.020749
3.6 0.019319 0.020866
3.7 0.018781 0.020251
------- *4 -------
3.8 0.068262 0.072558
3.9 0.069682 0.073773
==== ========= =========
(*1) repo._tags was replaced with repo._tagscache at this point
"repo._tags = None" in perftags "before" this patch doesn't clear
tags cache for Mercurial 2.0 or later. This causes significant
gap of "before" between 1.9 and 2.0 .
(*2) I'm not sure about significant gap at this point, but release
note of 2.2 described "a number of significant performance
improvements for large repositories"
(*3) filtered changelog was cached in repoview as repoview.changelog
at this point (by 131b01a4654d)
This avoids calculation of filtered changelog at each repetition
of t().
(*4) calculation of filtered changelog was included into wall time at
this point (by adf01efe43a5), again
See below for detail about this significant gap:
https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-April/083410.html
2016-10-08 19:03:20 +03:00
|
|
|
def repocleartagscachefunc(repo):
|
|
|
|
"""Return the function to clear tags cache according to repo internal API
|
|
|
|
"""
|
|
|
|
if util.safehasattr(repo, '_tagscache'): # since 2.0 (or 9dca7653b525)
|
|
|
|
# in this case, setattr(repo, '_tagscache', None) or so isn't
|
|
|
|
# correct way to clear tags cache, because existing code paths
|
|
|
|
# expect _tagscache to be a structured object.
|
|
|
|
def clearcache():
|
|
|
|
# _tagscache has been filteredpropertycache since 2.5 (or
|
|
|
|
# 98c867ac1330), and delattr() can't work in such case
|
|
|
|
if '_tagscache' in vars(repo):
|
|
|
|
del repo.__dict__['_tagscache']
|
|
|
|
return clearcache
|
|
|
|
|
|
|
|
repotags = safeattrsetter(repo, '_tags', ignoremissing=True)
|
|
|
|
if repotags: # since 1.4 (or 5614a628d173)
|
|
|
|
return lambda : repotags.set(None)
|
|
|
|
|
|
|
|
repotagscache = safeattrsetter(repo, 'tagscache', ignoremissing=True)
|
|
|
|
if repotagscache: # since 0.6 (or d7df759d0e97)
|
|
|
|
return lambda : repotagscache.set(None)
|
|
|
|
|
|
|
|
# Mercurial earlier than 0.6 (or d7df759d0e97) logically reaches
|
|
|
|
# this point, but it isn't so problematic, because:
|
|
|
|
# - repo.tags of such Mercurial isn't "callable", and repo.tags()
|
|
|
|
# in perftags() causes failure soon
|
|
|
|
# - perf.py itself has been available since 1.1 (or eb240755386d)
|
|
|
|
raise error.Abort(("tags API of this hg command is unknown"))
|
|
|
|
|
2016-10-08 19:03:16 +03:00
|
|
|
# perf commands
|
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfwalk', formatteropts)
|
|
|
|
def perfwalk(ui, repo, *pats, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2008-11-13 21:52:03 +03:00
|
|
|
try:
|
2011-06-19 01:52:51 +04:00
|
|
|
m = scmutil.match(repo[None], pats, {})
|
2010-01-01 02:19:30 +03:00
|
|
|
timer(lambda: len(list(repo.dirstate.walk(m, [], True, False))))
|
2012-05-12 18:02:46 +04:00
|
|
|
except Exception:
|
2008-11-13 21:52:03 +03:00
|
|
|
try:
|
2011-06-19 01:52:51 +04:00
|
|
|
m = scmutil.match(repo[None], pats, {})
|
2010-01-25 09:05:27 +03:00
|
|
|
timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)]))
|
2012-05-12 18:02:46 +04:00
|
|
|
except Exception:
|
2008-11-13 21:52:03 +03:00
|
|
|
timer(lambda: len(list(cmdutil.walk(repo, pats, {}))))
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfannotate', formatteropts)
|
|
|
|
def perfannotate(ui, repo, f, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2013-05-31 06:29:03 +04:00
|
|
|
fc = repo['.'][f]
|
|
|
|
timer(lambda: len(fc.annotate(True)))
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2013-05-31 06:29:03 +04:00
|
|
|
|
2013-01-04 22:20:51 +04:00
|
|
|
@command('perfstatus',
|
|
|
|
[('u', 'unknown', False,
|
2015-06-10 01:18:47 +03:00
|
|
|
'ask status to look for unknown files')] + formatteropts)
|
2012-12-04 01:53:53 +04:00
|
|
|
def perfstatus(ui, repo, **opts):
|
2008-11-13 21:52:03 +03:00
|
|
|
#m = match.always(repo.root, repo.getcwd())
|
2012-05-12 17:54:54 +04:00
|
|
|
#timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False,
|
|
|
|
# False))))
|
2015-11-20 00:02:27 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2015-06-10 01:18:47 +03:00
|
|
|
timer(lambda: sum(map(len, repo.status(unknown=opts['unknown']))))
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfaddremove', formatteropts)
|
|
|
|
def perfaddremove(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2013-04-02 10:09:36 +04:00
|
|
|
try:
|
|
|
|
oldquiet = repo.ui.quiet
|
|
|
|
repo.ui.quiet = True
|
2014-11-10 03:57:02 +03:00
|
|
|
matcher = scmutil.match(repo[None])
|
2014-11-25 06:27:49 +03:00
|
|
|
timer(lambda: scmutil.addremove(repo, matcher, "", dry_run=True))
|
2013-04-02 10:09:36 +04:00
|
|
|
finally:
|
|
|
|
repo.ui.quiet = oldquiet
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2013-04-02 10:09:36 +04:00
|
|
|
|
2012-05-20 06:44:23 +04:00
|
|
|
def clearcaches(cl):
|
|
|
|
# behave somewhat consistently across internal API changes
|
|
|
|
if util.safehasattr(cl, 'clearcaches'):
|
|
|
|
cl.clearcaches()
|
|
|
|
elif util.safehasattr(cl, '_nodecache'):
|
|
|
|
from mercurial.node import nullid, nullrev
|
|
|
|
cl._nodecache = {nullid: nullrev}
|
|
|
|
cl._nodepos = None
|
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfheads', formatteropts)
|
|
|
|
def perfheads(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-05-20 06:44:23 +04:00
|
|
|
cl = repo.changelog
|
|
|
|
def d():
|
|
|
|
len(cl.headrevs())
|
|
|
|
clearcaches(cl)
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perftags', formatteropts)
|
|
|
|
def perftags(ui, repo, **opts):
|
2013-09-20 18:14:59 +04:00
|
|
|
import mercurial.changelog
|
|
|
|
import mercurial.manifest
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2016-10-08 19:03:18 +03:00
|
|
|
svfs = getsvfs(repo)
|
perf: make perftags clear tags cache correctly
Before this patch, "hg perftags" command doesn't measure performance
of "repo.tags()" correctly, because it doesn't clear tags cache
correctly.
a043ed82a5cd replaced repo._tags with repo._tagscache, but didn't
change the code path to clear tags cache in perftags() at that time.
BTW, full history of "tags cache" is:
- b8d757d45f24 (or 0.6) introduced repo.tagscache as the first "tags cache"
- 4cbf51c74e8c (or 1.4) replaced repo.tagscache with repo._tags
- a043ed82a5cd (or 2.0) replaced repo._tags with repo._tagscache
- 04c204f1ed65 (or 2.5) made repo._tagscache filteredpropertycache
To make perftags clear tags cache correctly, and to increase
"historical portability" of perftags, this patch examines existence of
attributes in repo object, and guess appropriate procedure to clear
tags cache.
To avoid examining existence of attributes at each repetition, this
patch makes repocleartagscachefunc() return the function, which
actually clears tags cache.
mozilla-central repo (85 tags on 308365 revs) with each Mercurial
version between before and after this patch.
==== ========= =========
ver before after
==== ========= =========
1.9 0.476062 0.466464
------- *1 -------
2.0 0.346309 0.458327
2.1 0.343106 0.454489
------- *2 -------
2.2 0.069790 0.071263
2.3 0.067829 0.069340
2.4 0.068075 0.069573
------- *3 -------
2.5 0.021896 0.022406
2.6 0.021900 0.022374
2.7 0.021883 0.022379
2.8 0.021949 0.022327
2.9 0.021877 0.022330
3.0 0.021860 0.022314
3.1 0.021869 0.022669
3.2 0.021831 0.022668
3.3 0.021809 0.022691
3.4 0.021861 0.022916
3.5 0.019335 0.020749
3.6 0.019319 0.020866
3.7 0.018781 0.020251
------- *4 -------
3.8 0.068262 0.072558
3.9 0.069682 0.073773
==== ========= =========
(*1) repo._tags was replaced with repo._tagscache at this point
"repo._tags = None" in perftags "before" this patch doesn't clear
tags cache for Mercurial 2.0 or later. This causes significant
gap of "before" between 1.9 and 2.0 .
(*2) I'm not sure about significant gap at this point, but release
note of 2.2 described "a number of significant performance
improvements for large repositories"
(*3) filtered changelog was cached in repoview as repoview.changelog
at this point (by 131b01a4654d)
This avoids calculation of filtered changelog at each repetition
of t().
(*4) calculation of filtered changelog was included into wall time at
this point (by adf01efe43a5), again
See below for detail about this significant gap:
https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-April/083410.html
2016-10-08 19:03:20 +03:00
|
|
|
repocleartagscache = repocleartagscachefunc(repo)
|
2008-11-13 21:52:03 +03:00
|
|
|
def t():
|
2016-10-08 19:03:18 +03:00
|
|
|
repo.changelog = mercurial.changelog.changelog(svfs)
|
2016-10-19 03:33:39 +03:00
|
|
|
repo.manifestlog = mercurial.manifest.manifestlog(svfs, repo)
|
perf: make perftags clear tags cache correctly
Before this patch, "hg perftags" command doesn't measure performance
of "repo.tags()" correctly, because it doesn't clear tags cache
correctly.
a043ed82a5cd replaced repo._tags with repo._tagscache, but didn't
change the code path to clear tags cache in perftags() at that time.
BTW, full history of "tags cache" is:
- b8d757d45f24 (or 0.6) introduced repo.tagscache as the first "tags cache"
- 4cbf51c74e8c (or 1.4) replaced repo.tagscache with repo._tags
- a043ed82a5cd (or 2.0) replaced repo._tags with repo._tagscache
- 04c204f1ed65 (or 2.5) made repo._tagscache filteredpropertycache
To make perftags clear tags cache correctly, and to increase
"historical portability" of perftags, this patch examines existence of
attributes in repo object, and guess appropriate procedure to clear
tags cache.
To avoid examining existence of attributes at each repetition, this
patch makes repocleartagscachefunc() return the function, which
actually clears tags cache.
mozilla-central repo (85 tags on 308365 revs) with each Mercurial
version between before and after this patch.
==== ========= =========
ver before after
==== ========= =========
1.9 0.476062 0.466464
------- *1 -------
2.0 0.346309 0.458327
2.1 0.343106 0.454489
------- *2 -------
2.2 0.069790 0.071263
2.3 0.067829 0.069340
2.4 0.068075 0.069573
------- *3 -------
2.5 0.021896 0.022406
2.6 0.021900 0.022374
2.7 0.021883 0.022379
2.8 0.021949 0.022327
2.9 0.021877 0.022330
3.0 0.021860 0.022314
3.1 0.021869 0.022669
3.2 0.021831 0.022668
3.3 0.021809 0.022691
3.4 0.021861 0.022916
3.5 0.019335 0.020749
3.6 0.019319 0.020866
3.7 0.018781 0.020251
------- *4 -------
3.8 0.068262 0.072558
3.9 0.069682 0.073773
==== ========= =========
(*1) repo._tags was replaced with repo._tagscache at this point
"repo._tags = None" in perftags "before" this patch doesn't clear
tags cache for Mercurial 2.0 or later. This causes significant
gap of "before" between 1.9 and 2.0 .
(*2) I'm not sure about significant gap at this point, but release
note of 2.2 described "a number of significant performance
improvements for large repositories"
(*3) filtered changelog was cached in repoview as repoview.changelog
at this point (by 131b01a4654d)
This avoids calculation of filtered changelog at each repetition
of t().
(*4) calculation of filtered changelog was included into wall time at
this point (by adf01efe43a5), again
See below for detail about this significant gap:
https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-April/083410.html
2016-10-08 19:03:20 +03:00
|
|
|
repocleartagscache()
|
2008-11-13 21:52:03 +03:00
|
|
|
return len(repo.tags())
|
|
|
|
timer(t)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfancestors', formatteropts)
|
|
|
|
def perfancestors(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-05-15 21:44:17 +04:00
|
|
|
heads = repo.changelog.headrevs()
|
|
|
|
def d():
|
2012-06-01 23:37:18 +04:00
|
|
|
for a in repo.changelog.ancestors(heads):
|
2012-05-15 21:44:17 +04:00
|
|
|
pass
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2012-05-15 21:44:17 +04:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfancestorset', formatteropts)
|
|
|
|
def perfancestorset(ui, repo, revset, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-12-14 22:23:18 +04:00
|
|
|
revs = repo.revs(revset)
|
|
|
|
heads = repo.changelog.headrevs()
|
|
|
|
def d():
|
2012-12-19 00:47:20 +04:00
|
|
|
s = repo.changelog.ancestors(heads)
|
2012-12-14 22:23:18 +04:00
|
|
|
for rev in revs:
|
|
|
|
rev in s
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2012-12-14 22:23:18 +04:00
|
|
|
|
2016-09-24 22:22:30 +03:00
|
|
|
@command('perfchangegroupchangelog', formatteropts +
|
|
|
|
[('', 'version', '02', 'changegroup version'),
|
|
|
|
('r', 'rev', '', 'revisions to add to changegroup')])
|
|
|
|
def perfchangegroupchangelog(ui, repo, version='02', rev=None, **opts):
|
|
|
|
"""Benchmark producing a changelog group for a changegroup.
|
|
|
|
|
|
|
|
This measures the time spent processing the changelog during a
|
|
|
|
bundle operation. This occurs during `hg bundle` and on a server
|
|
|
|
processing a `getbundle` wire protocol request (handles clones
|
|
|
|
and pull requests).
|
|
|
|
|
|
|
|
By default, all revisions are added to the changegroup.
|
|
|
|
"""
|
|
|
|
cl = repo.changelog
|
|
|
|
revs = [cl.lookup(r) for r in repo.revs(rev or 'all()')]
|
|
|
|
bundler = changegroup.getbundler(version, repo)
|
|
|
|
|
|
|
|
def lookup(node):
|
|
|
|
# The real bundler reads the revision in order to access the
|
|
|
|
# manifest node and files list. Do that here.
|
|
|
|
cl.read(node)
|
|
|
|
return node
|
|
|
|
|
|
|
|
def d():
|
|
|
|
for chunk in bundler.group(revs, cl, lookup):
|
|
|
|
pass
|
|
|
|
|
|
|
|
timer, fm = gettimer(ui, opts)
|
|
|
|
timer(d)
|
|
|
|
fm.end()
|
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfdirs', formatteropts)
|
|
|
|
def perfdirs(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2013-04-02 00:46:32 +04:00
|
|
|
dirstate = repo.dirstate
|
|
|
|
'a' in dirstate
|
|
|
|
def d():
|
|
|
|
dirstate.dirs()
|
|
|
|
del dirstate._dirs
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2013-04-02 00:46:32 +04:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfdirstate', formatteropts)
|
|
|
|
def perfdirstate(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2008-11-13 21:52:03 +03:00
|
|
|
"a" in repo.dirstate
|
|
|
|
def d():
|
|
|
|
repo.dirstate.invalidate()
|
|
|
|
"a" in repo.dirstate
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfdirstatedirs', formatteropts)
|
|
|
|
def perfdirstatedirs(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2008-11-13 21:52:03 +03:00
|
|
|
"a" in repo.dirstate
|
|
|
|
def d():
|
|
|
|
"a" in repo.dirstate._dirs
|
|
|
|
del repo.dirstate._dirs
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfdirstatefoldmap', formatteropts)
|
2015-11-24 23:08:21 +03:00
|
|
|
def perfdirstatefoldmap(ui, repo, **opts):
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2014-10-04 06:58:26 +04:00
|
|
|
dirstate = repo.dirstate
|
|
|
|
'a' in dirstate
|
|
|
|
def d():
|
2015-04-03 05:13:50 +03:00
|
|
|
dirstate._filefoldmap.get('a')
|
|
|
|
del dirstate._filefoldmap
|
|
|
|
timer(d)
|
|
|
|
fm.end()
|
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfdirfoldmap', formatteropts)
|
|
|
|
def perfdirfoldmap(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2015-04-03 05:13:50 +03:00
|
|
|
dirstate = repo.dirstate
|
|
|
|
'a' in dirstate
|
|
|
|
def d():
|
|
|
|
dirstate._dirfoldmap.get('a')
|
|
|
|
del dirstate._dirfoldmap
|
2014-10-04 06:58:26 +04:00
|
|
|
del dirstate._dirs
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2014-10-04 06:58:26 +04:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfdirstatewrite', formatteropts)
|
|
|
|
def perfdirstatewrite(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-05-17 00:45:46 +04:00
|
|
|
ds = repo.dirstate
|
|
|
|
"a" in ds
|
|
|
|
def d():
|
|
|
|
ds._dirty = True
|
2015-10-16 19:15:34 +03:00
|
|
|
ds.write(repo.currenttransaction())
|
2012-05-17 00:45:46 +04:00
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2012-05-17 00:45:46 +04:00
|
|
|
|
2013-03-25 04:06:10 +04:00
|
|
|
@command('perfmergecalculate',
|
2015-06-10 01:18:47 +03:00
|
|
|
[('r', 'rev', '.', 'rev to merge against')] + formatteropts)
|
|
|
|
def perfmergecalculate(ui, repo, rev, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2013-03-25 04:06:10 +04:00
|
|
|
wctx = repo[None]
|
|
|
|
rctx = scmutil.revsingle(repo, rev, rev)
|
|
|
|
ancestor = wctx.ancestor(rctx)
|
|
|
|
# we don't want working dir files to be stat'd in the benchmark, so prime
|
|
|
|
# that cache
|
|
|
|
wctx.dirty()
|
|
|
|
def d():
|
|
|
|
# acceptremote is True because we don't want prompts in the middle of
|
|
|
|
# our benchmark
|
2015-11-25 00:44:16 +03:00
|
|
|
merge.calculateupdates(repo, wctx, rctx, [ancestor], False, False,
|
2015-12-15 04:37:41 +03:00
|
|
|
acceptremote=True, followcopies=True)
|
2013-03-25 04:06:10 +04:00
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2013-03-25 04:06:10 +04:00
|
|
|
|
2013-04-05 07:36:46 +04:00
|
|
|
@command('perfpathcopies', [], "REV REV")
|
2015-06-10 01:18:47 +03:00
|
|
|
def perfpathcopies(ui, repo, rev1, rev2, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2013-04-05 07:36:46 +04:00
|
|
|
ctx1 = scmutil.revsingle(repo, rev1, rev1)
|
|
|
|
ctx2 = scmutil.revsingle(repo, rev2, rev2)
|
|
|
|
def d():
|
|
|
|
copies.pathcopies(ctx1, ctx2)
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2013-04-05 07:36:46 +04:00
|
|
|
|
2013-09-07 00:35:29 +04:00
|
|
|
@command('perfmanifest', [], 'REV')
|
2015-06-10 01:18:47 +03:00
|
|
|
def perfmanifest(ui, repo, rev, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2013-09-07 00:35:29 +04:00
|
|
|
ctx = scmutil.revsingle(repo, rev, rev)
|
|
|
|
t = ctx.manifestnode()
|
2008-11-13 21:52:03 +03:00
|
|
|
def d():
|
2016-11-10 13:13:19 +03:00
|
|
|
repo.manifestlog.clearcaches()
|
2016-11-10 13:13:19 +03:00
|
|
|
repo.manifestlog[t].read()
|
2008-11-13 21:52:03 +03:00
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfchangeset', formatteropts)
|
|
|
|
def perfchangeset(ui, repo, rev, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-03-16 00:58:55 +04:00
|
|
|
n = repo[rev].node()
|
|
|
|
def d():
|
2013-07-01 22:48:56 +04:00
|
|
|
repo.changelog.read(n)
|
2012-03-17 04:58:47 +04:00
|
|
|
#repo.changelog._cache = None
|
2012-03-16 00:58:55 +04:00
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2012-03-16 00:58:55 +04:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfindex', formatteropts)
|
|
|
|
def perfindex(ui, repo, **opts):
|
2011-01-12 02:01:14 +03:00
|
|
|
import mercurial.revlog
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2011-01-19 00:55:49 +03:00
|
|
|
mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
|
2011-01-12 02:01:04 +03:00
|
|
|
n = repo["tip"].node()
|
2016-10-08 19:03:18 +03:00
|
|
|
svfs = getsvfs(repo)
|
2008-11-13 21:52:03 +03:00
|
|
|
def d():
|
2016-10-08 19:03:18 +03:00
|
|
|
cl = mercurial.revlog.revlog(svfs, "00changelog.i")
|
2012-03-15 22:11:03 +04:00
|
|
|
cl.rev(n)
|
2008-11-13 21:52:03 +03:00
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfstartup', formatteropts)
|
|
|
|
def perfstartup(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2008-11-13 21:52:03 +03:00
|
|
|
cmd = sys.argv[0]
|
|
|
|
def d():
|
2015-12-14 02:13:44 +03:00
|
|
|
if os.name != 'nt':
|
|
|
|
os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
|
|
|
|
else:
|
|
|
|
os.environ['HGRCPATH'] = ''
|
|
|
|
os.system("%s version -q > NUL" % cmd)
|
2008-11-13 21:52:03 +03:00
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfparents', formatteropts)
|
|
|
|
def perfparents(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2015-12-04 21:18:07 +03:00
|
|
|
# control the number of commits perfparents iterates over
|
|
|
|
# experimental config: perf.parentscount
|
perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
Before this patch, using ui.configint() prevents perf.py from
measuring performance with Mercurial earlier than 1.9 (or
12e7e9fbf243), because ui.configint() isn't available in such
Mercurial, even though there are some code paths for Mercurial earlier
than 1.9 in perf.py.
For example, setting "_prereadsize" attribute in perfindex() and
perfnodelookup() is effective only with hg earlier than 1.8 (or
1299f0c14572).
This patch replaces ui.configint() invocations by newly introduced
getint().
This patch also adds check-perf-code.py an extra check entry to detect
direct usage of ui.configint() in perf.py.
BTW, this patch doesn't choose adding configint() method at runtime by
replacing ui.__class__ like below, even though this is the recommended
way to modern Mercurial extensions.
def uisetup(ui):
if not util.safehasattr(ui, 'configint'):
class uiwrap(ui.__class__):
def configint(self, section, name, ....):
....
ui.__class__ = uiwrap
Because changes to ui.__class__ by uisetup() of loaded extension have
been propagated since 1.6.1 (or 07a6e7bd0cc1), the recommended way
above doesn't work as expected with Mercurial earlier than it.
2016-10-08 19:03:19 +03:00
|
|
|
count = getint(ui, "perf", "parentscount", 1000)
|
2015-12-04 21:18:07 +03:00
|
|
|
if len(repo.changelog) < count:
|
|
|
|
raise error.Abort("repo needs %d commits for this test" % count)
|
2015-11-25 00:36:20 +03:00
|
|
|
repo = repo.unfiltered()
|
2015-12-04 21:18:07 +03:00
|
|
|
nl = [repo.changelog.node(i) for i in xrange(count)]
|
2008-11-13 21:52:03 +03:00
|
|
|
def d():
|
|
|
|
for n in nl:
|
|
|
|
repo.changelog.parents(n)
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfctxfiles', formatteropts)
|
2015-11-24 23:08:21 +03:00
|
|
|
def perfctxfiles(ui, repo, x, **opts):
|
2015-03-18 20:03:44 +03:00
|
|
|
x = int(x)
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2015-03-18 20:03:44 +03:00
|
|
|
def d():
|
|
|
|
len(repo[x].files())
|
|
|
|
timer(d)
|
|
|
|
fm.end()
|
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfrawfiles', formatteropts)
|
2015-11-24 23:08:21 +03:00
|
|
|
def perfrawfiles(ui, repo, x, **opts):
|
2015-03-18 20:03:44 +03:00
|
|
|
x = int(x)
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2015-03-18 20:03:44 +03:00
|
|
|
cl = repo.changelog
|
|
|
|
def d():
|
|
|
|
len(cl.read(x)[3])
|
|
|
|
timer(d)
|
|
|
|
fm.end()
|
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perflookup', formatteropts)
|
|
|
|
def perflookup(ui, repo, rev, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2008-11-13 21:52:03 +03:00
|
|
|
timer(lambda: len(repo.lookup(rev)))
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2008-11-13 21:52:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfrevrange', formatteropts)
|
|
|
|
def perfrevrange(ui, repo, *specs, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-06-02 02:50:22 +04:00
|
|
|
revrange = scmutil.revrange
|
|
|
|
timer(lambda: len(revrange(repo, specs)))
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2012-06-02 02:50:22 +04:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfnodelookup', formatteropts)
|
|
|
|
def perfnodelookup(ui, repo, rev, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-04-13 01:05:59 +04:00
|
|
|
import mercurial.revlog
|
|
|
|
mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
|
|
|
|
n = repo[rev].node()
|
2016-10-08 19:03:18 +03:00
|
|
|
cl = mercurial.revlog.revlog(getsvfs(repo), "00changelog.i")
|
2012-04-13 01:05:59 +04:00
|
|
|
def d():
|
|
|
|
cl.rev(n)
|
2012-05-20 06:44:23 +04:00
|
|
|
clearcaches(cl)
|
2012-04-13 01:05:59 +04:00
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2012-04-13 01:05:59 +04:00
|
|
|
|
2013-01-04 22:20:51 +04:00
|
|
|
@command('perflog',
|
2015-06-10 01:18:47 +03:00
|
|
|
[('', 'rename', False, 'ask log to follow renames')] + formatteropts)
|
2015-12-04 21:08:50 +03:00
|
|
|
def perflog(ui, repo, rev=None, **opts):
|
|
|
|
if rev is None:
|
|
|
|
rev=[]
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2009-03-23 15:12:03 +03:00
|
|
|
ui.pushbuffer()
|
2015-12-04 21:08:50 +03:00
|
|
|
timer(lambda: commands.log(ui, repo, rev=rev, date='', user='',
|
2009-11-25 01:02:02 +03:00
|
|
|
copies=opts.get('rename')))
|
2009-03-23 15:12:03 +03:00
|
|
|
ui.popbuffer()
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2009-03-23 15:12:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfmoonwalk', formatteropts)
|
|
|
|
def perfmoonwalk(ui, repo, **opts):
|
2013-11-18 03:04:28 +04:00
|
|
|
"""benchmark walking the changelog backwards
|
|
|
|
|
|
|
|
This also loads the changelog data for each revision in the changelog.
|
|
|
|
"""
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2013-11-18 03:04:28 +04:00
|
|
|
def moonwalk():
|
|
|
|
for i in xrange(len(repo), -1, -1):
|
|
|
|
ctx = repo[i]
|
|
|
|
ctx.branch() # read changelog data (in addition to the index)
|
|
|
|
timer(moonwalk)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2013-11-18 03:04:28 +04:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perftemplating', formatteropts)
|
2015-12-04 21:08:50 +03:00
|
|
|
def perftemplating(ui, repo, rev=None, **opts):
|
|
|
|
if rev is None:
|
|
|
|
rev=[]
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2009-03-23 15:12:03 +03:00
|
|
|
ui.pushbuffer()
|
2015-12-04 21:08:50 +03:00
|
|
|
timer(lambda: commands.log(ui, repo, rev=rev, date='', user='',
|
2009-03-23 15:12:03 +03:00
|
|
|
template='{date|shortdate} [{rev}:{node|short}]'
|
|
|
|
' {author|person}: {desc|firstline}\n'))
|
|
|
|
ui.popbuffer()
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2009-03-23 15:12:03 +03:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfcca', formatteropts)
|
|
|
|
def perfcca(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-07-18 18:51:20 +04:00
|
|
|
timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2012-04-10 21:07:16 +04:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perffncacheload', formatteropts)
|
|
|
|
def perffncacheload(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-10-12 21:43:24 +04:00
|
|
|
s = repo.store
|
2012-04-13 02:21:52 +04:00
|
|
|
def d():
|
|
|
|
s.fncache._load()
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2012-04-13 02:21:52 +04:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perffncachewrite', formatteropts)
|
|
|
|
def perffncachewrite(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-10-12 21:43:24 +04:00
|
|
|
s = repo.store
|
2012-04-13 02:21:52 +04:00
|
|
|
s.fncache._load()
|
2015-11-25 01:01:11 +03:00
|
|
|
lock = repo.lock()
|
|
|
|
tr = repo.transaction('perffncachewrite')
|
2012-04-13 02:21:52 +04:00
|
|
|
def d():
|
|
|
|
s.fncache._dirty = True
|
2015-11-25 01:01:11 +03:00
|
|
|
s.fncache.write(tr)
|
2012-04-13 02:21:52 +04:00
|
|
|
timer(d)
|
2015-12-27 17:55:54 +03:00
|
|
|
tr.close()
|
2016-08-11 15:51:19 +03:00
|
|
|
lock.release()
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2012-04-13 02:21:52 +04:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perffncacheencode', formatteropts)
|
|
|
|
def perffncacheencode(ui, repo, **opts):
|
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-10-12 21:43:24 +04:00
|
|
|
s = repo.store
|
2012-09-14 15:02:31 +04:00
|
|
|
s.fncache._load()
|
|
|
|
def d():
|
|
|
|
for p in s.fncache.entries:
|
|
|
|
s.encode(p)
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2012-09-14 15:02:31 +04:00
|
|
|
|
2016-11-06 22:01:25 +03:00
|
|
|
@command('perfbdiff', revlogopts + formatteropts + [
|
2016-11-06 21:46:55 +03:00
|
|
|
('', 'count', 1, 'number of revisions to test (when using --startrev)'),
|
|
|
|
('', 'alldata', False, 'test bdiffs for all associated revisions')],
|
2016-11-06 22:01:25 +03:00
|
|
|
'-c|-m|FILE REV')
|
|
|
|
def perfbdiff(ui, repo, file_, rev=None, count=None, **opts):
|
|
|
|
"""benchmark a bdiff between revisions
|
|
|
|
|
|
|
|
By default, benchmark a bdiff between its delta parent and itself.
|
|
|
|
|
|
|
|
With ``--count``, benchmark bdiffs between delta parents and self for N
|
|
|
|
revisions starting at the specified revision.
|
2016-11-06 21:46:55 +03:00
|
|
|
|
|
|
|
With ``--alldata``, assume the requested revision is a changeset and
|
|
|
|
measure bdiffs for all changes related to that changeset (manifest
|
|
|
|
and filelogs).
|
2016-11-06 22:01:25 +03:00
|
|
|
"""
|
2016-11-06 21:46:55 +03:00
|
|
|
if opts['alldata']:
|
|
|
|
opts['changelog'] = True
|
|
|
|
|
2016-11-06 09:41:52 +03:00
|
|
|
if opts.get('changelog') or opts.get('manifest'):
|
|
|
|
file_, rev = None, file_
|
|
|
|
elif rev is None:
|
|
|
|
raise error.CommandError('perfbdiff', 'invalid arguments')
|
|
|
|
|
2016-11-06 20:51:14 +03:00
|
|
|
textpairs = []
|
|
|
|
|
2016-11-06 09:41:52 +03:00
|
|
|
r = cmdutil.openrevlog(repo, 'perfbdiff', file_, opts)
|
|
|
|
|
2016-11-06 22:01:25 +03:00
|
|
|
startrev = r.rev(r.lookup(rev))
|
|
|
|
for rev in range(startrev, min(startrev + count, len(r) - 1)):
|
2016-11-06 21:46:55 +03:00
|
|
|
if opts['alldata']:
|
|
|
|
# Load revisions associated with changeset.
|
|
|
|
ctx = repo[rev]
|
2016-11-17 19:52:52 +03:00
|
|
|
mtext = repo.manifestlog._revlog.revision(ctx.manifestnode())
|
2016-11-06 21:46:55 +03:00
|
|
|
for pctx in ctx.parents():
|
2016-11-17 19:52:52 +03:00
|
|
|
pman = repo.manifestlog._revlog.revision(pctx.manifestnode())
|
2016-11-06 21:46:55 +03:00
|
|
|
textpairs.append((pman, mtext))
|
|
|
|
|
|
|
|
# Load filelog revisions by iterating manifest delta.
|
|
|
|
man = ctx.manifest()
|
|
|
|
pman = ctx.p1().manifest()
|
|
|
|
for filename, change in pman.diff(man).items():
|
|
|
|
fctx = repo.file(filename)
|
|
|
|
f1 = fctx.revision(change[0][0] or -1)
|
|
|
|
f2 = fctx.revision(change[1][0] or -1)
|
|
|
|
textpairs.append((f1, f2))
|
|
|
|
else:
|
|
|
|
dp = r.deltaparent(rev)
|
|
|
|
textpairs.append((r.revision(dp), r.revision(rev)))
|
2016-11-06 09:41:52 +03:00
|
|
|
|
|
|
|
def d():
|
2016-11-06 20:51:14 +03:00
|
|
|
for pair in textpairs:
|
|
|
|
bdiff.bdiff(*pair)
|
2016-11-06 09:41:52 +03:00
|
|
|
|
|
|
|
timer, fm = gettimer(ui, opts)
|
|
|
|
timer(d)
|
|
|
|
fm.end()
|
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfdiffwd', formatteropts)
|
|
|
|
def perfdiffwd(ui, repo, **opts):
|
2009-11-11 19:02:00 +03:00
|
|
|
"""Profile diff of working directory changes"""
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2009-11-11 19:02:00 +03:00
|
|
|
options = {
|
|
|
|
'w': 'ignore_all_space',
|
|
|
|
'b': 'ignore_space_change',
|
|
|
|
'B': 'ignore_blank_lines',
|
|
|
|
}
|
|
|
|
|
|
|
|
for diffopt in ('', 'w', 'b', 'B', 'wB'):
|
|
|
|
opts = dict((options[c], '1') for c in diffopt)
|
|
|
|
def d():
|
|
|
|
ui.pushbuffer()
|
|
|
|
commands.diff(ui, repo, **opts)
|
|
|
|
ui.popbuffer()
|
|
|
|
title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
|
|
|
|
timer(d, title)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2009-11-11 19:02:00 +03:00
|
|
|
|
2015-12-21 06:45:55 +03:00
|
|
|
@command('perfrevlog', revlogopts + formatteropts +
|
2015-12-21 06:56:23 +03:00
|
|
|
[('d', 'dist', 100, 'distance between the revisions'),
|
2016-09-24 20:44:37 +03:00
|
|
|
('s', 'startrev', 0, 'revision to start reading at'),
|
|
|
|
('', 'reverse', False, 'read in reverse')],
|
2015-12-21 06:45:55 +03:00
|
|
|
'-c|-m|FILE')
|
2016-09-24 20:44:37 +03:00
|
|
|
def perfrevlog(ui, repo, file_=None, startrev=0, reverse=False, **opts):
|
2015-12-21 06:45:55 +03:00
|
|
|
"""Benchmark reading a series of revisions from a revlog.
|
|
|
|
|
|
|
|
By default, we read every ``-d/--dist`` revision from 0 to tip of
|
|
|
|
the specified revlog.
|
2015-12-21 06:56:23 +03:00
|
|
|
|
|
|
|
The start revision can be defined via ``-s/--startrev``.
|
2015-12-21 06:45:55 +03:00
|
|
|
"""
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2015-12-04 22:05:56 +03:00
|
|
|
_len = getlen(ui)
|
2016-09-24 20:44:37 +03:00
|
|
|
|
2010-07-27 19:20:09 +04:00
|
|
|
def d():
|
2015-12-21 06:45:55 +03:00
|
|
|
r = cmdutil.openrevlog(repo, 'perfrevlog', file_, opts)
|
2016-09-24 20:44:37 +03:00
|
|
|
|
|
|
|
startrev = 0
|
|
|
|
endrev = _len(r)
|
|
|
|
dist = opts['dist']
|
|
|
|
|
|
|
|
if reverse:
|
|
|
|
startrev, endrev = endrev, startrev
|
|
|
|
dist = -1 * dist
|
|
|
|
|
|
|
|
for x in xrange(startrev, endrev, dist):
|
2010-07-27 19:20:09 +04:00
|
|
|
r.revision(r.node(x))
|
|
|
|
|
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2010-07-27 19:20:09 +04:00
|
|
|
|
2016-11-18 07:17:51 +03:00
|
|
|
@command('perfrevlogchunks', revlogopts + formatteropts +
|
2017-01-02 23:02:08 +03:00
|
|
|
[('e', 'engines', '', 'compression engines to use'),
|
|
|
|
('s', 'startrev', 0, 'revision to start at')],
|
2016-11-18 07:17:51 +03:00
|
|
|
'-c|-m|FILE')
|
2017-01-02 23:02:08 +03:00
|
|
|
def perfrevlogchunks(ui, repo, file_=None, engines=None, startrev=0, **opts):
|
2016-11-18 07:17:51 +03:00
|
|
|
"""Benchmark operations on revlog chunks.
|
|
|
|
|
|
|
|
Logically, each revlog is a collection of fulltext revisions. However,
|
|
|
|
stored within each revlog are "chunks" of possibly compressed data. This
|
|
|
|
data needs to be read and decompressed or compressed and written.
|
|
|
|
|
|
|
|
This command measures the time it takes to read+decompress and recompress
|
|
|
|
chunks in a revlog. It effectively isolates I/O and compression performance.
|
|
|
|
For measurements of higher-level operations like resolving revisions,
|
|
|
|
see ``perfrevlog`` and ``perfrevlogrevision``.
|
|
|
|
"""
|
|
|
|
rl = cmdutil.openrevlog(repo, 'perfrevlogchunks', file_, opts)
|
2017-01-02 23:02:08 +03:00
|
|
|
|
|
|
|
# Verify engines argument.
|
|
|
|
if engines:
|
|
|
|
engines = set(e.strip() for e in engines.split(','))
|
|
|
|
for engine in engines:
|
|
|
|
try:
|
|
|
|
util.compressionengines[engine]
|
|
|
|
except KeyError:
|
|
|
|
raise error.Abort('unknown compression engine: %s' % engine)
|
|
|
|
else:
|
|
|
|
engines = []
|
|
|
|
for e in util.compengines:
|
|
|
|
engine = util.compengines[e]
|
|
|
|
try:
|
|
|
|
if engine.available():
|
|
|
|
engine.revlogcompressor().compress('dummy')
|
|
|
|
engines.append(e)
|
|
|
|
except NotImplementedError:
|
|
|
|
pass
|
|
|
|
|
2016-11-18 07:17:51 +03:00
|
|
|
revs = list(rl.revs(startrev, len(rl) - 1))
|
|
|
|
|
|
|
|
def rlfh(rl):
|
|
|
|
if rl._inline:
|
|
|
|
return getsvfs(repo)(rl.indexfile)
|
|
|
|
else:
|
|
|
|
return getsvfs(repo)(rl.datafile)
|
|
|
|
|
|
|
|
def doread():
|
|
|
|
rl.clearcaches()
|
|
|
|
for rev in revs:
|
|
|
|
rl._chunkraw(rev, rev)
|
|
|
|
|
|
|
|
def doreadcachedfh():
|
|
|
|
rl.clearcaches()
|
|
|
|
fh = rlfh(rl)
|
|
|
|
for rev in revs:
|
|
|
|
rl._chunkraw(rev, rev, df=fh)
|
|
|
|
|
|
|
|
def doreadbatch():
|
|
|
|
rl.clearcaches()
|
|
|
|
rl._chunkraw(revs[0], revs[-1])
|
|
|
|
|
|
|
|
def doreadbatchcachedfh():
|
|
|
|
rl.clearcaches()
|
|
|
|
fh = rlfh(rl)
|
|
|
|
rl._chunkraw(revs[0], revs[-1], df=fh)
|
|
|
|
|
|
|
|
def dochunk():
|
|
|
|
rl.clearcaches()
|
|
|
|
fh = rlfh(rl)
|
|
|
|
for rev in revs:
|
|
|
|
rl._chunk(rev, df=fh)
|
|
|
|
|
|
|
|
chunks = [None]
|
|
|
|
|
|
|
|
def dochunkbatch():
|
|
|
|
rl.clearcaches()
|
|
|
|
fh = rlfh(rl)
|
|
|
|
# Save chunks as a side-effect.
|
|
|
|
chunks[0] = rl._chunks(revs, df=fh)
|
|
|
|
|
2017-01-02 23:02:08 +03:00
|
|
|
def docompress(compressor):
|
2016-11-18 07:17:51 +03:00
|
|
|
rl.clearcaches()
|
2017-01-02 23:02:08 +03:00
|
|
|
|
|
|
|
try:
|
|
|
|
# Swap in the requested compression engine.
|
|
|
|
oldcompressor = rl._compressor
|
|
|
|
rl._compressor = compressor
|
|
|
|
for chunk in chunks[0]:
|
|
|
|
rl.compress(chunk)
|
|
|
|
finally:
|
|
|
|
rl._compressor = oldcompressor
|
2016-11-18 07:17:51 +03:00
|
|
|
|
|
|
|
benches = [
|
|
|
|
(lambda: doread(), 'read'),
|
|
|
|
(lambda: doreadcachedfh(), 'read w/ reused fd'),
|
|
|
|
(lambda: doreadbatch(), 'read batch'),
|
|
|
|
(lambda: doreadbatchcachedfh(), 'read batch w/ reused fd'),
|
|
|
|
(lambda: dochunk(), 'chunk'),
|
|
|
|
(lambda: dochunkbatch(), 'chunk batch'),
|
|
|
|
]
|
|
|
|
|
2017-01-02 23:02:08 +03:00
|
|
|
for engine in sorted(engines):
|
|
|
|
compressor = util.compengines[engine].revlogcompressor()
|
|
|
|
benches.append((functools.partial(docompress, compressor),
|
|
|
|
'compress w/ %s' % engine))
|
|
|
|
|
2016-11-18 07:17:51 +03:00
|
|
|
for fn, title in benches:
|
|
|
|
timer, fm = gettimer(ui, opts)
|
|
|
|
timer(fn, title=title)
|
|
|
|
fm.end()
|
|
|
|
|
2015-12-21 05:38:21 +03:00
|
|
|
@command('perfrevlogrevision', revlogopts + formatteropts +
|
|
|
|
[('', 'cache', False, 'use caches instead of clearing')],
|
|
|
|
'-c|-m|FILE REV')
|
|
|
|
def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts):
|
|
|
|
"""Benchmark obtaining a revlog revision.
|
|
|
|
|
|
|
|
Obtaining a revlog revision consists of roughly the following steps:
|
|
|
|
|
|
|
|
1. Compute the delta chain
|
|
|
|
2. Obtain the raw chunks for that delta chain
|
|
|
|
3. Decompress each raw chunk
|
|
|
|
4. Apply binary patches to obtain fulltext
|
|
|
|
5. Verify hash of fulltext
|
|
|
|
|
|
|
|
This command measures the time spent in each of these phases.
|
|
|
|
"""
|
|
|
|
if opts.get('changelog') or opts.get('manifest'):
|
|
|
|
file_, rev = None, file_
|
|
|
|
elif rev is None:
|
|
|
|
raise error.CommandError('perfrevlogrevision', 'invalid arguments')
|
|
|
|
|
|
|
|
r = cmdutil.openrevlog(repo, 'perfrevlogrevision', file_, opts)
|
|
|
|
node = r.lookup(rev)
|
|
|
|
rev = r.rev(node)
|
|
|
|
|
2017-02-04 19:47:46 +03:00
|
|
|
def getrawchunks(data, chain):
|
|
|
|
start = r.start
|
|
|
|
length = r.length
|
|
|
|
inline = r._inline
|
|
|
|
iosize = r._io.size
|
|
|
|
buffer = util.buffer
|
|
|
|
offset = start(chain[0])
|
|
|
|
|
|
|
|
chunks = []
|
|
|
|
ladd = chunks.append
|
|
|
|
|
|
|
|
for rev in chain:
|
|
|
|
chunkstart = start(rev)
|
|
|
|
if inline:
|
|
|
|
chunkstart += (rev + 1) * iosize
|
|
|
|
chunklength = length(rev)
|
|
|
|
ladd(buffer(data, chunkstart - offset, chunklength))
|
|
|
|
|
|
|
|
return chunks
|
|
|
|
|
2015-12-21 05:38:21 +03:00
|
|
|
def dodeltachain(rev):
|
|
|
|
if not cache:
|
|
|
|
r.clearcaches()
|
|
|
|
r._deltachain(rev)
|
|
|
|
|
|
|
|
def doread(chain):
|
|
|
|
if not cache:
|
|
|
|
r.clearcaches()
|
|
|
|
r._chunkraw(chain[0], chain[-1])
|
|
|
|
|
2017-02-04 19:47:46 +03:00
|
|
|
def dorawchunks(data, chain):
|
2015-12-21 05:38:21 +03:00
|
|
|
if not cache:
|
|
|
|
r.clearcaches()
|
2017-02-04 19:47:46 +03:00
|
|
|
getrawchunks(data, chain)
|
2015-12-21 05:38:21 +03:00
|
|
|
|
2017-02-04 19:47:46 +03:00
|
|
|
def dodecompress(chunks):
|
|
|
|
decomp = r.decompress
|
|
|
|
for chunk in chunks:
|
|
|
|
decomp(chunk)
|
2015-12-21 05:38:21 +03:00
|
|
|
|
|
|
|
def dopatch(text, bins):
|
|
|
|
if not cache:
|
|
|
|
r.clearcaches()
|
|
|
|
mdiff.patches(text, bins)
|
|
|
|
|
|
|
|
def dohash(text):
|
|
|
|
if not cache:
|
|
|
|
r.clearcaches()
|
2016-12-13 17:21:36 +03:00
|
|
|
r.checkhash(text, node, rev=rev)
|
2015-12-21 05:38:21 +03:00
|
|
|
|
|
|
|
def dorevision():
|
|
|
|
if not cache:
|
|
|
|
r.clearcaches()
|
|
|
|
r.revision(node)
|
|
|
|
|
|
|
|
chain = r._deltachain(rev)[0]
|
2016-01-06 06:51:51 +03:00
|
|
|
data = r._chunkraw(chain[0], chain[-1])[1]
|
2017-02-04 19:47:46 +03:00
|
|
|
rawchunks = getrawchunks(data, chain)
|
2015-12-21 05:38:21 +03:00
|
|
|
bins = r._chunks(chain)
|
|
|
|
text = str(bins[0])
|
|
|
|
bins = bins[1:]
|
|
|
|
text = mdiff.patches(text, bins)
|
|
|
|
|
|
|
|
benches = [
|
|
|
|
(lambda: dorevision(), 'full'),
|
|
|
|
(lambda: dodeltachain(rev), 'deltachain'),
|
|
|
|
(lambda: doread(chain), 'read'),
|
2017-02-04 19:47:46 +03:00
|
|
|
(lambda: dorawchunks(data, chain), 'rawchunks'),
|
|
|
|
(lambda: dodecompress(rawchunks), 'decompress'),
|
2015-12-21 05:38:21 +03:00
|
|
|
(lambda: dopatch(text, bins), 'patch'),
|
|
|
|
(lambda: dohash(text), 'hash'),
|
|
|
|
]
|
|
|
|
|
|
|
|
for fn, title in benches:
|
|
|
|
timer, fm = gettimer(ui, opts)
|
|
|
|
timer(fn, title=title)
|
|
|
|
fm.end()
|
|
|
|
|
2013-01-04 22:22:40 +04:00
|
|
|
@command('perfrevset',
|
2015-11-22 02:39:18 +03:00
|
|
|
[('C', 'clear', False, 'clear volatile cache between each call.'),
|
|
|
|
('', 'contexts', False, 'obtain changectx for each revision')]
|
2015-06-10 01:18:47 +03:00
|
|
|
+ formatteropts, "REVSET")
|
2015-11-22 02:39:18 +03:00
|
|
|
def perfrevset(ui, repo, expr, clear=False, contexts=False, **opts):
|
2013-01-04 22:22:40 +04:00
|
|
|
"""benchmark the execution time of a revset
|
|
|
|
|
2013-02-10 21:24:29 +04:00
|
|
|
Use the --clean option if need to evaluate the impact of build volatile
|
2013-01-04 22:22:40 +04:00
|
|
|
revisions set cache on the revset execution. Volatile cache hold filtered
|
|
|
|
and obsolete related cache."""
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2012-12-06 23:21:11 +04:00
|
|
|
def d():
|
2013-01-04 22:22:40 +04:00
|
|
|
if clear:
|
|
|
|
repo.invalidatevolatilesets()
|
2015-11-22 02:39:18 +03:00
|
|
|
if contexts:
|
|
|
|
for ctx in repo.set(expr): pass
|
|
|
|
else:
|
|
|
|
for r in repo.revs(expr): pass
|
2012-12-06 23:21:11 +04:00
|
|
|
timer(d)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2013-01-04 22:23:26 +04:00
|
|
|
|
2015-06-10 01:18:47 +03:00
|
|
|
@command('perfvolatilesets', formatteropts)
|
|
|
|
def perfvolatilesets(ui, repo, *names, **opts):
|
2013-01-04 22:23:26 +04:00
|
|
|
"""benchmark the computation of various volatile set
|
|
|
|
|
|
|
|
Volatile set computes element related to filtering and obsolescence."""
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2013-01-04 22:23:26 +04:00
|
|
|
repo = repo.unfiltered()
|
|
|
|
|
|
|
|
def getobs(name):
|
|
|
|
def d():
|
|
|
|
repo.invalidatevolatilesets()
|
|
|
|
obsolete.getrevs(repo, name)
|
|
|
|
return d
|
|
|
|
|
2013-01-04 22:24:32 +04:00
|
|
|
allobs = sorted(obsolete.cachefuncs)
|
|
|
|
if names:
|
|
|
|
allobs = [n for n in allobs if n in names]
|
|
|
|
|
|
|
|
for name in allobs:
|
2013-01-04 22:23:26 +04:00
|
|
|
timer(getobs(name), title=name)
|
|
|
|
|
|
|
|
def getfiltered(name):
|
|
|
|
def d():
|
|
|
|
repo.invalidatevolatilesets()
|
2013-12-24 04:04:51 +04:00
|
|
|
repoview.filterrevs(repo, name)
|
2013-01-04 22:23:26 +04:00
|
|
|
return d
|
|
|
|
|
2013-01-04 22:24:32 +04:00
|
|
|
allfilter = sorted(repoview.filtertable)
|
|
|
|
if names:
|
|
|
|
allfilter = [n for n in allfilter if n in names]
|
|
|
|
|
|
|
|
for name in allfilter:
|
2013-01-04 22:23:26 +04:00
|
|
|
timer(getfiltered(name), title=name)
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2013-01-11 21:39:43 +04:00
|
|
|
|
|
|
|
@command('perfbranchmap',
|
|
|
|
[('f', 'full', False,
|
|
|
|
'Includes build time of subset'),
|
2015-06-10 01:18:47 +03:00
|
|
|
] + formatteropts)
|
|
|
|
def perfbranchmap(ui, repo, full=False, **opts):
|
2013-01-11 21:39:43 +04:00
|
|
|
"""benchmark the update of a branchmap
|
|
|
|
|
|
|
|
This benchmarks the full repo.branchmap() call with read and write disabled
|
|
|
|
"""
|
2015-06-10 01:18:47 +03:00
|
|
|
timer, fm = gettimer(ui, opts)
|
2013-01-11 21:39:43 +04:00
|
|
|
def getbranchmap(filtername):
|
|
|
|
"""generate a benchmark function for the filtername"""
|
|
|
|
if filtername is None:
|
|
|
|
view = repo
|
|
|
|
else:
|
|
|
|
view = repo.filtered(filtername)
|
|
|
|
def d():
|
|
|
|
if full:
|
|
|
|
view._branchcaches.clear()
|
|
|
|
else:
|
|
|
|
view._branchcaches.pop(filtername, None)
|
|
|
|
view.branchmap()
|
|
|
|
return d
|
|
|
|
# add filter in smaller subset to bigger subset
|
|
|
|
possiblefilters = set(repoview.filtertable)
|
2016-10-08 19:03:17 +03:00
|
|
|
subsettable = getbranchmapsubsettable()
|
2013-01-11 21:39:43 +04:00
|
|
|
allfilters = []
|
|
|
|
while possiblefilters:
|
|
|
|
for name in possiblefilters:
|
2016-10-08 19:03:17 +03:00
|
|
|
subset = subsettable.get(name)
|
2013-01-11 21:39:43 +04:00
|
|
|
if subset not in possiblefilters:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
assert False, 'subset cycle %s!' % possiblefilters
|
|
|
|
allfilters.append(name)
|
|
|
|
possiblefilters.remove(name)
|
|
|
|
|
|
|
|
# warm the cache
|
|
|
|
if not full:
|
|
|
|
for name in allfilters:
|
|
|
|
repo.filtered(name).branchmap()
|
|
|
|
# add unfiltered
|
|
|
|
allfilters.append(None)
|
perf: avoid actual writing branch cache out correctly
Mercurial 2.5 (or 0eb7dcc721cb) introduced "perfbranchmap" command,
and tried to avoid actual writing branch cache out by replacing
write() of branchcache class in branchmap.py with no-op function
(probably, for elimination of noisy and heavy file I/O factor).
But its implementation isn't correct, because 0eb7dcc721cb replaced
not branchmap.branchcache.write() but branchmap.write(). The latter
doesn't exist, even at that change.
To avoid actual writing branch cache out correctly, this patch
replaces branchmap.branchcache.write() with no-op function.
To detect mistake of replacement or change of API in the future
quickly, this patch uses safeattrsetter() instead of direct attribute
assignment. For similarity between replacements, this patch also
changes replacement of branchmap.read().
In this patch, replacement of read()/write() can run safely outside
"try" block, because two safeattrsetter() invocations ensure that
replacement doesn't cause exception.
FYI, the table below compares "base" filter wall time of perfbranchmap
on recent mozilla-central repo with each Mercurial version between
before and after this patch.
==== ========= =========
ver before after
==== ========= =========
2.5 18.492334 18.232455
2.6 18.733858 18.156702
2.7 18.245598 18.349210
2.8 18.289070 18.528422
2.9 17.572742 16.989655
3.0 17.406953 17.615012
3.1 17.228419 17.689805
3.2 17.862961 17.718367
3.3 2.632110 2.707960
3.4 3.285683 3.272060
3.5 3.370141 3.352176
3.6 3.366939 3.242455
3.7 3.300778 3.367328
3.8 3.300132 3.267298
3.9 3.418996 3.370265
==== ========= =========
IMHO, there is no serious overlooking performance regression.
2016-10-08 19:03:17 +03:00
|
|
|
|
|
|
|
branchcacheread = safeattrsetter(branchmap, 'read')
|
|
|
|
branchcachewrite = safeattrsetter(branchmap.branchcache, 'write')
|
|
|
|
branchcacheread.set(lambda repo: None)
|
|
|
|
branchcachewrite.set(lambda bc, repo: None)
|
2013-01-11 21:39:43 +04:00
|
|
|
try:
|
|
|
|
for name in allfilters:
|
|
|
|
timer(getbranchmap(name), title=str(name))
|
|
|
|
finally:
|
perf: avoid actual writing branch cache out correctly
Mercurial 2.5 (or 0eb7dcc721cb) introduced "perfbranchmap" command,
and tried to avoid actual writing branch cache out by replacing
write() of branchcache class in branchmap.py with no-op function
(probably, for elimination of noisy and heavy file I/O factor).
But its implementation isn't correct, because 0eb7dcc721cb replaced
not branchmap.branchcache.write() but branchmap.write(). The latter
doesn't exist, even at that change.
To avoid actual writing branch cache out correctly, this patch
replaces branchmap.branchcache.write() with no-op function.
To detect mistake of replacement or change of API in the future
quickly, this patch uses safeattrsetter() instead of direct attribute
assignment. For similarity between replacements, this patch also
changes replacement of branchmap.read().
In this patch, replacement of read()/write() can run safely outside
"try" block, because two safeattrsetter() invocations ensure that
replacement doesn't cause exception.
FYI, the table below compares "base" filter wall time of perfbranchmap
on recent mozilla-central repo with each Mercurial version between
before and after this patch.
==== ========= =========
ver before after
==== ========= =========
2.5 18.492334 18.232455
2.6 18.733858 18.156702
2.7 18.245598 18.349210
2.8 18.289070 18.528422
2.9 17.572742 16.989655
3.0 17.406953 17.615012
3.1 17.228419 17.689805
3.2 17.862961 17.718367
3.3 2.632110 2.707960
3.4 3.285683 3.272060
3.5 3.370141 3.352176
3.6 3.366939 3.242455
3.7 3.300778 3.367328
3.8 3.300132 3.267298
3.9 3.418996 3.370265
==== ========= =========
IMHO, there is no serious overlooking performance regression.
2016-10-08 19:03:17 +03:00
|
|
|
branchcacheread.restore()
|
|
|
|
branchcachewrite.restore()
|
perf: use a formatter for output
We use a `formatter` object in the perf extensions. This allow the use of
formatted output like json. To avoid adding logic to create a formatter and pass
it around to the timer function in every command, we add a `gettimer` function
in charge of returning a `timer` function as simple as before but embedding an
appropriate formatter.
This new `gettimer` function also return the formatter as it needs to be
explicitly closed at the end of the command.
example output:
$ hg --config ui.formatjson=True perfvolatilesets visible obsolete
[
{
"comb": 0.02,
"count": 126,
"sys": 0.0,
"title": "obsolete",
"user": 0.02,
"wall": 0.0199398994446
},
{
"comb": 0.02,
"count": 117,
"sys": 0.0,
"title": "visible",
"user": 0.02,
"wall": 0.0250301361084
}
]
2014-11-04 13:40:06 +03:00
|
|
|
fm.end()
|
2014-11-21 03:27:55 +03:00
|
|
|
|
|
|
|
@command('perfloadmarkers')
|
|
|
|
def perfloadmarkers(ui, repo):
|
|
|
|
"""benchmark the time to parse the on-disk markers for a repo
|
|
|
|
|
|
|
|
Result is the number of markers in the repo."""
|
|
|
|
timer, fm = gettimer(ui)
|
2016-10-08 19:03:18 +03:00
|
|
|
svfs = getsvfs(repo)
|
|
|
|
timer(lambda: len(obsolete.obsstore(svfs)))
|
2014-11-21 03:27:55 +03:00
|
|
|
fm.end()
|
2015-12-07 04:07:50 +03:00
|
|
|
|
|
|
|
@command('perflrucachedict', formatteropts +
|
|
|
|
[('', 'size', 4, 'size of cache'),
|
|
|
|
('', 'gets', 10000, 'number of key lookups'),
|
|
|
|
('', 'sets', 10000, 'number of key sets'),
|
|
|
|
('', 'mixed', 10000, 'number of mixed mode operations'),
|
|
|
|
('', 'mixedgetfreq', 50, 'frequency of get vs set ops in mixed mode')],
|
|
|
|
norepo=True)
|
|
|
|
def perflrucache(ui, size=4, gets=10000, sets=10000, mixed=10000,
|
|
|
|
mixedgetfreq=50, **opts):
|
|
|
|
def doinit():
|
|
|
|
for i in xrange(10000):
|
|
|
|
util.lrucachedict(size)
|
|
|
|
|
|
|
|
values = []
|
|
|
|
for i in xrange(size):
|
|
|
|
values.append(random.randint(0, sys.maxint))
|
|
|
|
|
|
|
|
# Get mode fills the cache and tests raw lookup performance with no
|
|
|
|
# eviction.
|
|
|
|
getseq = []
|
|
|
|
for i in xrange(gets):
|
|
|
|
getseq.append(random.choice(values))
|
|
|
|
|
|
|
|
def dogets():
|
|
|
|
d = util.lrucachedict(size)
|
|
|
|
for v in values:
|
|
|
|
d[v] = v
|
|
|
|
for key in getseq:
|
|
|
|
value = d[key]
|
|
|
|
value # silence pyflakes warning
|
|
|
|
|
|
|
|
# Set mode tests insertion speed with cache eviction.
|
|
|
|
setseq = []
|
|
|
|
for i in xrange(sets):
|
|
|
|
setseq.append(random.randint(0, sys.maxint))
|
|
|
|
|
|
|
|
def dosets():
|
|
|
|
d = util.lrucachedict(size)
|
|
|
|
for v in setseq:
|
|
|
|
d[v] = v
|
|
|
|
|
|
|
|
# Mixed mode randomly performs gets and sets with eviction.
|
|
|
|
mixedops = []
|
|
|
|
for i in xrange(mixed):
|
|
|
|
r = random.randint(0, 100)
|
|
|
|
if r < mixedgetfreq:
|
|
|
|
op = 0
|
|
|
|
else:
|
|
|
|
op = 1
|
|
|
|
|
|
|
|
mixedops.append((op, random.randint(0, size * 2)))
|
|
|
|
|
|
|
|
def domixed():
|
|
|
|
d = util.lrucachedict(size)
|
|
|
|
|
|
|
|
for op, v in mixedops:
|
|
|
|
if op == 0:
|
|
|
|
try:
|
|
|
|
d[v]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
d[v] = v
|
|
|
|
|
|
|
|
benches = [
|
|
|
|
(doinit, 'init'),
|
|
|
|
(dogets, 'gets'),
|
|
|
|
(dosets, 'sets'),
|
|
|
|
(domixed, 'mixed')
|
|
|
|
]
|
|
|
|
|
|
|
|
for fn, title in benches:
|
|
|
|
timer, fm = gettimer(ui, opts)
|
|
|
|
timer(fn, title=title)
|
|
|
|
fm.end()
|
perf: use locally defined revlog option list for Mercurial earlier than 3.7
Before this patch, referring commands.debugrevlogopts prevents perf.py
from being loaded by Mercurial earlier than 3.7 (or 1a89336e03aa),
because it isn't available in such Mercurial, even though
cmdutil.openrevlog(), a user of these options, has been available
since 1.9 (or f32fd7cab084).
In addition to it, there are some code paths for Mercurial earlier
than 3.7. For example, setting "_prereadsize" attribute in perfindex()
and perfnodelookup() is effective only with hg earlier than 1.8 (or
1299f0c14572).
But just "using locally defined revlog option list" might cause
unexpected behavior at runtime. If --dir option is specified to
cmdutil.openrevlog() of Mercurial earlier than 3.5 (or e3ab0b30c05e),
it is silently ignored without any warning or so.
============ ============ ===== ===============
debugrevlogopts
hg version openrevlog() --dir of commands
============ ============ ===== ===============
3.7 or later o o o
3.5 or later o o x
1.9 or later o x x
earlier x x x
============ ============ ===== ===============
Therefore, this patch does:
- use locally defined option list, if commands.debugrevlogopts isn't
available (for Mercurial earlier than 3.7)
- wrap cmdutil.openrevlog(), if it is ambiguous whether
cmdutil.openrevlog() can recognize --dir option correctly
(for Mercurial earlier than 3.5)
This wrapper function aborts execution, if:
- --dir option is specified, and
- localrepository doesn't have "dirlog" attribute, which indicates
that localrepository has a function for '--dir'
BTW, extensions.wrapfunction() has been available since 1.1 (or
56ba0b824b91), and this seems old enough for "historical
portability" of perf.py, which has been available since 1.1 (or
bca5e7427e89).
2016-07-05 01:25:51 +03:00
|
|
|
|
2017-02-16 00:07:26 +03:00
|
|
|
@command('perfwrite', formatteropts)
|
|
|
|
def perfwrite(ui, repo, **opts):
|
|
|
|
"""microbenchmark ui.write
|
|
|
|
"""
|
|
|
|
timer, fm = gettimer(ui, opts)
|
|
|
|
def write():
|
|
|
|
for i in range(100000):
|
|
|
|
ui.write(('Testing write performance\n'))
|
|
|
|
timer(write)
|
|
|
|
fm.end()
|
|
|
|
|
perf: use locally defined revlog option list for Mercurial earlier than 3.7
Before this patch, referring commands.debugrevlogopts prevents perf.py
from being loaded by Mercurial earlier than 3.7 (or 1a89336e03aa),
because it isn't available in such Mercurial, even though
cmdutil.openrevlog(), a user of these options, has been available
since 1.9 (or f32fd7cab084).
In addition to it, there are some code paths for Mercurial earlier
than 3.7. For example, setting "_prereadsize" attribute in perfindex()
and perfnodelookup() is effective only with hg earlier than 1.8 (or
1299f0c14572).
But just "using locally defined revlog option list" might cause
unexpected behavior at runtime. If --dir option is specified to
cmdutil.openrevlog() of Mercurial earlier than 3.5 (or e3ab0b30c05e),
it is silently ignored without any warning or so.
============ ============ ===== ===============
debugrevlogopts
hg version openrevlog() --dir of commands
============ ============ ===== ===============
3.7 or later o o o
3.5 or later o o x
1.9 or later o x x
earlier x x x
============ ============ ===== ===============
Therefore, this patch does:
- use locally defined option list, if commands.debugrevlogopts isn't
available (for Mercurial earlier than 3.7)
- wrap cmdutil.openrevlog(), if it is ambiguous whether
cmdutil.openrevlog() can recognize --dir option correctly
(for Mercurial earlier than 3.5)
This wrapper function aborts execution, if:
- --dir option is specified, and
- localrepository doesn't have "dirlog" attribute, which indicates
that localrepository has a function for '--dir'
BTW, extensions.wrapfunction() has been available since 1.1 (or
56ba0b824b91), and this seems old enough for "historical
portability" of perf.py, which has been available since 1.1 (or
bca5e7427e89).
2016-07-05 01:25:51 +03:00
|
|
|
def uisetup(ui):
|
|
|
|
if (util.safehasattr(cmdutil, 'openrevlog') and
|
|
|
|
not util.safehasattr(commands, 'debugrevlogopts')):
|
|
|
|
# for "historical portability":
|
|
|
|
# In this case, Mercurial should be 1.9 (or a79fea6b3e77) -
|
|
|
|
# 3.7 (or 5606f7d0d063). Therefore, '--dir' option for
|
|
|
|
# openrevlog() should cause failure, because it has been
|
|
|
|
# available since 3.5 (or 49c583ca48c4).
|
|
|
|
def openrevlog(orig, repo, cmd, file_, opts):
|
|
|
|
if opts.get('dir') and not util.safehasattr(repo, 'dirlog'):
|
|
|
|
raise error.Abort("This version doesn't support --dir option",
|
|
|
|
hint="use 3.5 or later")
|
|
|
|
return orig(repo, cmd, file_, opts)
|
|
|
|
extensions.wrapfunction(cmdutil, 'openrevlog', openrevlog)
|