contrib/perf.py
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Sun, 09 Oct 2016 01:03:16 +0900
changeset 30143 2d858c771760
parent 30069 98b9846a131e
child 30144 14031d183048
permissions -rw-r--r--
perf: introduce safeattrsetter to replace direct attribute assignment Referring not-existing attribute immediately causes failure, but assigning a value to such attribute doesn't. For example, perf.py has code paths below, which assign a value to not-existing attribute. This causes incorrect performance measurement, but these code paths are executed successfully. - "repo._tags = None" in perftags() recent Mercurial has tags cache information in repo._tagscache - "branchmap.write = lambda repo: None" in perfbranchmap() branchmap cache is written out by branchcache.write() in branchmap.py "util.safehasattr() before assignment" can avoid this issue, but might increase mistake at "copy & paste" attribute name or so. To centralize (1) examining existence of, (2) assigning a value to, and (3) restoring an old value to the attribute, this patch introduces safeattrsetter(). This is used to replace direct attribute assignment in subsequent patches. Encapsulation of restoring is needed to completely remove direct attribute assignment from perf.py, even though restoring isn't needed so often.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
# perf.py - performance test routines
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8656
diff changeset
     2
'''helper extension to measure performance'''
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
29493
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     4
# "historical portability" policy of perf.py:
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     5
#
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     6
# We have to do:
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     7
# - make perf.py "loadable" with as wide Mercurial version as possible
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     8
#   This doesn't mean that perf commands work correctly with that Mercurial.
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     9
#   BTW, perf.py itself has been available since 1.1 (or eb240755386d).
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    10
# - make historical perf command work correctly with as wide Mercurial
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    11
#   version as possible
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    12
#
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    13
# We have to do, if possible with reasonable cost:
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    14
# - make recent perf command for historical feature work correctly
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    15
#   with early Mercurial
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    16
#
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    17
# We don't have to do:
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    18
# - make perf command for recent feature work correctly with early
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    19
#   Mercurial
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    20
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    21
from __future__ import absolute_import
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    22
import functools
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    23
import os
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
    24
import random
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    25
import sys
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    26
import time
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    27
from mercurial import (
30018
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
    28
    changegroup,
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    29
    cmdutil,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    30
    commands,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    31
    copies,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    32
    error,
29495
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    33
    extensions,
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    34
    mdiff,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    35
    merge,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    36
    revlog,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    37
    util,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    38
)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    39
29494
3b5389ef5cfe perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29493
diff changeset
    40
# for "historical portability":
29567
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    41
# try to import modules separately (in dict order), and ignore
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    42
# failure, because these aren't available with early Mercurial
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    43
try:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    44
    from mercurial import branchmap # since 2.5 (or bcee63733aad)
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    45
except ImportError:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    46
    pass
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    47
try:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    48
    from mercurial import obsolete # since 2.3 (or ad0d6c2b3279)
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    49
except ImportError:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    50
    pass
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    51
try:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    52
    from mercurial import repoview # since 2.5 (or 3a6ddacb7198)
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    53
except ImportError:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    54
    pass
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    55
try:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    56
    from mercurial import scmutil # since 1.9 (or 8b252e826c68)
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    57
except ImportError:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    58
    pass
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    59
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    60
# for "historical portability":
29494
3b5389ef5cfe perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29493
diff changeset
    61
# define util.safehasattr forcibly, because util.safehasattr has been
3b5389ef5cfe perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29493
diff changeset
    62
# available since 1.9.3 (or 94b200a11cf7)
3b5389ef5cfe perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29493
diff changeset
    63
_undefined = object()
3b5389ef5cfe perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29493
diff changeset
    64
def safehasattr(thing, attr):
3b5389ef5cfe perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29493
diff changeset
    65
    return getattr(thing, attr, _undefined) is not _undefined
3b5389ef5cfe perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29493
diff changeset
    66
setattr(util, 'safehasattr', safehasattr)
3b5389ef5cfe perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29493
diff changeset
    67
29496
7299370cf304 perf: avoid using formatteropts for Mercurial earlier than 3.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29495
diff changeset
    68
# for "historical portability":
7299370cf304 perf: avoid using formatteropts for Mercurial earlier than 3.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29495
diff changeset
    69
# use locally defined empty option list, if formatteropts isn't
7299370cf304 perf: avoid using formatteropts for Mercurial earlier than 3.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29495
diff changeset
    70
# available, because commands.formatteropts has been available since
7299370cf304 perf: avoid using formatteropts for Mercurial earlier than 3.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29495
diff changeset
    71
# 3.2 (or 7a7eed5176a4), even though formatting itself has been
7299370cf304 perf: avoid using formatteropts for Mercurial earlier than 3.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29495
diff changeset
    72
# available since 2.2 (or ae5f92e154d3)
7299370cf304 perf: avoid using formatteropts for Mercurial earlier than 3.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29495
diff changeset
    73
formatteropts = getattr(commands, "formatteropts", [])
29495
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    74
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    75
# for "historical portability":
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    76
# use locally defined option list, if debugrevlogopts isn't available,
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    77
# because commands.debugrevlogopts has been available since 3.7 (or
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    78
# 5606f7d0d063), even though cmdutil.openrevlog() has been available
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    79
# since 1.9 (or a79fea6b3e77).
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    80
revlogopts = getattr(commands, "debugrevlogopts", [
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    81
        ('c', 'changelog', False, ('open changelog')),
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    82
        ('m', 'manifest', False, ('open manifest')),
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    83
        ('', 'dir', False, ('open directory manifest')),
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
    84
        ])
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
    85
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
    86
