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
|
2016-03-16 01:42:16 +03:00
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
from mercurial import (
|
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,
|
|
|
|
revlog,
|
|
|
|
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)
|
|
|
|
|
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
|
2015-01-11 06:13:10 +03:00
|
|
|
time.sleep(ui.configint("perf", "presleep", 1))
|
|
|
|
|
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 = {}
|
|
|
|
# redirect all to stderr
|
|
|
|
ui = ui.copy()
|
|
|
|
ui.fout = ui.ferr
|
|
|
|
# get a formatter
|
|
|
|
fm = ui.formatter('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):
|
2008-11-13 21:52:03 +03:00
|
|
|
results = []
|
|
|
|
begin = time.time()
|
|
|
|
count = 0
|
2011-06-01 14:38:46 +04:00
|
|
|
while True:
|
2008-11-13 21:52:03 +03:00
|
|
|
ostart = os.times()
|
|
|
|
cstart = time.time()
|
|
|
|
r = func()
|
|
|
|
cstop = time.time()
|
|
|
|
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
|
|
|
|
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)
|
2008-11-13 21:52:03 +03:00
|
|
|
def t():
|
2015-01-11 02:25:54 +03:00
|
|
|
repo.changelog = mercurial.changelog.changelog(repo.svfs)
|
|
|
|
repo.manifest = mercurial.manifest.manifest(repo.svfs)
|
2009-07-16 18:39:41 +04:00
|
|
|
repo._tags = None
|
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():
|
2015-12-21 04:57:44 +03:00
|
|
|
repo.manifest.clearcaches()
|
2013-09-07 00:20:07 +04:00
|
|
|
repo.manifest.read(t)
|
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()
|
2008-11-13 21:52:03 +03:00
|
|
|
def d():
|
2015-01-11 02:25:54 +03:00
|
|
|
cl = mercurial.revlog.revlog(repo.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
|
|
|
|
count = ui.configint("perf", "parentscount", 1000)
|
|
|
|
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()
|
2015-01-11 02:25:54 +03:00
|
|
|
cl = mercurial.revlog.revlog(repo.svfs, "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-11-25 01:01:11 +03:00
|
|
|
lock.release()
|
2015-12-27 17:55:54 +03:00
|
|
|
tr.close()
|
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
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
|
|
|
|
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])
|
|
|
|
|
|
|
|
def dodecompress(data, chain):
|
|
|
|
if not cache:
|
|
|
|
r.clearcaches()
|
|
|
|
|
|
|
|
start = r.start
|
|
|
|
length = r.length
|
|
|
|
inline = r._inline
|
|
|
|
iosize = r._io.size
|
|
|
|
buffer = util.buffer
|
|
|
|
offset = start(chain[0])
|
|
|
|
|
|
|
|
for rev in chain:
|
|
|
|
chunkstart = start(rev)
|
|
|
|
if inline:
|
|
|
|
chunkstart += (rev + 1) * iosize
|
|
|
|
chunklength = length(rev)
|
|
|
|
b = buffer(data, chunkstart - offset, chunklength)
|
|
|
|
revlog.decompress(b)
|
|
|
|
|
|
|
|
def dopatch(text, bins):
|
|
|
|
if not cache:
|
|
|
|
r.clearcaches()
|
|
|
|
mdiff.patches(text, bins)
|
|
|
|
|
|
|
|
def dohash(text):
|
|
|
|
if not cache:
|
|
|
|
r.clearcaches()
|
|
|
|
r._checkhash(text, node, rev)
|
|
|
|
|
|
|
|
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]
|
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'),
|
|
|
|
(lambda: dodecompress(data, chain), 'decompress'),
|
|
|
|
(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)
|
|
|
|
allfilters = []
|
|
|
|
while possiblefilters:
|
|
|
|
for name in possiblefilters:
|
2013-11-06 23:38:34 +04:00
|
|
|
subset = branchmap.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)
|
|
|
|
oldread = branchmap.read
|
|
|
|
oldwrite = branchmap.branchcache.write
|
|
|
|
try:
|
|
|
|
branchmap.read = lambda repo: None
|
|
|
|
branchmap.write = lambda repo: None
|
|
|
|
for name in allfilters:
|
|
|
|
timer(getbranchmap(name), title=str(name))
|
|
|
|
finally:
|
|
|
|
branchmap.read = oldread
|
|
|
|
branchmap.branchcache.write = oldwrite
|
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)
|
2015-01-11 02:25:54 +03:00
|
|
|
timer(lambda: len(obsolete.obsstore(repo.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
|
|
|
|
|
|
|
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)
|