cmdtable = {}
29497
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    87
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    88
# for "historical portability":
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    89
# define parsealiases locally, because cmdutil.parsealiases has been
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    90
# available since 1.5 (or 6252852b4332)
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    91
def parsealiases(cmd):
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    92
    return cmd.lstrip("^").split("|")
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    93
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    94
if safehasattr(cmdutil, 'command'):
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    95
    import inspect
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    96
    command = cmdutil.command(cmdtable)
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    97
    if 'norepo' not in inspect.getargspec(command)[0]:
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    98
        # for "historical portability":
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
    99
        # wrap original cmdutil.command, because "norepo" option has
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   100
        # been available since 3.1 (or 75a96326cecb)
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   101
        _command = command
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   102
        def command(name, options=(), synopsis=None, norepo=False):
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   103
            if norepo:
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   104
                commands.norepo += ' %s' % ' '.join(parsealiases(name))
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   105
            return _command(name, list(options), synopsis)
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   106
else:
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   107
    # for "historical portability":
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   108
    # define "@command" annotation locally, because cmdutil.command
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   109
    # has been available since 1.9 (or 2daa5179e73f)
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   110
    def command(name, options=(), synopsis=None, norepo=False):
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   111
        def decorator(func):
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   112
            if synopsis:
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   113
                cmdtable[name] = func, list(options), synopsis
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   114
            else:
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   115
                cmdtable[name] = func, list(options)
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   116
            if norepo:
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   117
                commands.norepo += ' %s' % ' '.join(parsealiases(name))
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   118
            return func
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   119
        return decorator
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   120
27307
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   121
def getlen(ui):
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   122
    if ui.configbool("perf", "stub"):
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   123
        return lambda x: 1
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   124
    return len
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   125
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   126
def gettimer(ui, opts=None):
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   127
    """return a timer function and formatter: (timer, formatter)
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   128
27303
57bd9c5431a5 perf: improve grammar of gettimer comment
timeless <timeless@mozdev.org>
parents: 27286
diff changeset
   129
    This function exists to gather the creation of formatter in a single
57bd9c5431a5 perf: improve grammar of gettimer comment
timeless <timeless@mozdev.org>
parents: 27286
diff changeset
   130
    place instead of duplicating it in all performance commands."""
23788
316ad725a1dd perf: add a configurable sleep on startup
Matt Mackall <mpm@selenic.com>
parents: 23537
diff changeset
   131
316ad725a1dd perf: add a configurable sleep on startup
Matt Mackall <mpm@selenic.com>
parents: 23537
diff changeset
   132
    # enforce an idle period before execution to counteract power management
25850
b130764e3eb5 perf: mark experimental option presleep
Matt Mackall <mpm@selenic.com>
parents: 25494
diff changeset
   133
    # experimental config: perf.presleep
23788
316ad725a1dd perf: add a configurable sleep on startup
Matt Mackall <mpm@selenic.com>
parents: 23537
diff changeset
   134
    time.sleep(ui.configint("perf", "presleep", 1))
316ad725a1dd perf: add a configurable sleep on startup
Matt Mackall <mpm@selenic.com>
parents: 23537
diff changeset
   135
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   136
    if opts is None:
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   137
        opts = {}
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   138
    # redirect all to stderr
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   139
    ui = ui.copy()
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   140
    ui.fout = ui.ferr
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   141
    # get a formatter
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   142
    fm = ui.formatter('perf', opts)
27304
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   143
    # stub function, runs code only once instead of in a loop
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   144
    # experimental config: perf.stub
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   145
    if ui.configbool("perf", "stub"):
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   146
        return functools.partial(stub_timer, fm), fm
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   147
    return functools.partial(_timer, fm), fm
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   148
27304
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   149
def stub_timer(fm, func, title=None):
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   150
    func()
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   151
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   152
def _timer(fm, func, title=None):
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   153
    results = []
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   154
    begin = time.time()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   155
    count = 0
14494
1ffeeb91c55d check-code: flag 0/1 used as constant Boolean expression
Martin Geisler <mg@lazybytes.net>
parents: 14322
diff changeset
   156
    while True:
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   157
        ostart = os.times()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   158
        cstart = time.time()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   159
        r = func()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   160
        cstop = time.time()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   161
        ostop = os.times()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   162
        count += 1
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   163
        a, b = ostart, ostop
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   164
        results.append((cstop - cstart, b[0] - a[0], b[1]-a[1]))
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   165
        if cstop - begin > 3 and count >= 100:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   166
            break
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   167
        if cstop - begin > 10 and count >= 3:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   168
            break
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   169
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   170
    fm.startitem()
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   171
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   172
    if title:
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   173
        fm.write('title', '! %s\n', title)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   174
    if r:
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   175
        fm.write('result', '! result: %s\n', r)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   176
    m = min(results)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   177
    fm.plain('!')
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   178
    fm.write('wall', ' wall %f', m[0])
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   179
    fm.write('comb', ' comb %f', m[1] + m[2])
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   180
    fm.write('user', ' user %f', m[1])
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   181
    fm.write('sys',  ' sys %f', m[2])
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   182
    fm.write('count',  ' (best of %d)', count)
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   183
    fm.plain('\n')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   184
30143
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   185
# utilities for historical portability
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   186
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   187
def safeattrsetter(obj, name, ignoremissing=False):
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   188
    """Ensure that 'obj' has 'name' attribute before subsequent setattr
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   189
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   190
    This function is aborted, if 'obj' doesn't have 'name' attribute
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   191
    at runtime. This avoids overlooking removal of an attribute, which
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   192
    breaks assumption of performance measurement, in the future.
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   193
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   194
    This function returns the object to (1) assign a new value, and
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   195
    (2) restore an original value to the attribute.
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   196
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   197
    If 'ignoremissing' is true, missing 'name' attribute doesn't cause
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   198
    abortion, and this function returns None. This is useful to
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   199
    examine an attribute, which isn't ensured in all Mercurial
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   200
    versions.
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   201
    """
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   202
    if not util.safehasattr(obj, name):
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   203
        if ignoremissing:
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   204
            return None
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   205
        raise error.Abort(("missing attribute %s of %s might break assumption"
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   206
                           " of performance measurement") % (name, obj))
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   207
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   208
    origvalue = getattr(obj, name)
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   209
    class attrutil(object):
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   210
        def set(self, newvalue):
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   211
            setattr(obj, name, newvalue)
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   212
        def restore(self):
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   213
            setattr(obj, name, origvalue)
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   214
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   215
    return attrutil()
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   216
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   217
# perf commands
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   218
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   219
@command('perfwalk', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   220
def perfwalk(ui, repo, *pats, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   221
    timer, fm = gettimer(ui, opts)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   222
    try:
14671
35c2cc322ba8 scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents: 14494
diff changeset
   223
        m = scmutil.match(repo[None], pats, {})
10176
24ce8f0c0a39 dirstate: don't check state of subrepo directories
Augie Fackler <durin42@gmail.com>
parents: 9932
diff changeset
   224
        timer(lambda: len(list(repo.dirstate.walk(m, [], True, False))))
16689
f366d4c2ff34 cleanup: replace naked excepts with except Exception: ...
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
   225
    except Exception:
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   226
        try:
14671
35c2cc322ba8 scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents: 14494
diff changeset
   227
            m = scmutil.match(repo[None], pats, {})
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10176
diff changeset
   228
            timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)]))
16689
f366d4c2ff34 cleanup: replace naked excepts with except Exception: ...
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
   229
        except Exception:
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   230
            timer(lambda: len(list(cmdutil.walk(repo, pats, {}))))
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   231
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   232
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   233
@command('perfannotate', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   234
def perfannotate(ui, repo, f, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   235
    timer, fm = gettimer(ui, opts)
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 18877
diff changeset
   236
    fc = repo['.'][f]
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 18877
diff changeset
   237
    timer(lambda: len(fc.annotate(True)))
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   238
    fm.end()
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 18877
diff changeset
   239
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   240
@command('perfstatus',
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   241
         [('u', 'unknown', False,
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   242
           'ask status to look for unknown files')] + formatteropts)
18033
00ac420f24ee perf: add option to perfstatus to get the status of unknown files
Siddharth Agarwal <sid0@fb.com>
parents: 17780
diff changeset
   243
def perfstatus(ui, repo, **opts):
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   244
    #m = match.always(repo.root, repo.getcwd())
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16414
diff changeset
   245
    #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False,
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16414
diff changeset
   246
    #                                                False))))
27017
cdc3e437b481 perf: un-bitrot perfstatus
Matt Mackall <mpm@selenic.com>
parents: 26748
diff changeset
   247
    timer, fm = gettimer(ui, opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   248
    timer(lambda: sum(map(len, repo.status(unknown=opts['unknown']))))
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   249
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   250
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   251
@command('perfaddremove', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   252
def perfaddremove(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   253
    timer, fm = gettimer(ui, opts)
18871
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   254
    try:
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   255
        oldquiet = repo.ui.quiet
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   256
        repo.ui.quiet = True
23533
891aaa7c0c70 scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents: 23485
diff changeset
   257
        matcher = scmutil.match(repo[None])
23537
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23533
diff changeset
   258
        timer(lambda: scmutil.addremove(repo, matcher, "", dry_run=True))
18871
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   259
    finally:
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   260
        repo.ui.quiet = oldquiet
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   261
        fm.end()
18871
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   262
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   263
def clearcaches(cl):
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   264
    # behave somewhat consistently across internal API changes
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   265
    if util.safehasattr(cl, 'clearcaches'):
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   266
        cl.clearcaches()
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   267
    elif util.safehasattr(cl, '_nodecache'):
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   268
        from mercurial.node import nullid, nullrev
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   269
        cl._nodecache = {nullid: nullrev}
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   270
        cl._nodepos = None
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   271
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   272
@command('perfheads', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   273
def perfheads(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   274
    timer, fm = gettimer(ui, opts)
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   275
    cl = repo.changelog
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   276
    def d():
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   277
        len(cl.headrevs())
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   278
        clearcaches(cl)
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   279
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   280
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   281
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   282
@command('perftags', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   283
def perftags(ui, repo, **opts):
19786
fe8795dee77d perf: rearrange imports of changelong and manifest to appease check-code
Augie Fackler <raf@durin42.com>
parents: 19712
diff changeset
   284
    import mercurial.changelog
fe8795dee77d perf: rearrange imports of changelong and manifest to appease check-code
Augie Fackler <raf@durin42.com>
parents: 19712
diff changeset
   285
    import mercurial.manifest
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   286
    timer, fm = gettimer(ui, opts)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   287
    def t():
23878
37a92908a382 localrepo: remove all external users of localrepo.sopener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23788
diff changeset
   288
        repo.changelog = mercurial.changelog.changelog(repo.svfs)
37a92908a382 localrepo: remove all external users of localrepo.sopener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23788
diff changeset
   289
        repo.manifest = mercurial.manifest.manifest(repo.svfs)
9146
5614a628d173 localrepo: rename in-memory tag cache instance attributes (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 8873
diff changeset
   290
        repo._tags = None
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   291
        return len(repo.tags())
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   292
    timer(t)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   293
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   294
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   295
@command('perfancestors', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   296
def perfancestors(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   297
    timer, fm = gettimer(ui, opts)
16802
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   298
    heads = repo.changelog.headrevs()
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   299
    def d():
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16858
diff changeset
   300
        for a in repo.changelog.ancestors(heads):
16802
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   301
            pass
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   302
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   303
    fm.end()
16802
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   304
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   305
@command('perfancestorset', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   306
def perfancestorset(ui, repo, revset, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   307
    timer, fm = gettimer(ui, opts)
18080
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   308
    revs = repo.revs(revset)
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   309
    heads = repo.changelog.headrevs()
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   310
    def d():
18091
f7f8159caad3 ancestor: add lazy membership testing to lazyancestors
Siddharth Agarwal <sid0@fb.com>
parents: 18080
diff changeset
   311
        s = repo.changelog.ancestors(heads)
18080
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   312
        for rev in revs:
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   313
            rev in s
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   314
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   315
    fm.end()
18080
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   316
30018
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   317
@command('perfchangegroupchangelog', formatteropts +
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   318
         [('', 'version', '02', 'changegroup version'),
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   319
          ('r', 'rev', '', 'revisions to add to changegroup')])
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   320
def perfchangegroupchangelog(ui, repo, version='02', rev=None, **opts):
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   321
    """Benchmark producing a changelog group for a changegroup.
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   322
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   323
    This measures the time spent processing the changelog during a
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   324
    bundle operation. This occurs during `hg bundle` and on a server
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   325
    processing a `getbundle` wire protocol request (handles clones
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   326
    and pull requests).
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   327
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   328
    By default, all revisions are added to the changegroup.
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   329
    """
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   330
    cl = repo.changelog
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   331
    revs = [cl.lookup(r) for r in repo.revs(rev or 'all()')]
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   332
    bundler = changegroup.getbundler(version, repo)
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   333
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   334
    def lookup(node):
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   335
        # The real bundler reads the revision in order to access the
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   336
        # manifest node and files list. Do that here.
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   337
        cl.read(node)
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   338
        return node
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   339
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   340
    def d():
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   341
        for chunk in bundler.group(revs, cl, lookup):
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   342
            pass
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   343
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   344
    timer, fm = gettimer(ui, opts)
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   345
    timer(d)
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   346
    fm.end()
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   347
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   348
@command('perfdirs', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   349
def perfdirs(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   350
    timer, fm = gettimer(ui, opts)
18845
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   351
    dirstate = repo.dirstate
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   352
    'a' in dirstate
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   353
    def d():
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   354
        dirstate.dirs()
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   355
        del dirstate._dirs
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   356
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   357
    fm.end()
18845
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   358
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   359
@command('perfdirstate', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   360
def perfdirstate(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   361
    timer, fm = gettimer(ui, opts)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   362
    "a" in repo.dirstate
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   363
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   364
        repo.dirstate.invalidate()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   365
        "a" in repo.dirstate
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   366
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   367
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   368
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   369
@command('perfdirstatedirs', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   370
def perfdirstatedirs(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   371
    timer, fm = gettimer(ui, opts)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   372
    "a" in repo.dirstate
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   373
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   374
        "a" in repo.dirstate._dirs
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   375
        del repo.dirstate._dirs
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   376
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   377
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   378
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   379
@command('perfdirstatefoldmap', formatteropts)
27095
aaf4e2d77148 contrib/perf: name functions to match decorators
timeless <timeless@mozdev.org>
parents: 27072
diff changeset
   380
def perfdirstatefoldmap(ui, repo, **opts):
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   381
    timer, fm = gettimer(ui, opts)
22780
d8ff1f671aed perf: add a way to measure the perf of constructing the foldmap
Siddharth Agarwal <sid0@fb.com>
parents: 20846
diff changeset
   382
    dirstate = repo.dirstate
d8ff1f671aed perf: add a way to measure the perf of constructing the foldmap
Siddharth Agarwal <sid0@fb.com>
parents: 20846
diff changeset
   383
    'a' in dirstate
d8ff1f671aed perf: add a way to measure the perf of constructing the foldmap
Siddharth Agarwal <sid0@fb.com>
parents: 20846
diff changeset
   384
    def d():
24607
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   385
        dirstate._filefoldmap.get('a')
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   386
        del dirstate._filefoldmap
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   387
    timer(d)
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   388
    fm.end()
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   389
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   390
@command('perfdirfoldmap', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   391
def perfdirfoldmap(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   392
    timer, fm = gettimer(ui, opts)
24607
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   393
    dirstate = repo.dirstate
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   394
    'a' in dirstate
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   395
    def d():
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   396
        dirstate._dirfoldmap.get('a')
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   397
        del dirstate._dirfoldmap
22780
d8ff1f671aed perf: add a way to measure the perf of constructing the foldmap
Siddharth Agarwal <sid0@fb.com>
parents: 20846
diff changeset
   398
        del dirstate._dirs
d8ff1f671aed perf: add a way to measure the perf of constructing the foldmap
Siddharth Agarwal <sid0@fb.com>
parents: 20846
diff changeset
   399
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   400
    fm.end()
22780
d8ff1f671aed perf: add a way to measure the perf of constructing the foldmap
Siddharth Agarwal <sid0@fb.com>
parents: 20846
diff changeset
   401
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   402
@command('perfdirstatewrite', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   403
def perfdirstatewrite(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   404
    timer, fm = gettimer(ui, opts)
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   405
    ds = repo.dirstate
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   406
    "a" in ds
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   407
    def d():
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   408
        ds._dirty = True
26748
5ba0a99ff27f dirstate: make dirstate.write() callers pass transaction object to it
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25850
diff changeset
   409
        ds.write(repo.currenttransaction())
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   410
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   411
    fm.end()
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   412
18817
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   413
@command('perfmergecalculate',
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   414
         [('r', 'rev', '.', 'rev to merge against')] + formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   415
def perfmergecalculate(ui, repo, rev, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   416
    timer, fm = gettimer(ui, opts)
18817
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   417
    wctx = repo[None]
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   418
    rctx = scmutil.revsingle(repo, rev, rev)
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   419
    ancestor = wctx.ancestor(rctx)
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   420
    # we don't want working dir files to be stat'd in the benchmark, so prime
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   421
    # that cache
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   422
    wctx.dirty()
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   423
    def d():
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   424
        # acceptremote is True because we don't want prompts in the middle of
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   425
        # our benchmark
27098
64cb281d23a5 contrib/perf: fix perfmergecalculate
timeless <timeless@mozdev.org>
parents: 27097
diff changeset
   426
        merge.calculateupdates(repo, wctx, rctx, [ancestor], False, False,
27345
98266b1d144d merge: restate calculateupdates in terms of a matcher
Augie Fackler <augie@google.com>
parents: 27308
diff changeset
   427
                               acceptremote=True, followcopies=True)
18817
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   428
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   429
    fm.end()
18817
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   430
18877
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   431
@command('perfpathcopies', [], "REV REV")
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   432
def perfpathcopies(ui, repo, rev1, rev2, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   433
    timer, fm = gettimer(ui, opts)
18877
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   434
    ctx1 = scmutil.revsingle(repo, rev1, rev1)
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   435
    ctx2 = scmutil.revsingle(repo, rev2, rev2)
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   436
    def d():
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   437
        copies.pathcopies(ctx1, ctx2)
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   438
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   439
    fm.end()
18877
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   440
19712
79e5de2bfa8c perfmanifest: allow and require passing in a rev
Siddharth Agarwal <sid0@fb.com>
parents: 19711
diff changeset
   441
@command('perfmanifest', [], 'REV')
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   442
def perfmanifest(ui, repo, rev, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   443
    timer, fm = gettimer(ui, opts)
19712
79e5de2bfa8c perfmanifest: allow and require passing in a rev
Siddharth Agarwal <sid0@fb.com>
parents: 19711
diff changeset
   444
    ctx = scmutil.revsingle(repo, rev, rev)
79e5de2bfa8c perfmanifest: allow and require passing in a rev
Siddharth Agarwal <sid0@fb.com>
parents: 19711
diff changeset
   445
    t = ctx.manifestnode()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   446
    def d():
27467
fbe292b591ec perf: call clearcaches() in perfmanifest
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27382
diff changeset
   447
        repo.manifest.clearcaches()
19378
9de689d20230 cleanup: drop unused variables and an unused import
Simon Heimberg <simohe@besonet.ch>
parents: 19322
diff changeset
   448
        repo.manifest.read(t)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   449
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   450
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   451
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   452
@command('perfchangeset', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   453
def perfchangeset(ui, repo, rev, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   454
    timer, fm = gettimer(ui, opts)
16262
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   455
    n = repo[rev].node()
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   456
    def d():
19378
9de689d20230 cleanup: drop unused variables and an unused import
Simon Heimberg <simohe@besonet.ch>
parents: 19322
diff changeset
   457
        repo.changelog.read(n)
16266
77d56a5e74a5 perf: add a changeset test
Matt Mackall <mpm@selenic.com>
parents: 16262
diff changeset
   458
        #repo.changelog._cache = None
16262
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   459
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   460
    fm.end()
16262
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   461
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   462
@command('perfindex', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   463
def perfindex(ui, repo, **opts):
13255
2696730ca233 perf: make perfindex results useful on hg with lazyparser
Matt Mackall <mpm@selenic.com>
parents: 13254
diff changeset
   464
    import mercurial.revlog
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   465
    timer, fm = gettimer(ui, opts)
13277
9f707b297b0f perf: restore lazyindex hack
Matt Mackall <mpm@selenic.com>
parents: 13262
diff changeset
   466
    mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
13254
5ef5eb1f3515 revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents: 13253
diff changeset
   467
    n = repo["tip"].node()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   468
    def d():
23878
37a92908a382 localrepo: remove all external users of localrepo.sopener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23788
diff changeset
   469
        cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i")
16260
33fcad3cfbbc perf: tweak tests for testing index performance improvements
Matt Mackall <mpm@selenic.com>
parents: 14671
diff changeset
   470
        cl.rev(n)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   471
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   472
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   473
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   474
@command('perfstartup', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   475
def perfstartup(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   476
    timer, fm = gettimer(ui, opts)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   477
    cmd = sys.argv[0]
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   478
    def d():
27382
de7bcbc68042 perf: adjust perfstartup() for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 27345
diff changeset
   479
        if os.name != 'nt':
de7bcbc68042 perf: adjust perfstartup() for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 27345
diff changeset
   480
            os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
de7bcbc68042 perf: adjust perfstartup() for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 27345
diff changeset
   481
        else:
de7bcbc68042 perf: adjust perfstartup() for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 27345
diff changeset
   482
            os.environ['HGRCPATH'] = ''
de7bcbc68042 perf: adjust perfstartup() for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 27345
diff changeset
   483
            os.system("%s version -q > NUL" % cmd)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   484
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   485
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   486
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   487
@command('perfparents', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   488
def perfparents(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   489
    timer, fm = gettimer(ui, opts)
27305
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
   490
    # control the number of commits perfparents iterates over
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
   491
    # experimental config: perf.parentscount
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
   492
    count = ui.configint("perf", "parentscount", 1000)
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
   493
    if len(repo.changelog) < count:
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
   494
        raise error.Abort("repo needs %d commits for this test" % count)
27100
8d5dba93aa4f contrib/perf: perfparents handle filtered repos
timeless <timeless@mozdev.org>
parents: 27099
diff changeset
   495
    repo = repo.unfiltered()
27305
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
   496
    nl = [repo.changelog.node(i) for i in xrange(count)]
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   497
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   498
        for n in nl:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   499
            repo.changelog.parents(n)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   500
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   501
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   502
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   503
@command('perfctxfiles', formatteropts)
27095
aaf4e2d77148 contrib/perf: name functions to match decorators
timeless <timeless@mozdev.org>
parents: 27072
diff changeset
   504
def perfctxfiles(ui, repo, x, **opts):
24349
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   505
    x = int(x)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   506
    timer, fm = gettimer(ui, opts)
24349
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   507
    def d():
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   508
        len(repo[x].files())
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   509
    timer(d)
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   510
    fm.end()
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   511
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   512
@command('perfrawfiles', formatteropts)
27095
aaf4e2d77148 contrib/perf: name functions to match decorators
timeless <timeless@mozdev.org>
parents: 27072
diff changeset
   513
def perfrawfiles(ui, repo, x, **opts):
24349
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   514
    x = int(x)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   515
    timer, fm = gettimer(ui, opts)
24349
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   516
    cl = repo.changelog
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   517
    def d():
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   518
        len(cl.read(x)[3])
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   519
    timer(d)
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   520
    fm.end()
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   521
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   522
@command('perflookup', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   523
def perflookup(ui, repo, rev, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   524
    timer, fm = gettimer(ui, opts)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   525
    timer(lambda: len(repo.lookup(rev)))
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   526
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   527
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   528
@command('perfrevrange', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   529
def perfrevrange(ui, repo, *specs, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   530
    timer, fm = gettimer(ui, opts)
16858
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
   531
    revrange = scmutil.revrange
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
   532
    timer(lambda: len(revrange(repo, specs)))
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   533
    fm.end()
16858
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
   534
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   535
@command('perfnodelookup', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   536
def perfnodelookup(ui, repo, rev, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   537
    timer, fm = gettimer(ui, opts)
16309
e0c1b3ef7c36 perf: node lookup
Matt Mackall <mpm@selenic.com>
parents: 16266
diff changeset
   538
    import mercurial.revlog
e0c1b3ef7c36 perf: node lookup
Matt Mackall <mpm@selenic.com>
parents: 16266
diff changeset
   539
    mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
e0c1b3ef7c36 perf: node lookup
Matt Mackall <mpm@selenic.com>
parents: 16266
diff changeset
   540
    n = repo[rev].node()
23878
37a92908a382 localrepo: remove all external users of localrepo.sopener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23788
diff changeset
   541
    cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i")
16414
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
   542
    def d():
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
   543
        cl.rev(n)
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   544
        clearcaches(cl)
16414
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
   545
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   546
    fm.end()
16414
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
   547
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   548
@command('perflog',
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   549
         [('', 'rename', False, 'ask log to follow renames')] + formatteropts)
27306
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
   550
def perflog(ui, repo, rev=None, **opts):
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
   551
    if rev is None:
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
   552
        rev=[]
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   553
    timer, fm = gettimer(ui, opts)
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   554
    ui.pushbuffer()
27306
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
   555
    timer(lambda: commands.log(ui, repo, rev=rev, date='', user='',
9932
2fcbef9a349a perf.perflog: add option to follow renames
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9826
diff changeset
   556
                               copies=opts.get('rename')))
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   557
    ui.popbuffer()
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   558
    fm.end()
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   559
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   560
@command('perfmoonwalk', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   561
def perfmoonwalk(ui, repo, **opts):
20178
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
   562
    """benchmark walking the changelog backwards
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
   563
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
   564
    This also loads the changelog data for each revision in the changelog.
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
   565
    """
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   566
    timer, fm = gettimer(ui, opts)
20178
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
   567
    def moonwalk():
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
   568
        for i in xrange(len(repo), -1, -1):
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
   569
            ctx = repo[i]
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
   570
            ctx.branch() # read changelog data (in addition to the index)
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
   571
    timer(moonwalk)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   572
    fm.end()
20178
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
   573
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   574
@command('perftemplating', formatteropts)
27306
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
   575
def perftemplating(ui, repo, rev=None, **opts):
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
   576
    if rev is None:
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
   577
        rev=[]
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   578
    timer, fm = gettimer(ui, opts)
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   579
    ui.pushbuffer()
27306
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
   580
    timer(lambda: commands.log(ui, repo, rev=rev, date='', user='',
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   581
                               template='{date|shortdate} [{rev}:{node|short}]'
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   582
                               ' {author|person}: {desc|firstline}\n'))
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   583
    ui.popbuffer()
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   584
    fm.end()
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   585
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   586
@command('perfcca', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   587
def perfcca(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   588
    timer, fm = gettimer(ui, opts)
17216
01c1ee4bd1dd perf: fix perfcca to work with new casecollisionauditor interface
Joshua Redstone <joshua.redstone@fb.com>
parents: 16866
diff changeset
   589
    timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   590
    fm.end()
16386
ccc173d0914e perf: add case collision auditor perf
Matt Mackall <mpm@selenic.com>
parents: 16309
diff changeset
   591
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   592
@command('perffncacheload', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   593
def perffncacheload(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   594
    timer, fm = gettimer(ui, opts)
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
   595
    s = repo.store
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   596
    def d():
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   597
        s.fncache._load()
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   598
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   599
    fm.end()
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   600
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   601
@command('perffncachewrite', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   602
def perffncachewrite(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   603
    timer, fm = gettimer(ui, opts)
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
   604
    s = repo.store
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   605
    s.fncache._load()
27097
b3e24a9c5f9b contrib/perf: fix perffncachewrite
timeless <timeless@mozdev.org>
parents: 27096
diff changeset
   606
    lock = repo.lock()
b3e24a9c5f9b contrib/perf: fix perffncachewrite
timeless <timeless@mozdev.org>
parents: 27096
diff changeset
   607
    tr = repo.transaction('perffncachewrite')
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   608
    def d():
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   609
        s.fncache._dirty = True
27097
b3e24a9c5f9b contrib/perf: fix perffncachewrite
timeless <timeless@mozdev.org>
parents: 27096
diff changeset
   610
        s.fncache.write(tr)
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   611
    timer(d)
30069
98b9846a131e perf: release lock after transaction in perffncachewrite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30018
diff changeset
   612
    tr.close()
27097
b3e24a9c5f9b contrib/perf: fix perffncachewrite
timeless <timeless@mozdev.org>
parents: 27096
diff changeset
   613
    lock.release()
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   614
    fm.end()
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   615
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   616
@command('perffncacheencode', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   617
def perffncacheencode(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   618
    timer, fm = gettimer(ui, opts)
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
   619
    s = repo.store
17553
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   620
    s.fncache._load()
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   621
    def d():
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   622
        for p in s.fncache.entries:
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   623
            s.encode(p)
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   624
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   625
    fm.end()
17553
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   626
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   627
@command('perfdiffwd', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   628
def perfdiffwd(ui, repo, **opts):
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   629
    """Profile diff of working directory changes"""
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   630
    timer, fm = gettimer(ui, opts)
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   631
    options = {
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   632
        'w': 'ignore_all_space',
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   633
        'b': 'ignore_space_change',
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   634
        'B': 'ignore_blank_lines',
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   635
        }
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   636
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   637
    for diffopt in ('', 'w', 'b', 'B', 'wB'):
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   638
        opts = dict((options[c], '1') for c in diffopt)
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   639
        def d():
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   640
            ui.pushbuffer()
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   641
            commands.diff(ui, repo, **opts)
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   642
            ui.popbuffer()
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   643
        title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   644
        timer(d, title)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   645
    fm.end()
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   646
27492
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
   647
@command('perfrevlog', revlogopts + formatteropts +
27493
14b0930105da perf: make start revision configurable for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27492
diff changeset
   648
         [('d', 'dist', 100, 'distance between the revisions'),
30017
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   649
          ('s', 'startrev', 0, 'revision to start reading at'),
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   650
          ('', 'reverse', False, 'read in reverse')],
27492
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
   651
         '-c|-m|FILE')
30017
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   652
def perfrevlog(ui, repo, file_=None, startrev=0, reverse=False, **opts):
27492
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
   653
    """Benchmark reading a series of revisions from a revlog.
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
   654
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
   655
    By default, we read every ``-d/--dist`` revision from 0 to tip of
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
   656
    the specified revlog.
27493
14b0930105da perf: make start revision configurable for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27492
diff changeset
   657
14b0930105da perf: make start revision configurable for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27492
diff changeset
   658
    The start revision can be defined via ``-s/--startrev``.
27492
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
   659
    """
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   660
    timer, fm = gettimer(ui, opts)
27308
7bc52ac46172 perf: perfrevlog optimize for perf.stub
timeless <timeless@mozdev.org>
parents: 27307
diff changeset
   661
    _len = getlen(ui)
30017
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   662
11694
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   663
    def d():
27492
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
   664
        r = cmdutil.openrevlog(repo, 'perfrevlog', file_, opts)
30017
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   665
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   666
        startrev = 0
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   667
        endrev = _len(r)
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   668
        dist = opts['dist']
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   669
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   670
        if reverse:
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   671
            startrev, endrev = endrev, startrev
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   672
            dist = -1 * dist
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   673
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
   674
        for x in xrange(startrev, endrev, dist):
11694
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   675
            r.revision(r.node(x))
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   676
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   677
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   678
    fm.end()
11694
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   679
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   680
@command('perfrevlogrevision', revlogopts + formatteropts +
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   681
         [('', 'cache', False, 'use caches instead of clearing')],
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   682
         '-c|-m|FILE REV')
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   683
def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   684
    """Benchmark obtaining a revlog revision.
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   685
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   686
    Obtaining a revlog revision consists of roughly the following steps:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   687
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   688
    1. Compute the delta chain
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   689
    2. Obtain the raw chunks for that delta chain
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   690
    3. Decompress each raw chunk
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   691
    4. Apply binary patches to obtain fulltext
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   692
    5. Verify hash of fulltext
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   693
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   694
    This command measures the time spent in each of these phases.
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   695
    """
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   696
    if opts.get('changelog') or opts.get('manifest'):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   697
        file_, rev = None, file_
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   698
    elif rev is None:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   699
        raise error.CommandError('perfrevlogrevision', 'invalid arguments')
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   700
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   701
    r = cmdutil.openrevlog(repo, 'perfrevlogrevision', file_, opts)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   702
    node = r.lookup(rev)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   703
    rev = r.rev(node)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   704
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   705
    def dodeltachain(rev):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   706
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   707
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   708
        r._deltachain(rev)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   709
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   710
    def doread(chain):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   711
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   712
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   713
        r._chunkraw(chain[0], chain[-1])
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   714
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   715
    def dodecompress(data, chain):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   716
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   717
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   718
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   719
        start = r.start
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   720
        length = r.length
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   721
        inline = r._inline
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   722
        iosize = r._io.size
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   723
        buffer = util.buffer
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   724
        offset = start(chain[0])
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   725
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   726
        for rev in chain:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   727
            chunkstart = start(rev)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   728
            if inline:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   729
                chunkstart += (rev + 1) * iosize
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   730
            chunklength = length(rev)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   731
            b = buffer(data, chunkstart - offset, chunklength)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   732
            revlog.decompress(b)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   733
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   734
    def dopatch(text, bins):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   735
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   736
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   737
        mdiff.patches(text, bins)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   738
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   739
    def dohash(text):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   740
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   741
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   742
        r._checkhash(text, node, rev)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   743
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   744
    def dorevision():
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   745
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   746
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   747
        r.revision(node)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   748
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   749
    chain = r._deltachain(rev)[0]
27649
6446e9b37c8b revlog: return offset from _chunkraw()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27526
diff changeset
   750
    data = r._chunkraw(chain[0], chain[-1])[1]
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   751
    bins = r._chunks(chain)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   752
    text = str(bins[0])
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   753
    bins = bins[1:]
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   754
    text = mdiff.patches(text, bins)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   755
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   756
    benches = [
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   757
        (lambda: dorevision(), 'full'),
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   758
        (lambda: dodeltachain(rev), 'deltachain'),
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   759
        (lambda: doread(chain), 'read'),
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   760
        (lambda: dodecompress(data, chain), 'decompress'),
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   761
        (lambda: dopatch(text, bins), 'patch'),
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   762
        (lambda: dohash(text), 'hash'),
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   763
    ]
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   764
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   765
    for fn, title in benches:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   766
        timer, fm = gettimer(ui, opts)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   767
        timer(fn, title=title)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   768
        fm.end()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
   769
18239
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   770
@command('perfrevset',
27072
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
   771
         [('C', 'clear', False, 'clear volatile cache between each call.'),
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
   772
          ('', 'contexts', False, 'obtain changectx for each revision')]
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   773
         + formatteropts, "REVSET")
27072
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
   774
def perfrevset(ui, repo, expr, clear=False, contexts=False, **opts):
18239
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   775
    """benchmark the execution time of a revset
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   776
18644
3e92772d5383 spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents: 18304
diff changeset
   777
    Use the --clean option if need to evaluate the impact of build volatile
18239
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   778
    revisions set cache on the revset execution. Volatile cache hold filtered
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   779
    and obsolete related cache."""
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   780
    timer, fm = gettimer(ui, opts)
18062
1471f5e83686 perf: add a command to measure revset performance
Siddharth Agarwal <sid0@fb.com>
parents: 18033
diff changeset
   781
    def d():
18239
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   782
        if clear:
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   783
            repo.invalidatevolatilesets()
27072
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
   784
        if contexts:
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
   785
            for ctx in repo.set(expr): pass
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
   786
        else:
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
   787
            for r in repo.revs(expr): pass
18062
1471f5e83686 perf: add a command to measure revset performance
Siddharth Agarwal <sid0@fb.com>
parents: 18033
diff changeset
   788
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   789
    fm.end()
18240
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   790
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   791
@command('perfvolatilesets', formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   792
def perfvolatilesets(ui, repo, *names, **opts):
18240
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   793
    """benchmark the computation of various volatile set
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   794
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   795
    Volatile set computes element related to filtering and obsolescence."""
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   796
    timer, fm = gettimer(ui, opts)
18240
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   797
    repo = repo.unfiltered()
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   798
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   799
    def getobs(name):
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   800
        def d():
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   801
            repo.invalidatevolatilesets()
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   802
            obsolete.getrevs(repo, name)
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   803
        return d
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   804
18241
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   805
    allobs = sorted(obsolete.cachefuncs)
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   806
    if names:
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   807
        allobs = [n for n in allobs if n in names]
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   808
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   809
    for name in allobs:
18240
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   810
        timer(getobs(name), title=name)
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   811
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   812
    def getfiltered(name):
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   813
        def d():
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   814
            repo.invalidatevolatilesets()
20205
d67a7758da6d perf: fix perfvolatilesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20178
diff changeset
   815
            repoview.filterrevs(repo, name)
18240
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   816
        return d
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   817
18241
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   818
    allfilter = sorted(repoview.filtertable)
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   819
    if names:
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   820
        allfilter = [n for n in allfilter if n in names]
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   821
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   822
    for name in allfilter:
18240
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   823
        timer(getfiltered(name), title=name)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   824
    fm.end()
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   825
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   826
@command('perfbranchmap',
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   827
         [('f', 'full', False,
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   828
           'Includes build time of subset'),
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   829
         ] + formatteropts)
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   830
def perfbranchmap(ui, repo, full=False, **opts):
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   831
    """benchmark the update of a branchmap
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   832
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   833
    This benchmarks the full repo.branchmap() call with read and write disabled
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   834
    """
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   835
    timer, fm = gettimer(ui, opts)
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   836
    def getbranchmap(filtername):
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   837
        """generate a benchmark function for the filtername"""
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   838
        if filtername is None:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   839
            view = repo
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   840
        else:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   841
            view = repo.filtered(filtername)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   842
        def d():
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   843
            if full:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   844
                view._branchcaches.clear()
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   845
            else:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   846
                view._branchcaches.pop(filtername, None)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   847
            view.branchmap()
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   848
        return d
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   849
    # add filter in smaller subset to bigger subset
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   850
    possiblefilters = set(repoview.filtertable)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   851
    allfilters = []
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   852
    while possiblefilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   853
        for name in possiblefilters:
20032
175c6fd8cacc subsettable: move from repoview to branchmap, the only place it's used
Augie Fackler <raf@durin42.com>
parents: 19786
diff changeset
   854
            subset = branchmap.subsettable.get(name)
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   855
            if subset not in possiblefilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   856
                break
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   857
        else:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   858
            assert False, 'subset cycle %s!' % possiblefilters
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   859
        allfilters.append(name)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   860
        possiblefilters.remove(name)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   861
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   862
    # warm the cache
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   863
    if not full:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   864
        for name in allfilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   865
            repo.filtered(name).branchmap()
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   866
    # add unfiltered
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   867
    allfilters.append(None)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   868
    oldread = branchmap.read
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   869
    oldwrite = branchmap.branchcache.write
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   870
    try:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   871
        branchmap.read = lambda repo: None
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   872
        branchmap.write = lambda repo: None
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   873
        for name in allfilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   874
            timer(getbranchmap(name), title=str(name))
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   875
    finally:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   876
        branchmap.read = oldread
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   877
        branchmap.branchcache.write = oldwrite
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   878
    fm.end()
23485
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
   879
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
   880
@command('perfloadmarkers')
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
   881
def perfloadmarkers(ui, repo):
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
   882
    """benchmark the time to parse the on-disk markers for a repo
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
   883
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
   884
    Result is the number of markers in the repo."""
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
   885
    timer, fm = gettimer(ui)
23878
37a92908a382 localrepo: remove all external users of localrepo.sopener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23788
diff changeset
   886
    timer(lambda: len(obsolete.obsstore(repo.svfs)))
23485
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
   887
    fm.end()
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   888
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   889
@command('perflrucachedict', formatteropts +
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   890
    [('', 'size', 4, 'size of cache'),
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   891
     ('', 'gets', 10000, 'number of key lookups'),
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   892
     ('', 'sets', 10000, 'number of key sets'),
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   893
     ('', 'mixed', 10000, 'number of mixed mode operations'),
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   894
     ('', 'mixedgetfreq', 50, 'frequency of get vs set ops in mixed mode')],
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   895
    norepo=True)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   896
def perflrucache(ui, size=4, gets=10000, sets=10000, mixed=10000,
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   897
                 mixedgetfreq=50, **opts):
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   898
    def doinit():
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   899
        for i in xrange(10000):
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   900
            util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   901
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   902
    values = []
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   903
    for i in xrange(size):
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   904
        values.append(random.randint(0, sys.maxint))
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   905
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   906
    # Get mode fills the cache and tests raw lookup performance with no
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   907
    # eviction.
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   908
    getseq = []
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   909
    for i in xrange(gets):
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   910
        getseq.append(random.choice(values))
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   911
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   912
    def dogets():
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   913
        d = util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   914
        for v in values:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   915
            d[v] = v
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   916
        for key in getseq:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   917
            value = d[key]
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   918
            value # silence pyflakes warning
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   919
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   920
    # Set mode tests insertion speed with cache eviction.
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   921
    setseq = []
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   922
    for i in xrange(sets):
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   923
        setseq.append(random.randint(0, sys.maxint))
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   924
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   925
    def dosets():
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   926
        d = util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   927
        for v in setseq:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   928
            d[v] = v
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   929
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   930
    # Mixed mode randomly performs gets and sets with eviction.
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   931
    mixedops = []
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   932
    for i in xrange(mixed):
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   933
        r = random.randint(0, 100)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   934
        if r < mixedgetfreq:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   935
            op = 0
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   936
        else:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   937
            op = 1
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   938
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   939
        mixedops.append((op, random.randint(0, size * 2)))
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   940
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   941
    def domixed():
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   942
        d = util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   943
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   944
        for op, v in mixedops:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   945
            if op == 0:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   946
                try:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   947
                    d[v]
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   948
                except KeyError:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   949
                    pass
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   950
            else:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   951
                d[v] = v
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   952
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   953
    benches = [
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   954
        (doinit, 'init'),
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   955
        (dogets, 'gets'),
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   956
        (dosets, 'sets'),
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   957
        (domixed, 'mixed')
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   958
    ]
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   959
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   960
    for fn, title in benches:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   961
        timer, fm = gettimer(ui, opts)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   962
        timer(fn, title=title)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
   963
        fm.end()
29495
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   964
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   965
def uisetup(ui):
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   966
    if (util.safehasattr(cmdutil, 'openrevlog') and
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   967
        not util.safehasattr(commands, 'debugrevlogopts')):
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   968
        # for "historical portability":
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   969
        # In this case, Mercurial should be 1.9 (or a79fea6b3e77) -
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   970
        # 3.7 (or 5606f7d0d063). Therefore, '--dir' option for
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   971
        # openrevlog() should cause failure, because it has been
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   972
        # available since 3.5 (or 49c583ca48c4).
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   973
        def openrevlog(orig, repo, cmd, file_, opts):
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   974
            if opts.get('dir') and not util.safehasattr(repo, 'dirlog'):
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   975
                raise error.Abort("This version doesn't support --dir option",
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   976
                                  hint="use 3.5 or later")
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   977
            return orig(repo, cmd, file_, opts)
f83445296213 perf: use locally defined revlog option list for Mercurial earlier than 3.7
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29494
diff changeset
   978
        extensions.wrapfunction(cmdutil, 'openrevlog', openrevlog)