contrib/perf.py
author Boris Feld <boris.feld@octobus.net>
Fri, 25 Jan 2019 18:43:48 -0500
changeset 41460 e9891c734bf8
parent 41459 d65ba1ff4559
child 41461 7eb7637e34bf
permissions -rw-r--r--
perf: add a no-lookup variant to perfindex It is useful to check how long it takes to create a index object without doing anything with it. We add a new flag dedicated to that.
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
40144
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
    22
import contextlib
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    23
import functools
31406
8f5ed8fa39f8 perf: perform a garbage collection before each iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30997
diff changeset
    24
import gc
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    25
import os
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
    26
import random
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
    27
import shutil
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
    28
import struct
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    29
import sys
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
    30
import tempfile
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
    31
import threading
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    32
import time
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    33
from mercurial import (
30020
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
    34
    changegroup,
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    35
    cmdutil,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    36
    commands,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    37
    copies,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    38
    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
    39
    extensions,
40954
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
    40
    hg,
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    41
    mdiff,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    42
    merge,
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
    43
    revlog,
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    44
    util,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    45
)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    46
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
    47
# for "historical portability":
29567
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    48
# 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
    49
# 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
    50
try:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    51
    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
    52
except ImportError:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    53
    pass
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    54
try:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    55
    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
    56
except ImportError:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    57
    pass
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    58
try:
32376
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
    59
    from mercurial import registrar # since 3.7 (or 37d50250b696)
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
    60
    dir(registrar) # forcibly load it
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
    61
except ImportError:
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
    62
    registrar = None
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
    63
try:
29567
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    64
    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
    65
except ImportError:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    66
    pass
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    67
try:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    68
    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
    69
except ImportError:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    70
    pass
40954
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
    71
try:
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
    72
    from mercurial import setdiscovery # since 1.9 (or cb98fed52495)
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
    73
except ImportError:
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
    74
    pass
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
    75
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
    76
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
    77
def identity(a):
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
    78
    return a
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
    79
36216
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35990
diff changeset
    80
try:
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35990
diff changeset
    81
    from mercurial import pycompat
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35990
diff changeset
    82
    getargspec = pycompat.getargspec  # added to module after 4.5
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
    83
    _byteskwargs = pycompat.byteskwargs  # since 4.1 (or fbc3f73dc802)
39826
6787dc1b93a9 py3: handle sysstr conversion around get/set attr in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39779
diff changeset
    84
    _sysstr = pycompat.sysstr         # since 4.0 (or 2219f4f82ede)
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
    85
    _xrange = pycompat.xrange         # since 4.8 (or 7eba8f83129b)
40214
b456b2e0ad9f py3: make test-contrib-perf.t work on python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40145
diff changeset
    86
    fsencode = pycompat.fsencode      # since 3.9 (or f4a5e0e86a7e)
39828
c4ab9fa81377 py3: work around the lack of sys.maxint in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39827
diff changeset
    87
    if pycompat.ispy3:
c4ab9fa81377 py3: work around the lack of sys.maxint in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39827
diff changeset
    88
        _maxint = sys.maxsize  # per py3 docs for replacing maxint
c4ab9fa81377 py3: work around the lack of sys.maxint in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39827
diff changeset
    89
    else:
c4ab9fa81377 py3: work around the lack of sys.maxint in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39827
diff changeset
    90
        _maxint = sys.maxint
36216
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35990
diff changeset
    91
except (ImportError, AttributeError):
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35990
diff changeset
    92
    import inspect
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35990
diff changeset
    93
    getargspec = inspect.getargspec
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
    94
    _byteskwargs = identity
40214
b456b2e0ad9f py3: make test-contrib-perf.t work on python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40145
diff changeset
    95
    fsencode = identity               # no py3 support
39828
c4ab9fa81377 py3: work around the lack of sys.maxint in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39827
diff changeset
    96
    _maxint = sys.maxint              # no py3 support
39826
6787dc1b93a9 py3: handle sysstr conversion around get/set attr in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39779
diff changeset
    97
    _sysstr = lambda x: x             # no py3 support
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
    98
    _xrange = xrange
29567
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    99
37890
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
   100
try:
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
   101
    # 4.7+
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
   102
    queue = pycompat.queue.Queue
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
   103
except (AttributeError, ImportError):
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
   104
    # <4.7.
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
   105
    try:
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
   106
        queue = pycompat.queue
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
   107
    except (AttributeError, ImportError):
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
   108
        queue = util.queue
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
   109
38269
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
   110
try:
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
   111
    from mercurial import logcmdutil
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
   112
    makelogtemplater = logcmdutil.maketemplater
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
   113
except (AttributeError, ImportError):
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
   114
    try:
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
   115
        makelogtemplater = cmdutil.makelogtemplater
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
   116
    except (AttributeError, ImportError):
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
   117
        makelogtemplater = None
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
   118
29567
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
   119
# 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
   120
# 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
   121
# 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
   122
_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
   123
def safehasattr(thing, attr):
39826
6787dc1b93a9 py3: handle sysstr conversion around get/set attr in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39779
diff changeset
   124
    return getattr(thing, _sysstr(attr), _undefined) is not _undefined
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
   125
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
   126
29496
7299370cf304 perf: avoid using formatteropts for Mercurial earlier than 3.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29495
diff changeset
   127
# for "historical portability":
31823
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31483
diff changeset
   128
# define util.timer forcibly, because util.timer has been available
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31483
diff changeset
   129
# since ae5d60bb70c9
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31483
diff changeset
   130
if safehasattr(time, 'perf_counter'):
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31483
diff changeset
   131
    util.timer = time.perf_counter
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   132
elif os.name == b'nt':
31823
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31483
diff changeset
   133
    util.timer = time.clock
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31483
diff changeset
   134
else:
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31483
diff changeset
   135
    util.timer = time.time
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31483
diff changeset
   136
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31483
diff changeset
   137
# for "historical portability":
29496
7299370cf304 perf: avoid using formatteropts for Mercurial earlier than 3.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29495
diff changeset
   138
# 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
   139
# 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
   140
# 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
   141
# available since 2.2 (or ae5f92e154d3)
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32376
diff changeset
   142
formatteropts = getattr(cmdutil, "formatteropts",
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32376
diff changeset
   143
                        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
   144
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
   145
# 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
   146
# 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
   147
# 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
   148
# 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
   149
# since 1.9 (or a79fea6b3e77).
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32376
diff changeset
   150
revlogopts = getattr(cmdutil, "debugrevlogopts",
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32376
diff changeset
   151
                     getattr(commands, "debugrevlogopts", [
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   152
        (b'c', b'changelog', False, (b'open changelog')),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   153
        (b'm', b'manifest', False, (b'open manifest')),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   154
        (b'', b'dir', False, (b'open directory manifest')),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32376
diff changeset
   155
        ]))
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   156
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   157
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
   158
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   159
# 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
   160
# 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
   161
# 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
   162
def parsealiases(cmd):
40295
fa88170c10bb help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents: 40214
diff changeset
   163
    return cmd.split(b"|")
29497
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   164
32376
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
   165
if safehasattr(registrar, 'command'):
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
   166
    command = registrar.command(cmdtable)
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
   167
elif safehasattr(cmdutil, 'command'):
29497
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   168
    command = cmdutil.command(cmdtable)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   169
    if b'norepo' not in getargspec(command).args:
29497
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   170
        # 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
   171
        # 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
   172
        # 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
   173
        _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
   174
        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
   175
            if norepo:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   176
                commands.norepo += b' %s' % b' '.join(parsealiases(name))
29497
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   177
            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
   178
else:
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   179
    # 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
   180
    # 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
   181
    # 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
   182
    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
   183
        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
   184
            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
   185
                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
   186
            else:
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   187
                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
   188
            if norepo:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   189
                commands.norepo += b' %s' % b' '.join(parsealiases(name))
29497
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   190
            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
   191
        return decorator
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   192
34494
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34350
diff changeset
   193
try:
34749
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   194
    import mercurial.registrar
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   195
    import mercurial.configitems
34494
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34350
diff changeset
   196
    configtable = {}
34749
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   197
    configitem = mercurial.registrar.configitem(configtable)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   198
    configitem(b'perf', b'presleep',
34749
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   199
        default=mercurial.configitems.dynamicdefault,
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   200
    )
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   201
    configitem(b'perf', b'stub',
34749
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   202
        default=mercurial.configitems.dynamicdefault,
34494
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34350
diff changeset
   203
    )
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   204
    configitem(b'perf', b'parentscount',
34750
caf6c446cbe3 contrib-perf: register the 'parentscount' config item
Boris Feld <boris.feld@octobus.net>
parents: 34749
diff changeset
   205
        default=mercurial.configitems.dynamicdefault,
caf6c446cbe3 contrib-perf: register the 'parentscount' config item
Boris Feld <boris.feld@octobus.net>
parents: 34749
diff changeset
   206
    )
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   207
    configitem(b'perf', b'all-timing',
38694
55101513ed94 perf: add a 'perf.all-timing' option to display more than best time
Boris Feld <boris.feld@octobus.net>
parents: 38693
diff changeset
   208
        default=mercurial.configitems.dynamicdefault,
55101513ed94 perf: add a 'perf.all-timing' option to display more than best time
Boris Feld <boris.feld@octobus.net>
parents: 38693
diff changeset
   209
    )
34494
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34350
diff changeset
   210
except (ImportError, AttributeError):
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34350
diff changeset
   211
    pass
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34350
diff changeset
   212
27307
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   213
def getlen(ui):
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   214
    if ui.configbool(b"perf", b"stub", False):
27307
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   215
        return lambda x: 1
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   216
    return len
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   217
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   218
def gettimer(ui, opts=None):
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   219
    """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
   220
27303
57bd9c5431a5 perf: improve grammar of gettimer comment
timeless <timeless@mozdev.org>
parents: 27286
diff changeset
   221
    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
   222
    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
   223
316ad725a1dd perf: add a configurable sleep on startup
Matt Mackall <mpm@selenic.com>
parents: 23537
diff changeset
   224
    # 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
   225
    # experimental config: perf.presleep
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   226
    time.sleep(getint(ui, b"perf", b"presleep", 1))
23788
316ad725a1dd perf: add a configurable sleep on startup
Matt Mackall <mpm@selenic.com>
parents: 23537
diff changeset
   227
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   228
    if opts is None:
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   229
        opts = {}
30415
e77e8876886f perf: omit copying ui and redirect to ferr if buffer API is in use
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 30380
diff changeset
   230
    # redirect all to stderr unless buffer api is in use
e77e8876886f perf: omit copying ui and redirect to ferr if buffer API is in use
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 30380
diff changeset
   231
    if not ui._buffers:
e77e8876886f perf: omit copying ui and redirect to ferr if buffer API is in use
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 30380
diff changeset
   232
        ui = ui.copy()
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   233
        uifout = safeattrsetter(ui, b'fout', ignoremissing=True)
30415
e77e8876886f perf: omit copying ui and redirect to ferr if buffer API is in use
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 30380
diff changeset
   234
        if uifout:
e77e8876886f perf: omit copying ui and redirect to ferr if buffer API is in use
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 30380
diff changeset
   235
            # for "historical portability":
e77e8876886f perf: omit copying ui and redirect to ferr if buffer API is in use
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 30380
diff changeset
   236
            # ui.fout/ferr have been available since 1.9 (or 4e1ccd4c2b6d)
e77e8876886f perf: omit copying ui and redirect to ferr if buffer API is in use
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 30380
diff changeset
   237
            uifout.set(ui.ferr)
30147
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   238
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   239
    # get a formatter
30147
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   240
    uiformatter = getattr(ui, 'formatter', None)
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   241
    if uiformatter:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   242
        fm = uiformatter(b'perf', opts)
30147
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   243
    else:
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   244
        # for "historical portability":
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   245
        # define formatter locally, because ui.formatter has been
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   246
        # available since 2.2 (or ae5f92e154d3)
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   247
        from mercurial import node
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   248
        class defaultformatter(object):
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   249
            """Minimized composition of baseformatter and plainformatter
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   250
            """
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   251
            def __init__(self, ui, topic, opts):
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   252
                self._ui = ui
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   253
                if ui.debugflag:
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   254
                    self.hexfunc = node.hex
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   255
                else:
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   256
                    self.hexfunc = node.short
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   257
            def __nonzero__(self):
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   258
                return False
31483
413b44003462 py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31406
diff changeset
   259
            __bool__ = __nonzero__
30147
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   260
            def startitem(self):
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   261
                pass
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   262
            def data(self, **data):
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   263
                pass
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   264
            def write(self, fields, deftext, *fielddata, **opts):
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   265
                self._ui.write(deftext % fielddata, **opts)
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   266
            def condwrite(self, cond, fields, deftext, *fielddata, **opts):
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   267
                if cond:
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   268
                    self._ui.write(deftext % fielddata, **opts)
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   269
            def plain(self, text, **opts):
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   270
                self._ui.write(text, **opts)
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   271
            def end(self):
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   272
                pass
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   273
        fm = defaultformatter(ui, b'perf', opts)
30147
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   274
27304
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   275
    # 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
   276
    # experimental config: perf.stub
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   277
    if ui.configbool(b"perf", b"stub", False):
27304
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   278
        return functools.partial(stub_timer, fm), fm
38694
55101513ed94 perf: add a 'perf.all-timing' option to display more than best time
Boris Feld <boris.feld@octobus.net>
parents: 38693
diff changeset
   279
55101513ed94 perf: add a 'perf.all-timing' option to display more than best time
Boris Feld <boris.feld@octobus.net>
parents: 38693
diff changeset
   280
    # experimental config: perf.all-timing
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   281
    displayall = ui.configbool(b"perf", b"all-timing", False)
38694
55101513ed94 perf: add a 'perf.all-timing' option to display more than best time
Boris Feld <boris.feld@octobus.net>
parents: 38693
diff changeset
   282
    return functools.partial(_timer, fm, displayall=displayall), fm
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   283
40719
9d88ae5c635b perf: add a `setup` argument to run code outside of the timed section
Boris Feld <boris.feld@octobus.net>
parents: 40718
diff changeset
   284
def stub_timer(fm, func, setup=None, title=None):
40760
0adc2c0a0792 perf: run 'setup' function during stub run
Boris Feld <boris.feld@octobus.net>
parents: 40759
diff changeset
   285
    if setup is not None:
0adc2c0a0792 perf: run 'setup' function during stub run
Boris Feld <boris.feld@octobus.net>
parents: 40759
diff changeset
   286
        setup()
27304
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   287
    func()
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   288
40144
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   289
@contextlib.contextmanager
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   290
def timeone():
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   291
    r = []
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   292
    ostart = os.times()
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   293
    cstart = util.timer()
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   294
    yield r
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   295
    cstop = util.timer()
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   296
    ostop = os.times()
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   297
    a, b = ostart, ostop
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   298
    r.append((cstop - cstart, b[0] - a[0], b[1]-a[1]))
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   299
40719
9d88ae5c635b perf: add a `setup` argument to run code outside of the timed section
Boris Feld <boris.feld@octobus.net>
parents: 40718
diff changeset
   300
def _timer(fm, func, setup=None, title=None, displayall=False):
31406
8f5ed8fa39f8 perf: perform a garbage collection before each iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30997
diff changeset
   301
    gc.collect()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   302
    results = []
30995
22fbca1d11ed mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents: 30914
diff changeset
   303
    begin = util.timer()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   304
    count = 0
14494
1ffeeb91c55d check-code: flag 0/1 used as constant Boolean expression
Martin Geisler <mg@lazybytes.net>
parents: 14322
diff changeset
   305
    while True:
40719
9d88ae5c635b perf: add a `setup` argument to run code outside of the timed section
Boris Feld <boris.feld@octobus.net>
parents: 40718
diff changeset
   306
        if setup is not None:
9d88ae5c635b perf: add a `setup` argument to run code outside of the timed section
Boris Feld <boris.feld@octobus.net>
parents: 40718
diff changeset
   307
            setup()
40144
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   308
        with timeone() as item:
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   309
            r = func()
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   310
        count += 1
acf560bc9b56 perf: extract the timing of a section in a context manager
Boris Feld <boris.feld@octobus.net>
parents: 40143
diff changeset
   311
        results.append(item[0])
30995
22fbca1d11ed mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents: 30914
diff changeset
   312
        cstop = util.timer()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   313
        if cstop - begin > 3 and count >= 100:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   314
            break
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   315
        if cstop - begin > 10 and count >= 3:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   316
            break
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   317
40145
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   318
    formatone(fm, results, title=title, result=r,
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   319
              displayall=displayall)
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   320
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   321
def formatone(fm, timings, title=None, result=None, displayall=False):
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   322
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   323
    count = len(timings)
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   324
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   325
    fm.startitem()
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   326
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   327
    if title:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   328
        fm.write(b'title', b'! %s\n', title)
40145
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   329
    if result:
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   330
        fm.write(b'result', b'! result: %s\n', result)
38694
55101513ed94 perf: add a 'perf.all-timing' option to display more than best time
Boris Feld <boris.feld@octobus.net>
parents: 38693
diff changeset
   331
    def display(role, entry):
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   332
        prefix = b''
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   333
        if role != b'best':
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   334
            prefix = b'%s.' % role
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   335
        fm.plain(b'!')
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   336
        fm.write(prefix + b'wall', b' wall %f', entry[0])
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   337
        fm.write(prefix + b'comb', b' comb %f', entry[1] + entry[2])
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   338
        fm.write(prefix + b'user', b' user %f', entry[1])
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   339
        fm.write(prefix + b'sys',  b' sys %f', entry[2])
40141
8643219146e1 perf: fix -T json
Boris Feld <boris.feld@octobus.net>
parents: 39830
diff changeset
   340
        fm.write(prefix + b'count',  b' (%s of %%d)' % role, count)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   341
        fm.plain(b'\n')
40145
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   342
    timings.sort()
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   343
    min_val = timings[0]
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   344
    display(b'best', min_val)
38694
55101513ed94 perf: add a 'perf.all-timing' option to display more than best time
Boris Feld <boris.feld@octobus.net>
parents: 38693
diff changeset
   345
    if displayall:
40145
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   346
        max_val = timings[-1]
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   347
        display(b'max', max_val)
40145
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   348
        avg = tuple([sum(x) / count for x in zip(*timings)])
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   349
        display(b'avg', avg)
40145
21261fc0fb2b perf: extract result formatting in its own function
Boris Feld <boris.feld@octobus.net>
parents: 40144
diff changeset
   350
        median = timings[len(timings) // 2]
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   351
        display(b'median', median)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   352
30143
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   353
# utilities for historical portability
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   354
30149
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30148
diff changeset
   355
def getint(ui, section, name, default):
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30148
diff changeset
   356
    # for "historical portability":
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30148
diff changeset
   357
    # ui.configint has been available since 1.9 (or fa2b596db182)
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30148
diff changeset
   358
    v = ui.config(section, name, None)
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30148
diff changeset
   359
    if v is None:
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30148
diff changeset
   360
        return default
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30148
diff changeset
   361
    try:
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30148
diff changeset
   362
        return int(v)
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30148
diff changeset
   363
    except ValueError:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   364
        raise error.ConfigError((b"%s.%s is not an integer ('%s')")
30149
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30148
diff changeset
   365
                                % (section, name, v))
d8a2c536dd96 perf: replace ui.configint() by getint() for Mercurial earlier than 1.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30148
diff changeset
   366
30143
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   367
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
   368
    """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
   369
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   370
    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
   371
    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
   372
    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
   373
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   374
    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
   375
    (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
   376
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   377
    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
   378
    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
   379
    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
   380
    versions.
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   381
    """
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   382
    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
   383
        if ignoremissing:
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   384
            return None
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   385
        raise error.Abort((b"missing attribute %s of %s might break assumption"
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   386
                           b" of performance measurement") % (name, obj))
30143
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   387
39826
6787dc1b93a9 py3: handle sysstr conversion around get/set attr in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39779
diff changeset
   388
    origvalue = getattr(obj, _sysstr(name))
30143
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   389
    class attrutil(object):
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   390
        def set(self, newvalue):
39826
6787dc1b93a9 py3: handle sysstr conversion around get/set attr in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39779
diff changeset
   391
            setattr(obj, _sysstr(name), newvalue)
30143
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   392
        def restore(self):
39826
6787dc1b93a9 py3: handle sysstr conversion around get/set attr in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39779
diff changeset
   393
            setattr(obj, _sysstr(name), origvalue)
30143
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   394
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   395
    return attrutil()
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   396
30144
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   397
# utilities to examine each internal API changes
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   398
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   399
def getbranchmapsubsettable():
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   400
    # for "historical portability":
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   401
    # subsettable is defined in:
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   402
    # - branchmap since 2.9 (or 175c6fd8cacc)
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   403
    # - repoview since 2.5 (or 59a9f18d4587)
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   404
    for mod in (branchmap, repoview):
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   405
        subsettable = getattr(mod, 'subsettable', None)
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   406
        if subsettable:
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   407
            return subsettable
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   408
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   409
    # bisecting in bcee63733aad::59a9f18d4587 can reach here (both
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   410
    # branchmap and repoview modules exist, but subsettable attribute
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   411
    # doesn't)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   412
    raise error.Abort((b"perfbranchmap not available with this Mercurial"),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   413
                      hint=b"use 2.5 or later")
30144
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   414
30146
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   415
def getsvfs(repo):
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   416
    """Return appropriate object to access files under .hg/store
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   417
    """
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   418
    # for "historical portability":
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   419
    # repo.svfs has been available since 2.3 (or 7034365089bf)
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   420
    svfs = getattr(repo, 'svfs', None)
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   421
    if svfs:
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   422
        return svfs
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   423
    else:
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   424
        return getattr(repo, 'sopener')
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   425
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   426
def getvfs(repo):
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   427
    """Return appropriate object to access files under .hg
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   428
    """
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   429
    # for "historical portability":
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   430
    # repo.vfs has been available since 2.3 (or 7034365089bf)
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   431
    vfs = getattr(repo, 'vfs', None)
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   432
    if vfs:
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   433
        return vfs
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   434
    else:
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   435
        return getattr(repo, 'opener')
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
   436
30150
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   437
def repocleartagscachefunc(repo):
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   438
    """Return the function to clear tags cache according to repo internal API
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   439
    """
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   440
    if util.safehasattr(repo, b'_tagscache'): # since 2.0 (or 9dca7653b525)
30150
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   441
        # in this case, setattr(repo, '_tagscache', None) or so isn't
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   442
        # correct way to clear tags cache, because existing code paths
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   443
        # expect _tagscache to be a structured object.
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   444
        def clearcache():
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   445
            # _tagscache has been filteredpropertycache since 2.5 (or
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   446
            # 98c867ac1330), and delattr() can't work in such case
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   447
            if b'_tagscache' in vars(repo):
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   448
                del repo.__dict__[b'_tagscache']
30150
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   449
        return clearcache
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   450
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   451
    repotags = safeattrsetter(repo, b'_tags', ignoremissing=True)
30150
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   452
    if repotags: # since 1.4 (or 5614a628d173)
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   453
        return lambda : repotags.set(None)
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   454
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   455
    repotagscache = safeattrsetter(repo, b'tagscache', ignoremissing=True)
30150
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   456
    if repotagscache: # since 0.6 (or d7df759d0e97)
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   457
        return lambda : repotagscache.set(None)
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   458
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   459
    # Mercurial earlier than 0.6 (or d7df759d0e97) logically reaches
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   460
    # this point, but it isn't so problematic, because:
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   461
    # - repo.tags of such Mercurial isn't "callable", and repo.tags()
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   462
    #   in perftags() causes failure soon
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   463
    # - perf.py itself has been available since 1.1 (or eb240755386d)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   464
    raise error.Abort((b"tags API of this hg command is unknown"))
30150
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   465
32751
6f791ca70640 perf: have a generic "clearstorecache" function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32730
diff changeset
   466
# utilities to clear cache
6f791ca70640 perf: have a generic "clearstorecache" function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32730
diff changeset
   467
40722
d7936a9dad47 perf: make `clearfilecache` helper work with any object
Boris Feld <boris.feld@octobus.net>
parents: 40721
diff changeset
   468
def clearfilecache(obj, attrname):
d7936a9dad47 perf: make `clearfilecache` helper work with any object
Boris Feld <boris.feld@octobus.net>
parents: 40721
diff changeset
   469
    unfiltered = getattr(obj, 'unfiltered', None)
d7936a9dad47 perf: make `clearfilecache` helper work with any object
Boris Feld <boris.feld@octobus.net>
parents: 40721
diff changeset
   470
    if unfiltered is not None:
d7936a9dad47 perf: make `clearfilecache` helper work with any object
Boris Feld <boris.feld@octobus.net>
parents: 40721
diff changeset
   471
        obj = obj.unfiltered()
d7936a9dad47 perf: make `clearfilecache` helper work with any object
Boris Feld <boris.feld@octobus.net>
parents: 40721
diff changeset
   472
    if attrname in vars(obj):
d7936a9dad47 perf: make `clearfilecache` helper work with any object
Boris Feld <boris.feld@octobus.net>
parents: 40721
diff changeset
   473
        delattr(obj, attrname)
d7936a9dad47 perf: make `clearfilecache` helper work with any object
Boris Feld <boris.feld@octobus.net>
parents: 40721
diff changeset
   474
    obj._filecache.pop(attrname, None)
32751
6f791ca70640 perf: have a generic "clearstorecache" function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32730
diff changeset
   475
40740
e4ea63855d5a perf: introduce a function to fully "unload" a changelog
Boris Feld <boris.feld@octobus.net>
parents: 40739
diff changeset
   476
def clearchangelog(repo):
e4ea63855d5a perf: introduce a function to fully "unload" a changelog
Boris Feld <boris.feld@octobus.net>
parents: 40739
diff changeset
   477
    if repo is not repo.unfiltered():
e4ea63855d5a perf: introduce a function to fully "unload" a changelog
Boris Feld <boris.feld@octobus.net>
parents: 40739
diff changeset
   478
        object.__setattr__(repo, r'_clcachekey', None)
e4ea63855d5a perf: introduce a function to fully "unload" a changelog
Boris Feld <boris.feld@octobus.net>
parents: 40739
diff changeset
   479
        object.__setattr__(repo, r'_clcache', None)
e4ea63855d5a perf: introduce a function to fully "unload" a changelog
Boris Feld <boris.feld@octobus.net>
parents: 40739
diff changeset
   480
    clearfilecache(repo.unfiltered(), 'changelog')
e4ea63855d5a perf: introduce a function to fully "unload" a changelog
Boris Feld <boris.feld@octobus.net>
parents: 40739
diff changeset
   481
30143
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   482
# perf commands
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   483
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   484
@command(b'perfwalk', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   485
def perfwalk(ui, repo, *pats, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   486
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   487
    timer, fm = gettimer(ui, opts)
34349
b3538c03a804 perf: remove fallbacks to ancient versions of dirstate.walk()
Martin von Zweigbergk <martinvonz@google.com>
parents: 32906
diff changeset
   488
    m = scmutil.match(repo[None], pats, {})
34350
255c761a52db dirstate: use keyword arguments to clarify walk()'s callers
Martin von Zweigbergk <martinvonz@google.com>
parents: 34349
diff changeset
   489
    timer(lambda: len(list(repo.dirstate.walk(m, subrepos=[], unknown=True,
255c761a52db dirstate: use keyword arguments to clarify walk()'s callers
Martin von Zweigbergk <martinvonz@google.com>
parents: 34349
diff changeset
   490
                                              ignored=False))))
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   491
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   492
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   493
@command(b'perfannotate', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   494
def perfannotate(ui, repo, f, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   495
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   496
    timer, fm = gettimer(ui, opts)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   497
    fc = repo[b'.'][f]
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 18877
diff changeset
   498
    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
   499
    fm.end()
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 18877
diff changeset
   500
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   501
@command(b'perfstatus',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   502
         [(b'u', b'unknown', False,
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   503
           b'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
   504
def perfstatus(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   505
    opts = _byteskwargs(opts)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   506
    #m = match.always(repo.root, repo.getcwd())
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16414
diff changeset
   507
    #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
   508
    #                                                False))))
27017
cdc3e437b481 perf: un-bitrot perfstatus
Matt Mackall <mpm@selenic.com>
parents: 26748
diff changeset
   509
    timer, fm = gettimer(ui, opts)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   510
    timer(lambda: sum(map(len, repo.status(unknown=opts[b'unknown']))))
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   511
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   512
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   513
@command(b'perfaddremove', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   514
def perfaddremove(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   515
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   516
    timer, fm = gettimer(ui, opts)
18871
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   517
    try:
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   518
        oldquiet = repo.ui.quiet
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   519
        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
   520
        matcher = scmutil.match(repo[None])
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   521
        opts[b'dry_run'] = True
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   522
        timer(lambda: scmutil.addremove(repo, matcher, b"", opts))
18871
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   523
    finally:
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   524
        repo.ui.quiet = oldquiet
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   525
        fm.end()
18871
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   526
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   527
def clearcaches(cl):
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   528
    # behave somewhat consistently across internal API changes
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   529
    if util.safehasattr(cl, b'clearcaches'):
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   530
        cl.clearcaches()
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   531
    elif util.safehasattr(cl, b'_nodecache'):
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   532
        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
   533
        cl._nodecache = {nullid: nullrev}
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   534
        cl._nodepos = None
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   535
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   536
@command(b'perfheads', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   537
def perfheads(ui, repo, **opts):
41456
48394923fbdc perf: document perfheads
Boris Feld <boris.feld@octobus.net>
parents: 41387
diff changeset
   538
    """benchmark the computation of a changelog heads"""
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   539
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   540
    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
   541
    cl = repo.changelog
41458
ab6d1f82be32 perf: move cache clearing in the `setup` step of `perfheads`
Boris Feld <boris.feld@octobus.net>
parents: 41456
diff changeset
   542
    def s():
ab6d1f82be32 perf: move cache clearing in the `setup` step of `perfheads`
Boris Feld <boris.feld@octobus.net>
parents: 41456
diff changeset
   543
        clearcaches(cl)
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   544
    def d():
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   545
        len(cl.headrevs())
41458
ab6d1f82be32 perf: move cache clearing in the `setup` step of `perfheads`
Boris Feld <boris.feld@octobus.net>
parents: 41456
diff changeset
   546
    timer(d, setup=s)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   547
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   548
40778
594e84a2e574 perf: add a `clear-revlogs` flag to `perftags`
Boris Feld <boris.feld@octobus.net>
parents: 40777
diff changeset
   549
@command(b'perftags', formatteropts+
594e84a2e574 perf: add a `clear-revlogs` flag to `perftags`
Boris Feld <boris.feld@octobus.net>
parents: 40777
diff changeset
   550
        [
40781
380a1f73830f perf: disable revlogs clearing in `perftags` by default
Boris Feld <boris.feld@octobus.net>
parents: 40780
diff changeset
   551
            (b'', b'clear-revlogs', False, b'refresh changelog and manifest'),
40778
594e84a2e574 perf: add a `clear-revlogs` flag to `perftags`
Boris Feld <boris.feld@octobus.net>
parents: 40777
diff changeset
   552
        ])
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   553
def perftags(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   554
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   555
    timer, fm = gettimer(ui, opts)
30150
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   556
    repocleartagscache = repocleartagscachefunc(repo)
40778
594e84a2e574 perf: add a `clear-revlogs` flag to `perftags`
Boris Feld <boris.feld@octobus.net>
parents: 40777
diff changeset
   557
    clearrevlogs = opts[b'clear_revlogs']
40721
4369c00a8ee1 perf: move some of the perftags benchmark to the setup function
Boris Feld <boris.feld@octobus.net>
parents: 40720
diff changeset
   558
    def s():
40778
594e84a2e574 perf: add a `clear-revlogs` flag to `perftags`
Boris Feld <boris.feld@octobus.net>
parents: 40777
diff changeset
   559
        if clearrevlogs:
594e84a2e574 perf: add a `clear-revlogs` flag to `perftags`
Boris Feld <boris.feld@octobus.net>
parents: 40777
diff changeset
   560
            clearchangelog(repo)
594e84a2e574 perf: add a `clear-revlogs` flag to `perftags`
Boris Feld <boris.feld@octobus.net>
parents: 40777
diff changeset
   561
            clearfilecache(repo.unfiltered(), 'manifest')
30150
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   562
        repocleartagscache()
40721
4369c00a8ee1 perf: move some of the perftags benchmark to the setup function
Boris Feld <boris.feld@octobus.net>
parents: 40720
diff changeset
   563
    def t():
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   564
        return len(repo.tags())
40721
4369c00a8ee1 perf: move some of the perftags benchmark to the setup function
Boris Feld <boris.feld@octobus.net>
parents: 40720
diff changeset
   565
    timer(t, setup=s)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   566
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   567
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   568
@command(b'perfancestors', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   569
def perfancestors(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   570
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   571
    timer, fm = gettimer(ui, opts)
16802
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   572
    heads = repo.changelog.headrevs()
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   573
    def d():
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16858
diff changeset
   574
        for a in repo.changelog.ancestors(heads):
16802
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   575
            pass
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   576
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   577
    fm.end()
16802
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   578
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   579
@command(b'perfancestorset', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   580
def perfancestorset(ui, repo, revset, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   581
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   582
    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
   583
    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
   584
    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
   585
    def d():
18091
f7f8159caad3 ancestor: add lazy membership testing to lazyancestors
Siddharth Agarwal <sid0@fb.com>
parents: 18080
diff changeset
   586
        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
   587
        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
   588
            rev in s
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   589
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   590
    fm.end()
18080
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   591
40954
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   592
@command(b'perfdiscovery', formatteropts, b'PATH')
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   593
def perfdiscovery(ui, repo, path, **opts):
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   594
    """benchmark discovery between local repo and the peer at given path
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   595
    """
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   596
    repos = [repo, None]
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   597
    timer, fm = gettimer(ui, opts)
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   598
    path = ui.expandpath(path)
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   599
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   600
    def s():
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   601
        repos[1] = hg.peer(ui, opts, path)
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   602
    def d():
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   603
        setdiscovery.findcommonheads(ui, *repos)
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   604
    timer(d, setup=s)
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   605
    fm.end()
db6cace18765 perfdiscovery: benching findcommonheads()
Georges Racinet <gracinet@anybox.fr>
parents: 40943
diff changeset
   606
40780
82c189c511bd perf: add a `clear-revlogs` flag to `perfbookmarks`
Boris Feld <boris.feld@octobus.net>
parents: 40778
diff changeset
   607
@command(b'perfbookmarks', formatteropts +
82c189c511bd perf: add a `clear-revlogs` flag to `perfbookmarks`
Boris Feld <boris.feld@octobus.net>
parents: 40778
diff changeset
   608
        [
82c189c511bd perf: add a `clear-revlogs` flag to `perfbookmarks`
Boris Feld <boris.feld@octobus.net>
parents: 40778
diff changeset
   609
            (b'', b'clear-revlogs', False, b'refresh changelog and manifest'),
82c189c511bd perf: add a `clear-revlogs` flag to `perfbookmarks`
Boris Feld <boris.feld@octobus.net>
parents: 40778
diff changeset
   610
        ])
32753
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32752
diff changeset
   611
def perfbookmarks(ui, repo, **opts):
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32752
diff changeset
   612
    """benchmark parsing bookmarks from disk to memory"""
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   613
    opts = _byteskwargs(opts)
32753
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32752
diff changeset
   614
    timer, fm = gettimer(ui, opts)
40720
c0a1686d9391 perf: use the new setup function in "perfbookmarks"
Boris Feld <boris.feld@octobus.net>
parents: 40719
diff changeset
   615
40780
82c189c511bd perf: add a `clear-revlogs` flag to `perfbookmarks`
Boris Feld <boris.feld@octobus.net>
parents: 40778
diff changeset
   616
    clearrevlogs = opts[b'clear_revlogs']
40720
c0a1686d9391 perf: use the new setup function in "perfbookmarks"
Boris Feld <boris.feld@octobus.net>
parents: 40719
diff changeset
   617
    def s():
40780
82c189c511bd perf: add a `clear-revlogs` flag to `perfbookmarks`
Boris Feld <boris.feld@octobus.net>
parents: 40778
diff changeset
   618
        if clearrevlogs:
82c189c511bd perf: add a `clear-revlogs` flag to `perfbookmarks`
Boris Feld <boris.feld@octobus.net>
parents: 40778
diff changeset
   619
            clearchangelog(repo)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   620
        clearfilecache(repo, b'_bookmarks')
40720
c0a1686d9391 perf: use the new setup function in "perfbookmarks"
Boris Feld <boris.feld@octobus.net>
parents: 40719
diff changeset
   621
    def d():
32753
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32752
diff changeset
   622
        repo._bookmarks
40720
c0a1686d9391 perf: use the new setup function in "perfbookmarks"
Boris Feld <boris.feld@octobus.net>
parents: 40719
diff changeset
   623
    timer(d, setup=s)
32753
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32752
diff changeset
   624
    fm.end()
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32752
diff changeset
   625
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   626
@command(b'perfbundleread', formatteropts, b'BUNDLE')
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   627
def perfbundleread(ui, repo, bundlepath, **opts):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   628
    """Benchmark reading of bundle files.
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   629
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   630
    This command is meant to isolate the I/O part of bundle reading as
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   631
    much as possible.
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   632
    """
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   633
    from mercurial import (
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   634
        bundle2,
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   635
        exchange,
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   636
        streamclone,
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   637
    )
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   638
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   639
    opts = _byteskwargs(opts)
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   640
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   641
    def makebench(fn):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   642
        def run():
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   643
            with open(bundlepath, b'rb') as fh:
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   644
                bundle = exchange.readbundle(ui, fh, bundlepath)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   645
                fn(bundle)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   646
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   647
        return run
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   648
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   649
    def makereadnbytes(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   650
        def run():
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   651
            with open(bundlepath, b'rb') as fh:
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   652
                bundle = exchange.readbundle(ui, fh, bundlepath)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   653
                while bundle.read(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   654
                    pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   655
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   656
        return run
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   657
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   658
    def makestdioread(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   659
        def run():
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   660
            with open(bundlepath, b'rb') as fh:
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   661
                while fh.read(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   662
                    pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   663
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   664
        return run
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   665
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   666
    # bundle1
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   667
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   668
    def deltaiter(bundle):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   669
        for delta in bundle.deltaiter():
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   670
            pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   671
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   672
    def iterchunks(bundle):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   673
        for chunk in bundle.getchunks():
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   674
            pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   675
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   676
    # bundle2
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   677
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   678
    def forwardchunks(bundle):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   679
        for chunk in bundle._forwardchunks():
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   680
            pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   681
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   682
    def iterparts(bundle):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   683
        for part in bundle.iterparts():
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   684
            pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   685
35137
da91e7309daf bundle2: don't use seekable bundle2 parts by default (issue5691)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35132
diff changeset
   686
    def iterpartsseekable(bundle):
da91e7309daf bundle2: don't use seekable bundle2 parts by default (issue5691)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35132
diff changeset
   687
        for part in bundle.iterparts(seekable=True):
da91e7309daf bundle2: don't use seekable bundle2 parts by default (issue5691)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35132
diff changeset
   688
            pass
da91e7309daf bundle2: don't use seekable bundle2 parts by default (issue5691)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35132
diff changeset
   689
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   690
    def seek(bundle):
35137
da91e7309daf bundle2: don't use seekable bundle2 parts by default (issue5691)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35132
diff changeset
   691
        for part in bundle.iterparts(seekable=True):
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   692
            part.seek(0, os.SEEK_END)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   693
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   694
    def makepartreadnbytes(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   695
        def run():
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   696
            with open(bundlepath, b'rb') as fh:
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   697
                bundle = exchange.readbundle(ui, fh, bundlepath)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   698
                for part in bundle.iterparts():
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   699
                    while part.read(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   700
                        pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   701
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   702
        return run
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   703
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   704
    benches = [
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   705
        (makestdioread(8192), b'read(8k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   706
        (makestdioread(16384), b'read(16k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   707
        (makestdioread(32768), b'read(32k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   708
        (makestdioread(131072), b'read(128k)'),
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   709
    ]
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   710
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   711
    with open(bundlepath, b'rb') as fh:
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   712
        bundle = exchange.readbundle(ui, fh, bundlepath)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   713
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   714
        if isinstance(bundle, changegroup.cg1unpacker):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   715
            benches.extend([
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   716
                (makebench(deltaiter), b'cg1 deltaiter()'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   717
                (makebench(iterchunks), b'cg1 getchunks()'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   718
                (makereadnbytes(8192), b'cg1 read(8k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   719
                (makereadnbytes(16384), b'cg1 read(16k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   720
                (makereadnbytes(32768), b'cg1 read(32k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   721
                (makereadnbytes(131072), b'cg1 read(128k)'),
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   722
            ])
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   723
        elif isinstance(bundle, bundle2.unbundle20):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   724
            benches.extend([
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   725
                (makebench(forwardchunks), b'bundle2 forwardchunks()'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   726
                (makebench(iterparts), b'bundle2 iterparts()'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   727
                (makebench(iterpartsseekable), b'bundle2 iterparts() seekable'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   728
                (makebench(seek), b'bundle2 part seek()'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   729
                (makepartreadnbytes(8192), b'bundle2 part read(8k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   730
                (makepartreadnbytes(16384), b'bundle2 part read(16k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   731
                (makepartreadnbytes(32768), b'bundle2 part read(32k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   732
                (makepartreadnbytes(131072), b'bundle2 part read(128k)'),
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   733
            ])
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   734
        elif isinstance(bundle, streamclone.streamcloneapplier):
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   735
            raise error.Abort(b'stream clone bundles not supported')
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   736
        else:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   737
            raise error.Abort(b'unhandled bundle type: %s' % type(bundle))
35132
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   738
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   739
    for fn, title in benches:
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   740
        timer, fm = gettimer(ui, opts)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   741
        timer(fn, title=title)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   742
        fm.end()
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35107
diff changeset
   743
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   744
@command(b'perfchangegroupchangelog', formatteropts +
40752
cfaf3843491b perf: rename version flag of perfchangegroupchangelog to cgversion
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40741
diff changeset
   745
         [(b'', b'cgversion', b'02', b'changegroup version'),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   746
          (b'r', b'rev', b'', b'revisions to add to changegroup')])
40752
cfaf3843491b perf: rename version flag of perfchangegroupchangelog to cgversion
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40741
diff changeset
   747
def perfchangegroupchangelog(ui, repo, cgversion=b'02', rev=None, **opts):
30020
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   748
    """Benchmark producing a changelog group for a changegroup.
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   749
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   750
    This measures the time spent processing the changelog during a
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   751
    bundle operation. This occurs during `hg bundle` and on a server
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   752
    processing a `getbundle` wire protocol request (handles clones
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   753
    and pull requests).
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   754
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   755
    By default, all revisions are added to the changegroup.
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   756
    """
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   757
    opts = _byteskwargs(opts)
30020
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   758
    cl = repo.changelog
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   759
    nodes = [cl.lookup(r) for r in repo.revs(rev or b'all()')]
40752
cfaf3843491b perf: rename version flag of perfchangegroupchangelog to cgversion
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40741
diff changeset
   760
    bundler = changegroup.getbundler(cgversion, repo)
30020
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   761
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   762
    def d():
39015
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39007
diff changeset
   763
        state, chunks = bundler._generatechangelog(cl, nodes)
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39007
diff changeset
   764
        for chunk in chunks:
30020
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   765
            pass
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   766
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   767
    timer, fm = gettimer(ui, opts)
39015
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39007
diff changeset
   768
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39007
diff changeset
   769
    # Terminal printing can interfere with timing. So disable it.
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   770
    with ui.configoverride({(b'progress', b'disable'): True}):
39015
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39007
diff changeset
   771
        timer(d)
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39007
diff changeset
   772
30020
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   773
    fm.end()
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30019
diff changeset
   774
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   775
@command(b'perfdirs', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   776
def perfdirs(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   777
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   778
    timer, fm = gettimer(ui, opts)
18845
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   779
    dirstate = repo.dirstate
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   780
    b'a' in dirstate
18845
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   781
    def d():
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   782
        dirstate.hasdir(b'a')
35107
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 34750
diff changeset
   783
        del dirstate._map._dirs
18845
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   784
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   785
    fm.end()
18845
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   786
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   787
@command(b'perfdirstate', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   788
def perfdirstate(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   789
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   790
    timer, fm = gettimer(ui, opts)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   791
    b"a" in repo.dirstate
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   792
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   793
        repo.dirstate.invalidate()
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   794
        b"a" in repo.dirstate
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   795
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   796
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   797
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   798
@command(b'perfdirstatedirs', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   799
def perfdirstatedirs(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   800
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   801
    timer, fm = gettimer(ui, opts)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   802
    b"a" in repo.dirstate
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   803
    def d():
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   804
        repo.dirstate.hasdir(b"a")
35107
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 34750
diff changeset
   805
        del repo.dirstate._map._dirs
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   806
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   807
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   808
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   809
@command(b'perfdirstatefoldmap', formatteropts)
27095
aaf4e2d77148 contrib/perf: name functions to match decorators
timeless <timeless@mozdev.org>
parents: 27072
diff changeset
   810
def perfdirstatefoldmap(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   811
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   812
    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
   813
    dirstate = repo.dirstate
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   814
    b'a' in dirstate
22780
d8ff1f671aed perf: add a way to measure the perf of constructing the foldmap
Siddharth Agarwal <sid0@fb.com>
parents: 20846
diff changeset
   815
    def d():
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   816
        dirstate._map.filefoldmap.get(b'a')
34676
bfddc3d678ae dirstate: remove _filefoldmap property cache
Durham Goode <durham@fb.com>
parents: 34494
diff changeset
   817
        del dirstate._map.filefoldmap
24607
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   818
    timer(d)
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   819
    fm.end()
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   820
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   821
@command(b'perfdirfoldmap', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   822
def perfdirfoldmap(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   823
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   824
    timer, fm = gettimer(ui, opts)
24607
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   825
    dirstate = repo.dirstate
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   826
    b'a' in dirstate
24607
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   827
    def d():
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   828
        dirstate._map.dirfoldmap.get(b'a')
34678
e8a89ed7ce96 dirstate: move the _dirfoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34677
diff changeset
   829
        del dirstate._map.dirfoldmap
35107
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 34750
diff changeset
   830
        del dirstate._map._dirs
22780
d8ff1f671aed perf: add a way to measure the perf of constructing the foldmap
Siddharth Agarwal <sid0@fb.com>
parents: 20846
diff changeset
   831
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   832
    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
   833
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   834
@command(b'perfdirstatewrite', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   835
def perfdirstatewrite(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   836
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   837
    timer, fm = gettimer(ui, opts)
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   838
    ds = repo.dirstate
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   839
    b"a" in ds
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   840
    def d():
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   841
        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
   842
        ds.write(repo.currenttransaction())
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   843
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   844
    fm.end()
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   845
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   846
@command(b'perfmergecalculate',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   847
         [(b'r', b'rev', b'.', b'rev to merge against')] + formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   848
def perfmergecalculate(ui, repo, rev, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   849
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   850
    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
   851
    wctx = repo[None]
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   852
    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
   853
    ancestor = wctx.ancestor(rctx)
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   854
    # 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
   855
    # that cache
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   856
    wctx.dirty()
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   857
    def d():
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   858
        # 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
   859
        # our benchmark
27098
64cb281d23a5 contrib/perf: fix perfmergecalculate
timeless <timeless@mozdev.org>
parents: 27097
diff changeset
   860
        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
   861
                               acceptremote=True, followcopies=True)
18817
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   862
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   863
    fm.end()
18817
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   864
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   865
@command(b'perfpathcopies', [], b"REV REV")
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   866
def perfpathcopies(ui, repo, rev1, rev2, **opts):
40773
dc3ab5e5fe64 perf: add a docstring to `perfpathcopies`
Boris Feld <boris.feld@octobus.net>
parents: 40765
diff changeset
   867
    """benchmark the copy tracing logic"""
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   868
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   869
    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
   870
    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
   871
    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
   872
    def d():
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   873
        copies.pathcopies(ctx1, ctx2)
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   874
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   875
    fm.end()
18877
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   876
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   877
@command(b'perfphases',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   878
         [(b'', b'full', False, b'include file reading time too'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   879
          ], b"")
32501
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32428
diff changeset
   880
def perfphases(ui, repo, **opts):
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32428
diff changeset
   881
    """benchmark phasesets computation"""
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   882
    opts = _byteskwargs(opts)
32501
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32428
diff changeset
   883
    timer, fm = gettimer(ui, opts)
32752
e36569bd9e28 perfphases: add a flag to also include file access time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32751
diff changeset
   884
    _phases = repo._phasecache
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   885
    full = opts.get(b'full')
32501
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32428
diff changeset
   886
    def d():
32752
e36569bd9e28 perfphases: add a flag to also include file access time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32751
diff changeset
   887
        phases = _phases
e36569bd9e28 perfphases: add a flag to also include file access time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32751
diff changeset
   888
        if full:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   889
            clearfilecache(repo, b'_phasecache')
32752
e36569bd9e28 perfphases: add a flag to also include file access time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32751
diff changeset
   890
            phases = repo._phasecache
32501
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32428
diff changeset
   891
        phases.invalidate()
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32428
diff changeset
   892
        phases.loadphaserevs(repo)
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32428
diff changeset
   893
    timer(d)
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32428
diff changeset
   894
    fm.end()
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32428
diff changeset
   895
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   896
@command(b'perfphasesremote',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   897
         [], b"[DEST]")
38771
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   898
def perfphasesremote(ui, repo, dest=None, **opts):
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   899
    """benchmark time needed to analyse phases of the remote server"""
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   900
    from mercurial.node import (
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   901
        bin,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   902
    )
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   903
    from mercurial import (
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   904
        exchange,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   905
        hg,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   906
        phases,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   907
    )
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   908
    opts = _byteskwargs(opts)
38771
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   909
    timer, fm = gettimer(ui, opts)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   910
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   911
    path = ui.paths.getpath(dest, default=(b'default-push', b'default'))
38771
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   912
    if not path:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   913
        raise error.Abort((b'default repository not configured!'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   914
                          hint=(b"see 'hg help config.paths'"))
38771
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   915
    dest = path.pushloc or path.loc
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   916
    ui.status((b'analysing phase of %s\n') % util.hidepassword(dest))
38771
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   917
    other = hg.peer(repo, opts, dest)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   918
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   919
    # easier to perform discovery through the operation
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   920
    op = exchange.pushoperation(repo, other)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   921
    exchange._pushdiscoverychangeset(op)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   922
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   923
    remotesubset = op.fallbackheads
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   924
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   925
    with other.commandexecutor() as e:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   926
        remotephases = e.callcommand(b'listkeys',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   927
                       {b'namespace': b'phases'}).result()
38771
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   928
    del other
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   929
    publishing = remotephases.get(b'publishing', False)
38771
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   930
    if publishing:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   931
        ui.status((b'publishing: yes\n'))
38771
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   932
    else:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   933
        ui.status((b'publishing: no\n'))
38771
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   934
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   935
    nodemap = repo.changelog.nodemap
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   936
    nonpublishroots = 0
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   937
    for nhex, phase in remotephases.iteritems():
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   938
        if nhex == b'publishing': # ignore data related to publish option
38771
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   939
            continue
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   940
        node = bin(nhex)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   941
        if node in nodemap and int(phase):
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   942
            nonpublishroots += 1
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   943
    ui.status((b'number of roots: %d\n') % len(remotephases))
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   944
    ui.status((b'number of known non public roots: %d\n') % nonpublishroots)
38771
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   945
    def d():
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   946
        phases.remotephasessummary(repo,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   947
                                   remotesubset,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   948
                                   remotephases)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   949
    timer(d)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   950
    fm.end()
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   951
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   952
@command(b'perfmanifest',[
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   953
            (b'm', b'manifest-rev', False, b'Look up a manifest node revision'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   954
            (b'', b'clear-disk', False, b'clear on-disk caches too'),
40142
25ce80ce84c5 perf: accept formatter option for perfmanifest
Boris Feld <boris.feld@octobus.net>
parents: 40141
diff changeset
   955
         ] + formatteropts, b'REV|NODE')
38820
ddb15a83ae0b debug: allow specifying a manifest node rather than a revision
Martijn Pieters <mj@zopatista.com>
parents: 38819
diff changeset
   956
def perfmanifest(ui, repo, rev, manifest_rev=False, clear_disk=False, **opts):
38693
9b6a708f2263 perf: document the perfmanifest command
Boris Feld <boris.feld@octobus.net>
parents: 38285
diff changeset
   957
    """benchmark the time to read a manifest from disk and return a usable
9b6a708f2263 perf: document the perfmanifest command
Boris Feld <boris.feld@octobus.net>
parents: 38285
diff changeset
   958
    dict-like object
9b6a708f2263 perf: document the perfmanifest command
Boris Feld <boris.feld@octobus.net>
parents: 38285
diff changeset
   959
9b6a708f2263 perf: document the perfmanifest command
Boris Feld <boris.feld@octobus.net>
parents: 38285
diff changeset
   960
    Manifest caches are cleared before retrieval."""
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   961
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   962
    timer, fm = gettimer(ui, opts)
38820
ddb15a83ae0b debug: allow specifying a manifest node rather than a revision
Martijn Pieters <mj@zopatista.com>
parents: 38819
diff changeset
   963
    if not manifest_rev:
ddb15a83ae0b debug: allow specifying a manifest node rather than a revision
Martijn Pieters <mj@zopatista.com>
parents: 38819
diff changeset
   964
        ctx = scmutil.revsingle(repo, rev, rev)
ddb15a83ae0b debug: allow specifying a manifest node rather than a revision
Martijn Pieters <mj@zopatista.com>
parents: 38819
diff changeset
   965
        t = ctx.manifestnode()
ddb15a83ae0b debug: allow specifying a manifest node rather than a revision
Martijn Pieters <mj@zopatista.com>
parents: 38819
diff changeset
   966
    else:
39345
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   967
        from mercurial.node import bin
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   968
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   969
        if len(rev) == 40:
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   970
            t = bin(rev)
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   971
        else:
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   972
            try:
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   973
                rev = int(rev)
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   974
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   975
                if util.safehasattr(repo.manifestlog, b'getstorage'):
39345
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   976
                    t = repo.manifestlog.getstorage(b'').node(rev)
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   977
                else:
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   978
                    t = repo.manifestlog._revlog.lookup(rev)
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39226
diff changeset
   979
            except ValueError:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   980
                raise error.Abort(b'manifest revision must be integer or full '
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   981
                                  b'node')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   982
    def d():
38821
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38820
diff changeset
   983
        repo.manifestlog.clearcaches(clear_persisted_data=clear_disk)
30379
d79c141fdf41 manifest: remove usages of manifest.read
Durham Goode <durham@fb.com>
parents: 30347
diff changeset
   984
        repo.manifestlog[t].read()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   985
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   986
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   987
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
   988
@command(b'perfchangeset', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   989
def perfchangeset(ui, repo, rev, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
   990
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   991
    timer, fm = gettimer(ui, opts)
37355
5bcd5859b505 perf: make perfmanifest and perfnodelookup work with revsets
Martin von Zweigbergk <martinvonz@google.com>
parents: 37271
diff changeset
   992
    n = scmutil.revsingle(repo, rev).node()
16262
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   993
    def d():
19378
9de689d20230 cleanup: drop unused variables and an unused import
Simon Heimberg <simohe@besonet.ch>
parents: 19322
diff changeset
   994
        repo.changelog.read(n)
16266
77d56a5e74a5 perf: add a changeset test
Matt Mackall <mpm@selenic.com>
parents: 16262
diff changeset
   995
        #repo.changelog._cache = None
16262
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   996
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   997
    fm.end()
16262
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   998
40784
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
   999
@command(b'perfignore', formatteropts)
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1000
def perfignore(ui, repo, **opts):
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1001
    """benchmark operation related to computing ignore"""
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1002
    opts = _byteskwargs(opts)
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1003
    timer, fm = gettimer(ui, opts)
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1004
    dirstate = repo.dirstate
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1005
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1006
    def setupone():
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1007
        dirstate.invalidate()
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1008
        clearfilecache(dirstate, b'_ignore')
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1009
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1010
    def runone():
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1011
        dirstate._ignore
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1012
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1013
    timer(runone, setup=setupone, title=b"load")
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1014
    fm.end()
45a0047c0ebc perf: add a perfignore command
Boris Feld <boris.feld@octobus.net>
parents: 40781
diff changeset
  1015
40818
a0f2641ddd61 perf: add a --rev attribute to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 40817
diff changeset
  1016
@command(b'perfindex', [
40958
ebc471ce9fad py3: add a missing b'' prefix in contrib/perf.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40954
diff changeset
  1017
            (b'', b'rev', b'', b'revision to be looked up (default tip)'),
41460
e9891c734bf8 perf: add a no-lookup variant to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41459
diff changeset
  1018
            (b'', b'no-lookup', None, b'do not revision lookup post creation'),
40818
a0f2641ddd61 perf: add a --rev attribute to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 40817
diff changeset
  1019
         ] + formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1020
def perfindex(ui, repo, **opts):
41459
d65ba1ff4559 perf: add some documentation to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41458
diff changeset
  1021
    """benchmark index creation time followed by a lookup
d65ba1ff4559 perf: add some documentation to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41458
diff changeset
  1022
d65ba1ff4559 perf: add some documentation to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41458
diff changeset
  1023
    The default is to look `tip` up. Depending on the index implementation,
d65ba1ff4559 perf: add some documentation to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41458
diff changeset
  1024
    the revision looked up can matters. For example, an implementation
d65ba1ff4559 perf: add some documentation to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41458
diff changeset
  1025
    scanning the index will have a faster lookup time for `--rev tip` than for
d65ba1ff4559 perf: add some documentation to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41458
diff changeset
  1026
    `--rev 0`.
d65ba1ff4559 perf: add some documentation to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41458
diff changeset
  1027
d65ba1ff4559 perf: add some documentation to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41458
diff changeset
  1028
    It is not currently possible to check for lookup of a missing node."""
13255
2696730ca233 perf: make perfindex results useful on hg with lazyparser
Matt Mackall <mpm@selenic.com>
parents: 13254
diff changeset
  1029
    import mercurial.revlog
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1030
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1031
    timer, fm = gettimer(ui, opts)
13277
9f707b297b0f perf: restore lazyindex hack
Matt Mackall <mpm@selenic.com>
parents: 13262
diff changeset
  1032
    mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
41460
e9891c734bf8 perf: add a no-lookup variant to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41459
diff changeset
  1033
    if opts[b'no_lookup']:
e9891c734bf8 perf: add a no-lookup variant to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41459
diff changeset
  1034
        n = None
e9891c734bf8 perf: add a no-lookup variant to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41459
diff changeset
  1035
    elif opts[b'rev'] is None:
40818
a0f2641ddd61 perf: add a --rev attribute to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 40817
diff changeset
  1036
        n = repo[b"tip"].node()
a0f2641ddd61 perf: add a --rev attribute to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 40817
diff changeset
  1037
    else:
40961
a314eafd7c8d perf: add two more missing b prefixes for Python 3
Augie Fackler <augie@google.com>
parents: 40958
diff changeset
  1038
        rev = scmutil.revsingle(repo, opts[b'rev'])
40818
a0f2641ddd61 perf: add a --rev attribute to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 40817
diff changeset
  1039
        n = repo[rev].node()
40817
e207f0d6c243 perf: update perfindex to be more realistic
Boris Feld <boris.feld@octobus.net>
parents: 40806
diff changeset
  1040
e207f0d6c243 perf: update perfindex to be more realistic
Boris Feld <boris.feld@octobus.net>
parents: 40806
diff changeset
  1041
    unfi = repo.unfiltered()
e207f0d6c243 perf: update perfindex to be more realistic
Boris Feld <boris.feld@octobus.net>
parents: 40806
diff changeset
  1042
    # find the filecache func directly
e207f0d6c243 perf: update perfindex to be more realistic
Boris Feld <boris.feld@octobus.net>
parents: 40806
diff changeset
  1043
    # This avoid polluting the benchmark with the filecache logic
e207f0d6c243 perf: update perfindex to be more realistic
Boris Feld <boris.feld@octobus.net>
parents: 40806
diff changeset
  1044
    makecl = unfi.__class__.changelog.func
e207f0d6c243 perf: update perfindex to be more realistic
Boris Feld <boris.feld@octobus.net>
parents: 40806
diff changeset
  1045
    def setup():
e207f0d6c243 perf: update perfindex to be more realistic
Boris Feld <boris.feld@octobus.net>
parents: 40806
diff changeset
  1046
        # probably not necessary, but for good measure
e207f0d6c243 perf: update perfindex to be more realistic
Boris Feld <boris.feld@octobus.net>
parents: 40806
diff changeset
  1047
        clearchangelog(unfi)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1048
    def d():
40817
e207f0d6c243 perf: update perfindex to be more realistic
Boris Feld <boris.feld@octobus.net>
parents: 40806
diff changeset
  1049
        cl = makecl(unfi)
41460
e9891c734bf8 perf: add a no-lookup variant to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41459
diff changeset
  1050
        if n is not None:
e9891c734bf8 perf: add a no-lookup variant to perfindex
Boris Feld <boris.feld@octobus.net>
parents: 41459
diff changeset
  1051
            cl.rev(n)
40817
e207f0d6c243 perf: update perfindex to be more realistic
Boris Feld <boris.feld@octobus.net>
parents: 40806
diff changeset
  1052
    timer(d, setup=setup)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1053
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1054
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1055
@command(b'perfstartup', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1056
def perfstartup(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1057
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1058
    timer, fm = gettimer(ui, opts)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1059
    def d():
39829
db875f97a969 py3: un-byteify strings around os.system() and os.devnull in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39828
diff changeset
  1060
        if os.name != r'nt':
40349
1524c305377f py3: restore perfstartup() prior to b456b2e0ad9f on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 40295
diff changeset
  1061
            os.system(b"HGRCPATH= %s version -q > /dev/null" %
1524c305377f py3: restore perfstartup() prior to b456b2e0ad9f on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 40295
diff changeset
  1062
                      fsencode(sys.argv[0]))
27382
de7bcbc68042 perf: adjust perfstartup() for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 27345
diff changeset
  1063
        else:
39829
db875f97a969 py3: un-byteify strings around os.system() and os.devnull in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39828
diff changeset
  1064
            os.environ[r'HGRCPATH'] = r' '
40349
1524c305377f py3: restore perfstartup() prior to b456b2e0ad9f on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 40295
diff changeset
  1065
            os.system(r"%s version -q > NUL" % sys.argv[0])
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1066
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1067
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1068
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1069
@command(b'perfparents', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1070
def perfparents(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1071
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1072
    timer, fm = gettimer(ui, opts)
27305
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
  1073
    # control the number of commits perfparents iterates over
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
  1074
    # experimental config: perf.parentscount
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1075
    count = getint(ui, b"perf", b"parentscount", 1000)
27305
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
  1076
    if len(repo.changelog) < count:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1077
        raise error.Abort(b"repo needs %d commits for this test" % count)
27100
8d5dba93aa4f contrib/perf: perfparents handle filtered repos
timeless <timeless@mozdev.org>
parents: 27099
diff changeset
  1078
    repo = repo.unfiltered()
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  1079
    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
  1080
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1081
        for n in nl:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1082
            repo.changelog.parents(n)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1083
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1084
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1085
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1086
@command(b'perfctxfiles', formatteropts)
27095
aaf4e2d77148 contrib/perf: name functions to match decorators
timeless <timeless@mozdev.org>
parents: 27072
diff changeset
  1087
def perfctxfiles(ui, repo, x, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1088
    opts = _byteskwargs(opts)
24349
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
  1089
    x = int(x)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1090
    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
  1091
    def d():
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
  1092
        len(repo[x].files())
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
  1093
    timer(d)
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
  1094
    fm.end()
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
  1095
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1096
@command(b'perfrawfiles', formatteropts)
27095
aaf4e2d77148 contrib/perf: name functions to match decorators
timeless <timeless@mozdev.org>
parents: 27072
diff changeset
  1097
def perfrawfiles(ui, repo, x, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1098
    opts = _byteskwargs(opts)
24349
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
  1099
    x = int(x)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1100
    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
  1101
    cl = repo.changelog
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
  1102
    def d():
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
  1103
        len(cl.read(x)[3])
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
  1104
    timer(d)
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
  1105
    fm.end()
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
  1106
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1107
@command(b'perflookup', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1108
def perflookup(ui, repo, rev, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1109
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1110
    timer, fm = gettimer(ui, opts)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1111
    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
  1112
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
  1113
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1114
@command(b'perflinelogedits',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1115
         [(b'n', b'edits', 10000, b'number of edits'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1116
          (b'', b'max-hunk-lines', 10, b'max lines in a hunk'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1117
          ], norepo=True)
39007
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1118
def perflinelogedits(ui, **opts):
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1119
    from mercurial import linelog
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1120
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1121
    opts = _byteskwargs(opts)
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1122
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1123
    edits = opts[b'edits']
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1124
    maxhunklines = opts[b'max_hunk_lines']
39007
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1125
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1126
    maxb1 = 100000
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1127
    random.seed(0)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1128
    randint = random.randint
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1129
    currentlines = 0
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1130
    arglist = []
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  1131
    for rev in _xrange(edits):
39007
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1132
        a1 = randint(0, currentlines)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1133
        a2 = randint(a1, min(currentlines, a1 + maxhunklines))
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1134
        b1 = randint(0, maxb1)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1135
        b2 = randint(b1, b1 + maxhunklines)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1136
        currentlines += (b2 - b1) - (a2 - a1)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1137
        arglist.append((rev, a1, a2, b1, b2))
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1138
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1139
    def d():
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1140
        ll = linelog.linelog()
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1141
        for args in arglist:
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1142
            ll.replacelines(*args)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1143
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1144
    timer, fm = gettimer(ui, opts)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1145
    timer(d)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1146
    fm.end()
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38821
diff changeset
  1147
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1148
@command(b'perfrevrange', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1149
def perfrevrange(ui, repo, *specs, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1150
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1151
    timer, fm = gettimer(ui, opts)
16858
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
  1152
    revrange = scmutil.revrange
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
  1153
    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
  1154
    fm.end()
16858
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
  1155
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1156
@command(b'perfnodelookup', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1157
def perfnodelookup(ui, repo, rev, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1158
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1159
    timer, fm = gettimer(ui, opts)
16309
e0c1b3ef7c36 perf: node lookup
Matt Mackall <mpm@selenic.com>
parents: 16266
diff changeset
  1160
    import mercurial.revlog
e0c1b3ef7c36 perf: node lookup
Matt Mackall <mpm@selenic.com>
parents: 16266
diff changeset
  1161
    mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
37355
5bcd5859b505 perf: make perfmanifest and perfnodelookup work with revsets
Martin von Zweigbergk <martinvonz@google.com>
parents: 37271
diff changeset
  1162
    n = scmutil.revsingle(repo, rev).node()
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1163
    cl = mercurial.revlog.revlog(getsvfs(repo), b"00changelog.i")
16414
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
  1164
    def d():
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
  1165
        cl.rev(n)
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
  1166
        clearcaches(cl)
16414
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
  1167
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1168
    fm.end()
16414
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
  1169
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1170
@command(b'perflog',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1171
         [(b'', b'rename', False, b'ask log to follow renames')
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1172
         ] + formatteropts)
27306
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
  1173
def perflog(ui, repo, rev=None, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1174
    opts = _byteskwargs(opts)
27306
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
  1175
    if rev is None:
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
  1176
        rev=[]
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1177
    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
  1178
    ui.pushbuffer()
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1179
    timer(lambda: commands.log(ui, repo, rev=rev, date=b'', user=b'',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1180
                               copies=opts.get(b'rename')))
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
  1181
    ui.popbuffer()
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1182
    fm.end()
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
  1183
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1184
@command(b'perfmoonwalk', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1185
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
  1186
    """benchmark walking the changelog backwards
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
  1187
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
  1188
    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
  1189
    """
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1190
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1191
    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
  1192
    def moonwalk():
38819
a4d847cea6f8 perfmoonwalk: make work with filtered repo
Martin von Zweigbergk <martinvonz@google.com>
parents: 38695
diff changeset
  1193
        for i in repo.changelog.revs(start=(len(repo) - 1), stop=-1):
20178
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
  1194
            ctx = repo[i]
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
  1195
            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
  1196
    timer(moonwalk)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1197
    fm.end()
20178
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
  1198
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1199
@command(b'perftemplating',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1200
         [(b'r', b'rev', [], b'revisions to run the template on'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1201
          ] + formatteropts)
38270
ae6e02fcee24 perftemplating: allow to specify the template to test
Boris Feld <boris.feld@octobus.net>
parents: 38269
diff changeset
  1202
def perftemplating(ui, repo, testedtemplate=None, **opts):
ae6e02fcee24 perftemplating: allow to specify the template to test
Boris Feld <boris.feld@octobus.net>
parents: 38269
diff changeset
  1203
    """test the rendering time of a given template"""
38269
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
  1204
    if makelogtemplater is None:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1205
        raise error.Abort((b"perftemplating not available with this Mercurial"),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1206
                          hint=b"use 4.3 or later")
38269
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
  1207
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1208
    opts = _byteskwargs(opts)
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1209
38267
71d59b487d0c perftemplating: drop usage of buffer
Boris Feld <boris.feld@octobus.net>
parents: 38266
diff changeset
  1210
    nullui = ui.copy()
39829
db875f97a969 py3: un-byteify strings around os.system() and os.devnull in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39828
diff changeset
  1211
    nullui.fout = open(os.devnull, r'wb')
38267
71d59b487d0c perftemplating: drop usage of buffer
Boris Feld <boris.feld@octobus.net>
parents: 38266
diff changeset
  1212
    nullui.disablepager()
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1213
    revs = opts.get(b'rev')
38269
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
  1214
    if not revs:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1215
        revs = [b'all()']
38269
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
  1216
    revs = list(scmutil.revrange(repo, revs))
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
  1217
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1218
    defaulttemplate = (b'{date|shortdate} [{rev}:{node|short}]'
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1219
                       b' {author|person}: {desc|firstline}\n')
38270
ae6e02fcee24 perftemplating: allow to specify the template to test
Boris Feld <boris.feld@octobus.net>
parents: 38269
diff changeset
  1220
    if testedtemplate is None:
ae6e02fcee24 perftemplating: allow to specify the template to test
Boris Feld <boris.feld@octobus.net>
parents: 38269
diff changeset
  1221
        testedtemplate = defaulttemplate
ae6e02fcee24 perftemplating: allow to specify the template to test
Boris Feld <boris.feld@octobus.net>
parents: 38269
diff changeset
  1222
    displayer = makelogtemplater(nullui, repo, testedtemplate)
38266
6b91815fcdce perftemplating: move template formating into its own function
Boris Feld <boris.feld@octobus.net>
parents: 38265
diff changeset
  1223
    def format():
38269
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
  1224
        for r in revs:
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
  1225
            ctx = repo[r]
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
  1226
            displayer.show(ctx)
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38268
diff changeset
  1227
            displayer.flush(ctx)
38266
6b91815fcdce perftemplating: move template formating into its own function
Boris Feld <boris.feld@octobus.net>
parents: 38265
diff changeset
  1228
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1229
    timer, fm = gettimer(ui, opts)
38266
6b91815fcdce perftemplating: move template formating into its own function
Boris Feld <boris.feld@octobus.net>
parents: 38265
diff changeset
  1230
    timer(format)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1231
    fm.end()
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
  1232
40774
30d878cb102d perf: rename `perfhelper-tracecopies` to `perfhelper-pathcopies`
Boris Feld <boris.feld@octobus.net>
parents: 40773
diff changeset
  1233
@command(b'perfhelper-pathcopies', formatteropts +
40730
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1234
         [
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1235
          (b'r', b'revs', [], b'restrict search to these revisions'),
40765
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1236
          (b'', b'timing', False, b'provides extra data (costly)'),
40730
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1237
         ])
40774
30d878cb102d perf: rename `perfhelper-tracecopies` to `perfhelper-pathcopies`
Boris Feld <boris.feld@octobus.net>
parents: 40773
diff changeset
  1238
def perfhelperpathcopies(ui, repo, revs=[], **opts):
40730
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1239
    """find statistic about potential parameters for the `perftracecopies`
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1240
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1241
    This command find source-destination pair relevant for copytracing testing.
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1242
    It report value for some of the parameters that impact copy tracing time.
40765
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1243
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1244
    If `--timing` is set, rename detection is run and the associated timing
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1245
    will be reported. The extra details comes at the cost of a slower command
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1246
    execution.
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1247
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1248
    Since the rename detection is only run once, other factors might easily
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1249
    affect the precision of the timing. However it should give a good
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1250
    approximation of which revision pairs are very costly.
40730
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1251
    """
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1252
    opts = _byteskwargs(opts)
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1253
    fm = ui.formatter(b'perf', opts)
40765
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1254
    dotiming = opts[b'timing']
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1255
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1256
    if dotiming:
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1257
        header = '%12s %12s %12s %12s %12s %12s\n'
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1258
        output = ("%(source)12s %(destination)12s "
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1259
                  "%(nbrevs)12d %(nbmissingfiles)12d "
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1260
                  "%(nbrenamedfiles)12d %(time)18.5f\n")
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1261
        header_names = ("source", "destination", "nb-revs", "nb-files",
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1262
                        "nb-renames", "time")
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1263
        fm.plain(header % header_names)
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1264
    else:
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1265
        header = '%12s %12s %12s %12s\n'
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1266
        output = ("%(source)12s %(destination)12s "
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1267
                  "%(nbrevs)12d %(nbmissingfiles)12d\n")
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1268
        fm.plain(header % ("source", "destination", "nb-revs", "nb-files"))
40730
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1269
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1270
    if not revs:
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1271
        revs = ['all()']
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1272
    revs = scmutil.revrange(repo, revs)
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1273
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1274
    roi = repo.revs('merge() and %ld', revs)
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1275
    for r in roi:
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1276
        ctx = repo[r]
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1277
        p1 = ctx.p1().rev()
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1278
        p2 = ctx.p2().rev()
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1279
        bases = repo.changelog._commonancestorsheads(p1, p2)
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1280
        for p in (p1, p2):
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1281
            for b in bases:
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1282
                base = repo[b]
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1283
                parent = repo[p]
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1284
                missing = copies._computeforwardmissing(base, parent)
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1285
                if not missing:
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1286
                    continue
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1287
                data = {
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1288
                    b'source': base.hex(),
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1289
                    b'destination': parent.hex(),
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1290
                    b'nbrevs': len(repo.revs('%d::%d', b, p)),
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1291
                    b'nbmissingfiles': len(missing),
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1292
                }
40765
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1293
                if dotiming:
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1294
                    begin = util.timer()
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1295
                    renames = copies.pathcopies(base, parent)
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1296
                    end = util.timer()
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1297
                    # not very stable timing since we did only one run
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1298
                    data['time'] = end - begin
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1299
                    data['nbrenamedfiles'] = len(renames)
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1300
                fm.startitem()
40730
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1301
                fm.data(**data)
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1302
                out = data.copy()
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1303
                out['source'] = fm.hexfunc(base.node())
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1304
                out['destination'] = fm.hexfunc(parent.node())
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1305
                fm.plain(output % out)
40765
36077a0f6f12 perf: add a `--timing` argument to `perfhelper-tracecopies`
Boris Feld <boris.feld@octobus.net>
parents: 40760
diff changeset
  1306
40730
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1307
    fm.end()
a65fe13de84f perf: add a new `perfhelper-tracecopies` command
Boris Feld <boris.feld@octobus.net>
parents: 40722
diff changeset
  1308
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1309
@command(b'perfcca', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1310
def perfcca(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1311
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1312
    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
  1313
    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
  1314
    fm.end()
16386
ccc173d0914e perf: add case collision auditor perf
Matt Mackall <mpm@selenic.com>
parents: 16309
diff changeset
  1315
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1316
@command(b'perffncacheload', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1317
def perffncacheload(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1318
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1319
    timer, fm = gettimer(ui, opts)
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
  1320
    s = repo.store
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1321
    def d():
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1322
        s.fncache._load()
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1323
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1324
    fm.end()
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1325
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1326
@command(b'perffncachewrite', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1327
def perffncachewrite(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1328
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1329
    timer, fm = gettimer(ui, opts)
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
  1330
    s = repo.store
38695
2cdb82e8fb44 perffncachewrite: load fncache after lock is acquired
Boris Feld <boris.feld@octobus.net>
parents: 38694
diff changeset
  1331
    lock = repo.lock()
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1332
    s.fncache._load()
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1333
    tr = repo.transaction(b'perffncachewrite')
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1334
    tr.addbackup(b'fncache')
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1335
    def d():
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1336
        s.fncache._dirty = True
27097
b3e24a9c5f9b contrib/perf: fix perffncachewrite
timeless <timeless@mozdev.org>
parents: 27096
diff changeset
  1337
        s.fncache.write(tr)
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1338
    timer(d)
30069
98b9846a131e perf: release lock after transaction in perffncachewrite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30020
diff changeset
  1339
    tr.close()
27097
b3e24a9c5f9b contrib/perf: fix perffncachewrite
timeless <timeless@mozdev.org>
parents: 27096
diff changeset
  1340
    lock.release()
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1341
    fm.end()
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1342
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1343
@command(b'perffncacheencode', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1344
def perffncacheencode(ui, repo, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1345
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1346
    timer, fm = gettimer(ui, opts)
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
  1347
    s = repo.store
17553
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1348
    s.fncache._load()
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1349
    def d():
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1350
        for p in s.fncache.entries:
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1351
            s.encode(p)
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1352
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1353
    fm.end()
17553
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1354
36774
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1355
def _bdiffworker(q, blocks, xdiff, ready, done):
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1356
    while not done.is_set():
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1357
        pair = q.get()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1358
        while pair is not None:
36774
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1359
            if xdiff:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1360
                mdiff.bdiff.xdiffblocks(*pair)
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1361
            elif blocks:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1362
                mdiff.bdiff.blocks(*pair)
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1363
            else:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1364
                mdiff.textdiff(*pair)
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1365
            q.task_done()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1366
            pair = q.get()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1367
        q.task_done() # for the None one
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1368
        with ready:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1369
            ready.wait()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1370
39346
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1371
def _manifestrevision(repo, mnode):
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1372
    ml = repo.manifestlog
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1373
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1374
    if util.safehasattr(ml, b'getstorage'):
39346
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1375
        store = ml.getstorage(b'')
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1376
    else:
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1377
        store = ml._revlog
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1378
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1379
    return store.revision(mnode)
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1380
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1381
@command(b'perfbdiff', revlogopts + formatteropts + [
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1382
    (b'', b'count', 1, b'number of revisions to test (when using --startrev)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1383
    (b'', b'alldata', False, b'test bdiffs for all associated revisions'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1384
    (b'', b'threads', 0, b'number of thread to use (disable with 0)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1385
    (b'', b'blocks', False, b'test computing diffs into blocks'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1386
    (b'', b'xdiff', False, b'use xdiff algorithm'),
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1387
    ],
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1388
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1389
    b'-c|-m|FILE REV')
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1390
def perfbdiff(ui, repo, file_, rev=None, count=None, threads=0, **opts):
30346
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30345
diff changeset
  1391
    """benchmark a bdiff between revisions
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30345
diff changeset
  1392
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30345
diff changeset
  1393
    By default, benchmark a bdiff between its delta parent and itself.
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30345
diff changeset
  1394
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30345
diff changeset
  1395
    With ``--count``, benchmark bdiffs between delta parents and self for N
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30345
diff changeset
  1396
    revisions starting at the specified revision.
30347
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1397
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1398
    With ``--alldata``, assume the requested revision is a changeset and
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1399
    measure bdiffs for all changes related to that changeset (manifest
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1400
    and filelogs).
30346
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30345
diff changeset
  1401
    """
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1402
    opts = _byteskwargs(opts)
36774
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1403
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1404
    if opts[b'xdiff'] and not opts[b'blocks']:
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1405
        raise error.CommandError(b'perfbdiff', b'--xdiff requires --blocks')
36774
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1406
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1407
    if opts[b'alldata']:
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1408
        opts[b'changelog'] = True
30347
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1409
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1410
    if opts.get(b'changelog') or opts.get(b'manifest'):
30320
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1411
        file_, rev = None, file_
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1412
    elif rev is None:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1413
        raise error.CommandError(b'perfbdiff', b'invalid arguments')
30320
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1414
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1415
    blocks = opts[b'blocks']
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1416
    xdiff = opts[b'xdiff']
30345
7d91a085ebe6 perf: prepare to handle multiple pairs in perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30320
diff changeset
  1417
    textpairs = []
7d91a085ebe6 perf: prepare to handle multiple pairs in perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30320
diff changeset
  1418
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1419
    r = cmdutil.openrevlog(repo, b'perfbdiff', file_, opts)
30320
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1420
30346
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30345
diff changeset
  1421
    startrev = r.rev(r.lookup(rev))
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30345
diff changeset
  1422
    for rev in range(startrev, min(startrev + count, len(r) - 1)):
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1423
        if opts[b'alldata']:
30347
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1424
            # Load revisions associated with changeset.
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1425
            ctx = repo[rev]
39346
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1426
            mtext = _manifestrevision(repo, ctx.manifestnode())
30347
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1427
            for pctx in ctx.parents():
39346
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1428
                pman = _manifestrevision(repo, pctx.manifestnode())
30347
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1429
                textpairs.append((pman, mtext))
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1430
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1431
            # Load filelog revisions by iterating manifest delta.
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1432
            man = ctx.manifest()
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1433
            pman = ctx.p1().manifest()
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1434
            for filename, change in pman.diff(man).items():
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1435
                fctx = repo.file(filename)
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1436
                f1 = fctx.revision(change[0][0] or -1)
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1437
                f2 = fctx.revision(change[1][0] or -1)
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1438
                textpairs.append((f1, f2))
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1439
        else:
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1440
            dp = r.deltaparent(rev)
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30346
diff changeset
  1441
            textpairs.append((r.revision(dp), r.revision(rev)))
30320
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1442
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1443
    withthreads = threads > 0
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1444
    if not withthreads:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1445
        def d():
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1446
            for pair in textpairs:
36774
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1447
                if xdiff:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1448
                    mdiff.bdiff.xdiffblocks(*pair)
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1449
                elif blocks:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1450
                    mdiff.bdiff.blocks(*pair)
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1451
                else:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1452
                    mdiff.textdiff(*pair)
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1453
    else:
37890
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
  1454
        q = queue()
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  1455
        for i in _xrange(threads):
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1456
            q.put(None)
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1457
        ready = threading.Condition()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1458
        done = threading.Event()
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  1459
        for i in _xrange(threads):
36774
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1460
            threading.Thread(target=_bdiffworker,
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36393
diff changeset
  1461
                             args=(q, blocks, xdiff, ready, done)).start()
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1462
        q.join()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1463
        def d():
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1464
            for pair in textpairs:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1465
                q.put(pair)
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  1466
            for i in _xrange(threads):
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1467
                q.put(None)
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1468
            with ready:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1469
                ready.notify_all()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1470
            q.join()
30320
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1471
    timer, fm = gettimer(ui, opts)
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1472
    timer(d)
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1473
    fm.end()
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1474
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1475
    if withthreads:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1476
        done.set()
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  1477
        for i in _xrange(threads):
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1478
            q.put(None)
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1479
        with ready:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1480
            ready.notify_all()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35137
diff changeset
  1481
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1482
@command(b'perfunidiff', revlogopts + formatteropts + [
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1483
    (b'', b'count', 1, b'number of revisions to test (when using --startrev)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1484
    (b'', b'alldata', False, b'test unidiffs for all associated revisions'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1485
    ], b'-c|-m|FILE REV')
35901
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1486
def perfunidiff(ui, repo, file_, rev=None, count=None, **opts):
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1487
    """benchmark a unified diff between revisions
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1488
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1489
    This doesn't include any copy tracing - it's just a unified diff
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1490
    of the texts.
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1491
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1492
    By default, benchmark a diff between its delta parent and itself.
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1493
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1494
    With ``--count``, benchmark diffs between delta parents and self for N
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1495
    revisions starting at the specified revision.
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1496
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1497
    With ``--alldata``, assume the requested revision is a changeset and
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1498
    measure diffs for all changes related to that changeset (manifest
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1499
    and filelogs).
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1500
    """
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1501
    opts = _byteskwargs(opts)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1502
    if opts[b'alldata']:
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1503
        opts[b'changelog'] = True
35901
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1504
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1505
    if opts.get(b'changelog') or opts.get(b'manifest'):
35901
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1506
        file_, rev = None, file_
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1507
    elif rev is None:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1508
        raise error.CommandError(b'perfunidiff', b'invalid arguments')
35901
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1509
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1510
    textpairs = []
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1511
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1512
    r = cmdutil.openrevlog(repo, b'perfunidiff', file_, opts)
35901
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1513
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1514
    startrev = r.rev(r.lookup(rev))
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1515
    for rev in range(startrev, min(startrev + count, len(r) - 1)):
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1516
        if opts[b'alldata']:
35901
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1517
            # Load revisions associated with changeset.
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1518
            ctx = repo[rev]
39346
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1519
            mtext = _manifestrevision(repo, ctx.manifestnode())
35901
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1520
            for pctx in ctx.parents():
39346
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39345
diff changeset
  1521
                pman = _manifestrevision(repo, pctx.manifestnode())
35901
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1522
                textpairs.append((pman, mtext))
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1523
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1524
            # Load filelog revisions by iterating manifest delta.
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1525
            man = ctx.manifest()
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1526
            pman = ctx.p1().manifest()
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1527
            for filename, change in pman.diff(man).items():
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1528
                fctx = repo.file(filename)
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1529
                f1 = fctx.revision(change[0][0] or -1)
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1530
                f2 = fctx.revision(change[1][0] or -1)
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1531
                textpairs.append((f1, f2))
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1532
        else:
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1533
            dp = r.deltaparent(rev)
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1534
            textpairs.append((r.revision(dp), r.revision(rev)))
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1535
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1536
    def d():
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1537
        for left, right in textpairs:
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1538
            # The date strings don't matter, so we pass empty strings.
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1539
            headerlines, hunks = mdiff.unidiff(
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1540
                left, b'', right, b'', b'left', b'right', binary=False)
35901
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1541
            # consume iterators in roughly the way patch.py does
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1542
            b'\n'.join(headerlines)
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1543
            b''.join(sum((list(hlines) for hrange, hlines in hunks), []))
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1544
    timer, fm = gettimer(ui, opts)
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1545
    timer(d)
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1546
    fm.end()
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1547
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1548
@command(b'perfdiffwd', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1549
def perfdiffwd(ui, repo, **opts):
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1550
    """Profile diff of working directory changes"""
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1551
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1552
    timer, fm = gettimer(ui, opts)
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1553
    options = {
40214
b456b2e0ad9f py3: make test-contrib-perf.t work on python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40145
diff changeset
  1554
        'w': 'ignore_all_space',
b456b2e0ad9f py3: make test-contrib-perf.t work on python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40145
diff changeset
  1555
        'b': 'ignore_space_change',
b456b2e0ad9f py3: make test-contrib-perf.t work on python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40145
diff changeset
  1556
        'B': 'ignore_blank_lines',
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1557
        }
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1558
40214
b456b2e0ad9f py3: make test-contrib-perf.t work on python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40145
diff changeset
  1559
    for diffopt in ('', 'w', 'b', 'B', 'wB'):
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1560
        opts = dict((options[c], b'1') for c in diffopt)
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1561
        def d():
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1562
            ui.pushbuffer()
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1563
            commands.diff(ui, repo, **opts)
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1564
            ui.popbuffer()
40214
b456b2e0ad9f py3: make test-contrib-perf.t work on python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40145
diff changeset
  1565
        diffopt = diffopt.encode('ascii')
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1566
        title = b'diffopts: %s' % (diffopt and (b'-' + diffopt) or b'none')
40718
20d2fd6036ed perf: explicitly pass title as a keyword argument in `perfdiffwd`
Boris Feld <boris.feld@octobus.net>
parents: 40605
diff changeset
  1567
        timer(d, title=title)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1568
    fm.end()
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1569
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1570
@command(b'perfrevlogindex', revlogopts + formatteropts,
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1571
         b'-c|-m|FILE')
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1572
def perfrevlogindex(ui, repo, file_=None, **opts):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1573
    """Benchmark operations against a revlog index.
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1574
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1575
    This tests constructing a revlog instance, reading index data,
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1576
    parsing index data, and performing various operations related to
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1577
    index data.
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1578
    """
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1579
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1580
    opts = _byteskwargs(opts)
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1581
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1582
    rl = cmdutil.openrevlog(repo, b'perfrevlogindex', file_, opts)
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1583
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1584
    opener = getattr(rl, 'opener')  # trick linter
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1585
    indexfile = rl.indexfile
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1586
    data = opener.read(indexfile)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1587
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1588
    header = struct.unpack(b'>I', data[0:4])[0]
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1589
    version = header & 0xFFFF
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1590
    if version == 1:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1591
        revlogio = revlog.revlogio()
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1592
        inline = header & (1 << 16)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1593
    else:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1594
        raise error.Abort((b'unsupported revlog version: %d') % version)
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1595
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1596
    rllen = len(rl)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1597
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1598
    node0 = rl.node(0)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1599
    node25 = rl.node(rllen // 4)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1600
    node50 = rl.node(rllen // 2)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1601
    node75 = rl.node(rllen // 4 * 3)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1602
    node100 = rl.node(rllen - 1)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1603
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1604
    allrevs = range(rllen)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1605
    allrevsrev = list(reversed(allrevs))
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1606
    allnodes = [rl.node(rev) for rev in range(rllen)]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1607
    allnodesrev = list(reversed(allnodes))
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1608
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1609
    def constructor():
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1610
        revlog.revlog(opener, indexfile)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1611
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1612
    def read():
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1613
        with opener(indexfile) as fh:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1614
            fh.read()
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1615
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1616
    def parseindex():
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1617
        revlogio.parseindex(data, inline)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1618
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1619
    def getentry(revornode):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1620
        index = revlogio.parseindex(data, inline)[0]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1621
        index[revornode]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1622
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1623
    def getentries(revs, count=1):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1624
        index = revlogio.parseindex(data, inline)[0]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1625
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1626
        for i in range(count):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1627
            for rev in revs:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1628
                index[rev]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1629
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1630
    def resolvenode(node):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1631
        nodemap = revlogio.parseindex(data, inline)[1]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1632
        # This only works for the C code.
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1633
        if nodemap is None:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1634
            return
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1635
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1636
        try:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1637
            nodemap[node]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1638
        except error.RevlogError:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1639
            pass
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1640
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1641
    def resolvenodes(nodes, count=1):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1642
        nodemap = revlogio.parseindex(data, inline)[1]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1643
        if nodemap is None:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1644
            return
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1645
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1646
        for i in range(count):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1647
            for node in nodes:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1648
                try:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1649
                    nodemap[node]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1650
                except error.RevlogError:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1651
                    pass
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1652
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1653
    benches = [
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1654
        (constructor, b'revlog constructor'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1655
        (read, b'read'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1656
        (parseindex, b'create index object'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1657
        (lambda: getentry(0), b'retrieve index entry for rev 0'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1658
        (lambda: resolvenode(b'a' * 20), b'look up missing node'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1659
        (lambda: resolvenode(node0), b'look up node at rev 0'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1660
        (lambda: resolvenode(node25), b'look up node at 1/4 len'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1661
        (lambda: resolvenode(node50), b'look up node at 1/2 len'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1662
        (lambda: resolvenode(node75), b'look up node at 3/4 len'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1663
        (lambda: resolvenode(node100), b'look up node at tip'),
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1664
        # 2x variation is to measure caching impact.
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1665
        (lambda: resolvenodes(allnodes),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1666
         b'look up all nodes (forward)'),
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1667
        (lambda: resolvenodes(allnodes, 2),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1668
         b'look up all nodes 2x (forward)'),
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1669
        (lambda: resolvenodes(allnodesrev),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1670
         b'look up all nodes (reverse)'),
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1671
        (lambda: resolvenodes(allnodesrev, 2),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1672
         b'look up all nodes 2x (reverse)'),
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1673
        (lambda: getentries(allrevs),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1674
         b'retrieve all index entries (forward)'),
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1675
        (lambda: getentries(allrevs, 2),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1676
         b'retrieve all index entries 2x (forward)'),
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1677
        (lambda: getentries(allrevsrev),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1678
         b'retrieve all index entries (reverse)'),
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1679
        (lambda: getentries(allrevsrev, 2),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1680
         b'retrieve all index entries 2x (reverse)'),
32565
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1681
    ]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1682
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1683
    for fn, title in benches:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1684
        timer, fm = gettimer(ui, opts)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1685
        timer(fn, title=title)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1686
        fm.end()
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32564
diff changeset
  1687
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1688
@command(b'perfrevlogrevisions', revlogopts + formatteropts +
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1689
         [(b'd', b'dist', 100, b'distance between the revisions'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1690
          (b's', b'startrev', 0, b'revision to start reading at'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1691
          (b'', b'reverse', False, b'read in reverse')],
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1692
         b'-c|-m|FILE')
32564
7236facefd4f perf: rename perfrevlog to perfrevlogrevisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32501
diff changeset
  1693
def perfrevlogrevisions(ui, repo, file_=None, startrev=0, reverse=False,
7236facefd4f perf: rename perfrevlog to perfrevlogrevisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32501
diff changeset
  1694
                        **opts):
27492
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
  1695
    """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
  1696
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
  1697
    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
  1698
    the specified revlog.
27493
14b0930105da perf: make start revision configurable for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27492
diff changeset
  1699
14b0930105da perf: make start revision configurable for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27492
diff changeset
  1700
    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
  1701
    """
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1702
    opts = _byteskwargs(opts)
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1703
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1704
    rl = cmdutil.openrevlog(repo, b'perfrevlogrevisions', file_, opts)
32272
4c6b2076d292 perf: move revlog construction and length calculation out of benchmark
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32271
diff changeset
  1705
    rllen = getlen(ui)(rl)
30019
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1706
40143
d5d28d360a19 pref: support negative indexing in perfrevlogrevisions
Boris Feld <boris.feld@octobus.net>
parents: 40142
diff changeset
  1707
    if startrev < 0:
d5d28d360a19 pref: support negative indexing in perfrevlogrevisions
Boris Feld <boris.feld@octobus.net>
parents: 40142
diff changeset
  1708
        startrev = rllen + startrev
d5d28d360a19 pref: support negative indexing in perfrevlogrevisions
Boris Feld <boris.feld@octobus.net>
parents: 40142
diff changeset
  1709
11694
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
  1710
    def d():
32272
4c6b2076d292 perf: move revlog construction and length calculation out of benchmark
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32271
diff changeset
  1711
        rl.clearcaches()
30019
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1712
32264
6b582f9b6e5e perf: don't clobber startrev variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32246
diff changeset
  1713
        beginrev = startrev
32272
4c6b2076d292 perf: move revlog construction and length calculation out of benchmark
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32271
diff changeset
  1714
        endrev = rllen
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1715
        dist = opts[b'dist']
30019
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1716
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1717
        if reverse:
40587
cbd251d479bb perf: fix perfrevlogrevisions --reverse
Boris Feld <boris.feld@octobus.net>
parents: 40581
diff changeset
  1718
            beginrev, endrev = endrev - 1, beginrev - 1
30019
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1719
            dist = -1 * dist
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1720
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  1721
        for x in _xrange(beginrev, endrev, dist):
32337
d7efaf6275a7 perf: always pass node to revlog.revision()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32272
diff changeset
  1722
            # Old revisions don't support passing int.
d7efaf6275a7 perf: always pass node to revlog.revision()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32272
diff changeset
  1723
            n = rl.node(x)
d7efaf6275a7 perf: always pass node to revlog.revision()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32272
diff changeset
  1724
            rl.revision(n)
11694
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
  1725
32265
c68c400d0a2d perf: move gettimer() call
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32264
diff changeset
  1726
    timer, fm = gettimer(ui, opts)
11694
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
  1727
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1728
    fm.end()
11694
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
  1729
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1730
@command(b'perfrevlogwrite', revlogopts + formatteropts +
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1731
         [(b's', b'startrev', 1000, b'revision to start writing at'),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1732
          (b'', b'stoprev', -1, b'last revision to write'),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1733
          (b'', b'count', 3, b'last revision to write'),
40598
4dd7edeb3da9 perf: offer full details in perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40597
diff changeset
  1734
          (b'', b'details', False, b'print timing for every revisions tested'),
40600
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1735
          (b'', b'source', b'full', b'the kind of data feed in the revlog'),
40605
4756a33d0d31 perf: add a lazydeltabase option to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40604
diff changeset
  1736
          (b'', b'lazydeltabase', True, b'try the provided delta first'),
40990
21a9cace4bbf perfrevflogwrite: clear revlog cache between each write
Boris Feld <boris.feld@octobus.net>
parents: 40969
diff changeset
  1737
          (b'', b'clear-caches', True, b'clear revlog cache between calls'),
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1738
         ],
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1739
         b'-c|-m|FILE')
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1740
def perfrevlogwrite(ui, repo, file_=None, startrev=1000, stoprev=-1, **opts):
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1741
    """Benchmark writing a series of revisions to a revlog.
40600
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1742
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1743
    Possible source values are:
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1744
    * `full`: add from a full text (default).
40601
6c2357029364 perf: add `parent-1` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40600
diff changeset
  1745
    * `parent-1`: add from a delta to the first parent
40602
b5b3dd4e40c3 perf: add `parent-2` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40601
diff changeset
  1746
    * `parent-2`: add from a delta to the second parent if it exists
b5b3dd4e40c3 perf: add `parent-2` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40601
diff changeset
  1747
                  (use a delta from the first parent otherwise)
40603
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1748
    * `parent-smallest`: add from the smallest delta (either p1 or p2)
40604
355ae096faef perf: add `storage` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40603
diff changeset
  1749
    * `storage`: add from the existing precomputed deltas
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1750
    """
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1751
    opts = _byteskwargs(opts)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1752
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1753
    rl = cmdutil.openrevlog(repo, b'perfrevlogwrite', file_, opts)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1754
    rllen = getlen(ui)(rl)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1755
    if startrev < 0:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1756
        startrev = rllen + startrev
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1757
    if stoprev < 0:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1758
        stoprev = rllen + stoprev
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1759
40605
4756a33d0d31 perf: add a lazydeltabase option to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40604
diff changeset
  1760
    lazydeltabase = opts['lazydeltabase']
40600
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1761
    source = opts['source']
41012
e88ced97151d perfrevlogwrite: fix a typo in the option name
Boris Feld <boris.feld@octobus.net>
parents: 40990
diff changeset
  1762
    clearcaches = opts['clear_caches']
40604
355ae096faef perf: add `storage` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40603
diff changeset
  1763
    validsource = (b'full', b'parent-1', b'parent-2', b'parent-smallest',
355ae096faef perf: add `storage` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40603
diff changeset
  1764
                   b'storage')
40600
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1765
    if source not in validsource:
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1766
        raise error.Abort('invalid source type: %s' % source)
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1767
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1768
    ### actually gather results
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1769
    count = opts['count']
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1770
    if count <= 0:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1771
        raise error.Abort('invalide run count: %d' % count)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1772
    allresults = []
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1773
    for c in range(count):
40605
4756a33d0d31 perf: add a lazydeltabase option to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40604
diff changeset
  1774
        timing = _timeonewrite(ui, rl, source, startrev, stoprev, c + 1,
40990
21a9cace4bbf perfrevflogwrite: clear revlog cache between each write
Boris Feld <boris.feld@octobus.net>
parents: 40969
diff changeset
  1775
                               lazydeltabase=lazydeltabase,
21a9cace4bbf perfrevflogwrite: clear revlog cache between each write
Boris Feld <boris.feld@octobus.net>
parents: 40969
diff changeset
  1776
                               clearcaches=clearcaches)
40600
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1777
        allresults.append(timing)
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1778
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1779
    ### consolidate the results in a single list
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1780
    results = []
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1781
    for idx, (rev, t) in enumerate(allresults[0]):
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1782
        ts = [t]
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1783
        for other in allresults[1:]:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1784
            orev, ot = other[idx]
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1785
            assert orev == rev
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1786
            ts.append(ot)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1787
        results.append((rev, ts))
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1788
    resultcount = len(results)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1789
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1790
    ### Compute and display relevant statistics
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1791
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1792
    # get a formatter
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1793
    fm = ui.formatter(b'perf', opts)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1794
    displayall = ui.configbool(b"perf", b"all-timing", False)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1795
40598
4dd7edeb3da9 perf: offer full details in perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40597
diff changeset
  1796
    # print individual details if requested
4dd7edeb3da9 perf: offer full details in perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40597
diff changeset
  1797
    if opts['details']:
4dd7edeb3da9 perf: offer full details in perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40597
diff changeset
  1798
        for idx, item in enumerate(results, 1):
4dd7edeb3da9 perf: offer full details in perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40597
diff changeset
  1799
            rev, data = item
4dd7edeb3da9 perf: offer full details in perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40597
diff changeset
  1800
            title = 'revisions #%d of %d, rev %d' % (idx, resultcount, rev)
4dd7edeb3da9 perf: offer full details in perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40597
diff changeset
  1801
            formatone(fm, data, title=title, displayall=displayall)
4dd7edeb3da9 perf: offer full details in perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40597
diff changeset
  1802
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1803
    # sorts results by median time
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1804
    results.sort(key=lambda x: sorted(x[1])[len(x[1]) // 2])
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1805
    # list of (name, index) to display)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1806
    relevants = [
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1807
        ("min", 0),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1808
        ("10%", resultcount * 10 // 100),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1809
        ("25%", resultcount * 25 // 100),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1810
        ("50%", resultcount * 70 // 100),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1811
        ("75%", resultcount * 75 // 100),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1812
        ("90%", resultcount * 90 // 100),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1813
        ("95%", resultcount * 95 // 100),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1814
        ("99%", resultcount * 99 // 100),
40969
74ee5ff1e81c perf: report more of the higher range in perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40961
diff changeset
  1815
        ("99.9%", resultcount * 999 // 1000),
74ee5ff1e81c perf: report more of the higher range in perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40961
diff changeset
  1816
        ("99.99%", resultcount * 9999 // 10000),
74ee5ff1e81c perf: report more of the higher range in perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40961
diff changeset
  1817
        ("99.999%", resultcount * 99999 // 100000),
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1818
        ("max", -1),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1819
    ]
40599
c63081cd3902 perf: only display the total time for perfrevlogwrite if quiet
Boris Feld <boris.feld@octobus.net>
parents: 40598
diff changeset
  1820
    if not ui.quiet:
c63081cd3902 perf: only display the total time for perfrevlogwrite if quiet
Boris Feld <boris.feld@octobus.net>
parents: 40598
diff changeset
  1821
        for name, idx in relevants:
c63081cd3902 perf: only display the total time for perfrevlogwrite if quiet
Boris Feld <boris.feld@octobus.net>
parents: 40598
diff changeset
  1822
            data = results[idx]
c63081cd3902 perf: only display the total time for perfrevlogwrite if quiet
Boris Feld <boris.feld@octobus.net>
parents: 40598
diff changeset
  1823
            title = '%s of %d, rev %d' % (name, resultcount, data[0])
c63081cd3902 perf: only display the total time for perfrevlogwrite if quiet
Boris Feld <boris.feld@octobus.net>
parents: 40598
diff changeset
  1824
            formatone(fm, data[1], title=title, displayall=displayall)
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1825
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1826
    # XXX summing that many float will not be very precise, we ignore this fact
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1827
    # for now
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1828
    totaltime = []
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1829
    for item in allresults:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1830
        totaltime.append((sum(x[1][0] for x in item),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1831
                          sum(x[1][1] for x in item),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1832
                          sum(x[1][2] for x in item),)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1833
        )
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1834
    formatone(fm, totaltime, title="total time (%d revs)" % resultcount,
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1835
              displayall=displayall)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1836
    fm.end()
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1837
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1838
class _faketr(object):
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1839
    def add(s, x, y, z=None):
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1840
        return None
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1841
40605
4756a33d0d31 perf: add a lazydeltabase option to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40604
diff changeset
  1842
def _timeonewrite(ui, orig, source, startrev, stoprev, runidx=None,
40990
21a9cace4bbf perfrevflogwrite: clear revlog cache between each write
Boris Feld <boris.feld@octobus.net>
parents: 40969
diff changeset
  1843
                  lazydeltabase=True, clearcaches=True):
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1844
    timings = []
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1845
    tr = _faketr()
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1846
    with _temprevlog(ui, orig, startrev) as dest:
40605
4756a33d0d31 perf: add a lazydeltabase option to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40604
diff changeset
  1847
        dest._lazydeltabase = lazydeltabase
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1848
        revs = list(orig.revs(startrev, stoprev))
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1849
        total = len(revs)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1850
        topic = 'adding'
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1851
        if runidx is not None:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1852
            topic += ' (run #%d)' % runidx
41156
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1853
         # Support both old and new progress API
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1854
        if util.safehasattr(ui, 'makeprogress'):
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1855
            progress = ui.makeprogress(topic, unit='revs', total=total)
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1856
            def updateprogress(pos):
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1857
                progress.update(pos)
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1858
            def completeprogress():
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1859
                progress.complete()
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1860
        else:
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1861
            def updateprogress(pos):
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1862
                ui.progress(topic, pos, unit='revs', total=total)
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1863
            def completeprogress():
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1864
                ui.progress(topic, None, unit='revs', total=total)
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1865
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1866
        for idx, rev in enumerate(revs):
41156
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1867
            updateprogress(idx)
40600
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1868
            addargs, addkwargs = _getrevisionseed(orig, rev, tr, source)
40990
21a9cace4bbf perfrevflogwrite: clear revlog cache between each write
Boris Feld <boris.feld@octobus.net>
parents: 40969
diff changeset
  1869
            if clearcaches:
21a9cace4bbf perfrevflogwrite: clear revlog cache between each write
Boris Feld <boris.feld@octobus.net>
parents: 40969
diff changeset
  1870
                dest.index.clearcaches()
21a9cace4bbf perfrevflogwrite: clear revlog cache between each write
Boris Feld <boris.feld@octobus.net>
parents: 40969
diff changeset
  1871
                dest.clearcaches()
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1872
            with timeone() as r:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1873
                dest.addrawrevision(*addargs, **addkwargs)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1874
            timings.append((rev, r[0]))
41156
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1875
        updateprogress(total)
f36fd52dae8f perfrevlogwrite: use progress helper on modern hg
Martin von Zweigbergk <martinvonz@google.com>
parents: 41012
diff changeset
  1876
        completeprogress()
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1877
    return timings
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1878
40600
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1879
def _getrevisionseed(orig, rev, tr, source):
40602
b5b3dd4e40c3 perf: add `parent-2` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40601
diff changeset
  1880
    from mercurial.node import nullid
b5b3dd4e40c3 perf: add `parent-2` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40601
diff changeset
  1881
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1882
    linkrev = orig.linkrev(rev)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1883
    node = orig.node(rev)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1884
    p1, p2 = orig.parents(node)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1885
    flags = orig.flags(rev)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1886
    cachedelta = None
40600
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1887
    text = None
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1888
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1889
    if source == b'full':
631011ff6771 perf: add the notion of "source" to perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40599
diff changeset
  1890
        text = orig.revision(rev)
40601
6c2357029364 perf: add `parent-1` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40600
diff changeset
  1891
    elif source == b'parent-1':
6c2357029364 perf: add `parent-1` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40600
diff changeset
  1892
        baserev = orig.rev(p1)
6c2357029364 perf: add `parent-1` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40600
diff changeset
  1893
        cachedelta = (baserev, orig.revdiff(p1, rev))
40602
b5b3dd4e40c3 perf: add `parent-2` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40601
diff changeset
  1894
    elif source == b'parent-2':
b5b3dd4e40c3 perf: add `parent-2` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40601
diff changeset
  1895
        parent = p2
b5b3dd4e40c3 perf: add `parent-2` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40601
diff changeset
  1896
        if p2 == nullid:
b5b3dd4e40c3 perf: add `parent-2` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40601
diff changeset
  1897
            parent = p1
b5b3dd4e40c3 perf: add `parent-2` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40601
diff changeset
  1898
        baserev = orig.rev(parent)
b5b3dd4e40c3 perf: add `parent-2` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40601
diff changeset
  1899
        cachedelta = (baserev, orig.revdiff(parent, rev))
40603
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1900
    elif source == b'parent-smallest':
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1901
        p1diff = orig.revdiff(p1, rev)
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1902
        parent = p1
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1903
        diff = p1diff
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1904
        if p2 != nullid:
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1905
            p2diff = orig.revdiff(p2, rev)
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1906
            if len(p1diff) > len(p2diff):
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1907
                parent = p2
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1908
                diff = p2diff
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1909
        baserev = orig.rev(parent)
e14d44772fb3 perf: add `parent-smallest` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40602
diff changeset
  1910
        cachedelta = (baserev, diff)
40604
355ae096faef perf: add `storage` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40603
diff changeset
  1911
    elif source == b'storage':
355ae096faef perf: add `storage` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40603
diff changeset
  1912
        baserev = orig.deltaparent(rev)
355ae096faef perf: add `storage` as possible source for perfrevlogwrite
Boris Feld <boris.feld@octobus.net>
parents: 40603
diff changeset
  1913
        cachedelta = (baserev, orig.revdiff(orig.node(baserev), rev))
40597
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1914
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1915
    return ((text, tr, linkrev, p1, p2),
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1916
            {'node': node, 'flags': flags, 'cachedelta': cachedelta})
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1917
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1918
@contextlib.contextmanager
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1919
def _temprevlog(ui, orig, truncaterev):
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1920
    from mercurial import vfs as vfsmod
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1921
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1922
    if orig._inline:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1923
        raise error.Abort('not supporting inline revlog (yet)')
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1924
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1925
    origindexpath = orig.opener.join(orig.indexfile)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1926
    origdatapath = orig.opener.join(orig.datafile)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1927
    indexname = 'revlog.i'
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1928
    dataname = 'revlog.d'
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1929
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1930
    tmpdir = tempfile.mkdtemp(prefix='tmp-hgperf-')
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1931
    try:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1932
        # copy the data file in a temporary directory
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1933
        ui.debug('copying data in %s\n' % tmpdir)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1934
        destindexpath = os.path.join(tmpdir, 'revlog.i')
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1935
        destdatapath = os.path.join(tmpdir, 'revlog.d')
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1936
        shutil.copyfile(origindexpath, destindexpath)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1937
        shutil.copyfile(origdatapath, destdatapath)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1938
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1939
        # remove the data we want to add again
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1940
        ui.debug('truncating data to be rewritten\n')
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1941
        with open(destindexpath, 'ab') as index:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1942
            index.seek(0)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1943
            index.truncate(truncaterev * orig._io.size)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1944
        with open(destdatapath, 'ab') as data:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1945
            data.seek(0)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1946
            data.truncate(orig.start(truncaterev))
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1947
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1948
        # instantiate a new revlog from the temporary copy
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1949
        ui.debug('truncating adding to be rewritten\n')
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1950
        vfs = vfsmod.vfs(tmpdir)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1951
        vfs.options = getattr(orig.opener, 'options', None)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1952
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1953
        dest = revlog.revlog(vfs,
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1954
                             indexfile=indexname,
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1955
                             datafile=dataname)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1956
        if dest._inline:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1957
            raise error.Abort('not supporting inline revlog (yet)')
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1958
        # make sure internals are initialized
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1959
        dest.revision(len(dest) - 1)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1960
        yield dest
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1961
        del dest, vfs
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1962
    finally:
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1963
        shutil.rmtree(tmpdir, True)
164b2e77f9a5 perf: introduce a perfrevlogwrite command
Boris Feld <boris.feld@octobus.net>
parents: 40587
diff changeset
  1964
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1965
@command(b'perfrevlogchunks', revlogopts + formatteropts +
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1966
         [(b'e', b'engines', b'', b'compression engines to use'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1967
          (b's', b'startrev', 0, b'revision to start at')],
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1968
         b'-c|-m|FILE')
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1969
def perfrevlogchunks(ui, repo, file_=None, engines=None, startrev=0, **opts):
30460
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  1970
    """Benchmark operations on revlog chunks.
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  1971
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  1972
    Logically, each revlog is a collection of fulltext revisions. However,
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  1973
    stored within each revlog are "chunks" of possibly compressed data. This
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  1974
    data needs to be read and decompressed or compressed and written.
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  1975
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  1976
    This command measures the time it takes to read+decompress and recompress
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  1977
    chunks in a revlog. It effectively isolates I/O and compression performance.
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  1978
    For measurements of higher-level operations like resolving revisions,
32564
7236facefd4f perf: rename perfrevlog to perfrevlogrevisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32501
diff changeset
  1979
    see ``perfrevlogrevisions`` and ``perfrevlogrevision``.
30460
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  1980
    """
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1981
    opts = _byteskwargs(opts)
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  1982
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1983
    rl = cmdutil.openrevlog(repo, b'perfrevlogchunks', file_, opts)
32269
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  1984
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  1985
    # _chunkraw was renamed to _getsegmentforrevs.
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  1986
    try:
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  1987
        segmentforrevs = rl._getsegmentforrevs
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  1988
    except AttributeError:
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  1989
        segmentforrevs = rl._chunkraw
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1990
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1991
    # Verify engines argument.
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1992
    if engines:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1993
        engines = set(e.strip() for e in engines.split(b','))
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1994
        for engine in engines:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1995
            try:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1996
                util.compressionengines[engine]
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1997
            except KeyError:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  1998
                raise error.Abort(b'unknown compression engine: %s' % engine)
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1999
    else:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2000
        engines = []
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2001
        for e in util.compengines:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2002
            engine = util.compengines[e]
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2003
            try:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2004
                if engine.available():
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2005
                    engine.revlogcompressor().compress(b'dummy')
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2006
                    engines.append(e)
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2007
            except NotImplementedError:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2008
                pass
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2009
30460
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2010
    revs = list(rl.revs(startrev, len(rl) - 1))
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2011
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2012
    def rlfh(rl):
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2013
        if rl._inline:
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2014
            return getsvfs(repo)(rl.indexfile)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2015
        else:
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2016
            return getsvfs(repo)(rl.datafile)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2017
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2018
    def doread():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2019
        rl.clearcaches()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2020
        for rev in revs:
32268
112ba1c7d65d perf: store reference to revlog._chunkraw in a local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32265
diff changeset
  2021
            segmentforrevs(rev, rev)
30460
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2022
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2023
    def doreadcachedfh():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2024
        rl.clearcaches()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2025
        fh = rlfh(rl)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2026
        for rev in revs:
32268
112ba1c7d65d perf: store reference to revlog._chunkraw in a local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32265
diff changeset
  2027
            segmentforrevs(rev, rev, df=fh)
30460
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2028
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2029
    def doreadbatch():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2030
        rl.clearcaches()
32268
112ba1c7d65d perf: store reference to revlog._chunkraw in a local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32265
diff changeset
  2031
        segmentforrevs(revs[0], revs[-1])
30460
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2032
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2033
    def doreadbatchcachedfh():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2034
        rl.clearcaches()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2035
        fh = rlfh(rl)
32268
112ba1c7d65d perf: store reference to revlog._chunkraw in a local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32265
diff changeset
  2036
        segmentforrevs(revs[0], revs[-1], df=fh)
30460
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2037
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2038
    def dochunk():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2039
        rl.clearcaches()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2040
        fh = rlfh(rl)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2041
        for rev in revs:
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2042
            rl._chunk(rev, df=fh)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2043
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2044
    chunks = [None]
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2045
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2046
    def dochunkbatch():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2047
        rl.clearcaches()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2048
        fh = rlfh(rl)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2049
        # Save chunks as a side-effect.
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2050
        chunks[0] = rl._chunks(revs, df=fh)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2051
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2052
    def docompress(compressor):
30460
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2053
        rl.clearcaches()
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2054
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2055
        try:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2056
            # Swap in the requested compression engine.
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2057
            oldcompressor = rl._compressor
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2058
            rl._compressor = compressor
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2059
            for chunk in chunks[0]:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2060
                rl.compress(chunk)
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2061
        finally:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2062
            rl._compressor = oldcompressor
30460
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2063
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2064
    benches = [
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2065
        (lambda: doread(), b'read'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2066
        (lambda: doreadcachedfh(), b'read w/ reused fd'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2067
        (lambda: doreadbatch(), b'read batch'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2068
        (lambda: doreadbatchcachedfh(), b'read batch w/ reused fd'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2069
        (lambda: dochunk(), b'chunk'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2070
        (lambda: dochunkbatch(), b'chunk batch'),
30460
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2071
    ]
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2072
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2073
    for engine in sorted(engines):
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2074
        compressor = util.compengines[engine].revlogcompressor()
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2075
        benches.append((functools.partial(docompress, compressor),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2076
                        b'compress w/ %s' % engine))
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  2077
30460
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2078
    for fn, title in benches:
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2079
        timer, fm = gettimer(ui, opts)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2080
        timer(fn, title=title)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2081
        fm.end()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30435
diff changeset
  2082
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2083
@command(b'perfrevlogrevision', revlogopts + formatteropts +
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2084
         [(b'', b'cache', False, b'use caches instead of clearing')],
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2085
         b'-c|-m|FILE REV')
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2086
def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2087
    """Benchmark obtaining a revlog revision.
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2088
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2089
    Obtaining a revlog revision consists of roughly the following steps:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2090
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2091
    1. Compute the delta chain
40581
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2092
    2. Slice the delta chain if applicable
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2093
    3. Obtain the raw chunks for that delta chain
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2094
    4. Decompress each raw chunk
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2095
    5. Apply binary patches to obtain fulltext
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2096
    6. Verify hash of fulltext
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2097
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2098
    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
  2099
    """
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2100
    opts = _byteskwargs(opts)
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2101
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2102
    if opts.get(b'changelog') or opts.get(b'manifest'):
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2103
        file_, rev = None, file_
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2104
    elif rev is None:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2105
        raise error.CommandError(b'perfrevlogrevision', b'invalid arguments')
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2106
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2107
    r = cmdutil.openrevlog(repo, b'perfrevlogrevision', file_, opts)
32269
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  2108
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  2109
    # _chunkraw was renamed to _getsegmentforrevs.
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  2110
    try:
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  2111
        segmentforrevs = r._getsegmentforrevs
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  2112
    except AttributeError:
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  2113
        segmentforrevs = r._chunkraw
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32268
diff changeset
  2114
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2115
    node = r.lookup(rev)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2116
    rev = r.rev(node)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2117
30914
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2118
    def getrawchunks(data, chain):
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2119
        start = r.start
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2120
        length = r.length
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2121
        inline = r._inline
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2122
        iosize = r._io.size
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2123
        buffer = util.buffer
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2124
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2125
        chunks = []
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2126
        ladd = chunks.append
40580
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2127
        for idx, item in enumerate(chain):
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2128
            offset = start(item[0])
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2129
            bits = data[idx]
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2130
            for rev in item:
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2131
                chunkstart = start(rev)
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2132
                if inline:
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2133
                    chunkstart += (rev + 1) * iosize
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2134
                chunklength = length(rev)
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2135
                ladd(buffer(bits, chunkstart - offset, chunklength))
30914
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2136
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2137
        return chunks
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2138
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2139
    def dodeltachain(rev):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2140
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2141
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2142
        r._deltachain(rev)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2143
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2144
    def doread(chain):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2145
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2146
            r.clearcaches()
40580
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2147
        for item in slicedchain:
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2148
            segmentforrevs(item[0], item[-1])
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2149
40581
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2150
    def doslice(r, chain, size):
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2151
        for s in slicechunk(r, chain, targetsize=size):
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2152
            pass
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2153
30914
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2154
    def dorawchunks(data, chain):
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2155
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2156
            r.clearcaches()
30914
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2157
        getrawchunks(data, chain)
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2158
30914
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2159
    def dodecompress(chunks):
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2160
        decomp = r.decompress
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2161
        for chunk in chunks:
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  2162
            decomp(chunk)
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2163
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2164
    def dopatch(text, bins):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2165
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2166
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2167
        mdiff.patches(text, bins)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2168
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2169
    def dohash(text):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2170
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2171
            r.clearcaches()
30589
be5b2098a817 revlog: merge hash checking subfunctions
Remi Chaintron <remi@fb.com>
parents: 30460
diff changeset
  2172
        r.checkhash(text, node, rev=rev)
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2173
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2174
    def dorevision():
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2175
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2176
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2177
        r.revision(node)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2178
40580
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2179
    try:
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2180
        from mercurial.revlogutils.deltas import slicechunk
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2181
    except ImportError:
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2182
        slicechunk = getattr(revlog, '_slicechunk', None)
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2183
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2184
    size = r.length(rev)
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2185
    chain = r._deltachain(rev)[0]
40580
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2186
    if not getattr(r, '_withsparseread', False):
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2187
        slicedchain = (chain,)
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2188
    else:
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2189
        slicedchain = tuple(slicechunk(r, chain, targetsize=size))
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2190
    data = [segmentforrevs(seg[0], seg[-1])[1] for seg in slicedchain]
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2191
    rawchunks = getrawchunks(data, slicedchain)
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2192
    bins = r._chunks(chain)
40214
b456b2e0ad9f py3: make test-contrib-perf.t work on python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40145
diff changeset
  2193
    text = bytes(bins[0])
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2194
    bins = bins[1:]
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2195
    text = mdiff.patches(text, bins)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2196
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2197
    benches = [
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2198
        (lambda: dorevision(), b'full'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2199
        (lambda: dodeltachain(rev), b'deltachain'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2200
        (lambda: doread(chain), b'read'),
40581
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2201
    ]
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2202
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2203
    if getattr(r, '_withsparseread', False):
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2204
        slicing = (lambda: doslice(r, chain, size), b'slice-sparse-chain')
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2205
        benches.append(slicing)
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2206
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2207
    benches.extend([
40580
914079ee3334 perf: teach perfrevlogrevision about sparse reading
Boris Feld <boris.feld@octobus.net>
parents: 40579
diff changeset
  2208
        (lambda: dorawchunks(data, slicedchain), b'rawchunks'),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2209
        (lambda: dodecompress(rawchunks), b'decompress'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2210
        (lambda: dopatch(text, bins), b'patch'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2211
        (lambda: dohash(text), b'hash'),
40581
e6c8a0fd3db4 perf: measure slicing time in perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40580
diff changeset
  2212
    ])
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2213
40579
cf3bef7f162b perf: use the same timer for all section of perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40349
diff changeset
  2214
    timer, fm = gettimer(ui, opts)
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2215
    for fn, title in benches:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2216
        timer(fn, title=title)
40579
cf3bef7f162b perf: use the same timer for all section of perfrevlogrevision
Boris Feld <boris.feld@octobus.net>
parents: 40349
diff changeset
  2217
    fm.end()
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  2218
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2219
@command(b'perfrevset',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2220
         [(b'C', b'clear', False, b'clear volatile cache between each call.'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2221
          (b'', b'contexts', False, b'obtain changectx for each revision')]
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2222
         + formatteropts, b"REVSET")
27072
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
  2223
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
  2224
    """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
  2225
18644
3e92772d5383 spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents: 18304
diff changeset
  2226
    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
  2227
    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
  2228
    and obsolete related cache."""
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2229
    opts = _byteskwargs(opts)
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2230
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  2231
    timer, fm = gettimer(ui, opts)
18062
1471f5e83686 perf: add a command to measure revset performance
Siddharth Agarwal <sid0@fb.com>
parents: 18033
diff changeset
  2232
    def d():
18239
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
  2233
        if clear:
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
  2234
            repo.invalidatevolatilesets()
27072
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
  2235
        if contexts:
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
  2236
            for ctx in repo.set(expr): pass
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
  2237
        else:
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
  2238
            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
  2239
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  2240
    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
  2241
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2242
@command(b'perfvolatilesets',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2243
         [(b'', b'clear-obsstore', False, b'drop obsstore between each call.'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2244
          ] + formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  2245
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
  2246
    """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
  2247
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
  2248
    Volatile set computes element related to filtering and obsolescence."""
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2249
    opts = _byteskwargs(opts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  2250
    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
  2251
    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
  2252
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
  2253
    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
  2254
        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
  2255
            repo.invalidatevolatilesets()
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2256
            if opts[b'clear_obsstore']:
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2257
                clearfilecache(repo, b'obsstore')
18240
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
  2258
            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
  2259
        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
  2260
18241
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  2261
    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
  2262
    if names:
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  2263
        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
  2264
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  2265
    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
  2266
        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
  2267
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
  2268
    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
  2269
        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
  2270
            repo.invalidatevolatilesets()
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2271
            if opts[b'clear_obsstore']:
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2272
                clearfilecache(repo, b'obsstore')
20205
d67a7758da6d perf: fix perfvolatilesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20178
diff changeset
  2273
            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
  2274
        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
  2275
18241
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  2276
    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
  2277
    if names:
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  2278
        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
  2279
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  2280
    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
  2281
        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
  2282
    fm.end()
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2283
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2284
@command(b'perfbranchmap',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2285
         [(b'f', b'full', False,
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2286
           b'Includes build time of subset'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2287
          (b'', b'clear-revbranch', False,
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2288
           b'purge the revbranch cache between computation'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2289
          ] + formatteropts)
36393
c25290b98190 perfbranchmap: allow to select the filter to benchmark
Boris Feld <boris.feld@octobus.net>
parents: 36392
diff changeset
  2290
def perfbranchmap(ui, repo, *filternames, **opts):
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2291
    """benchmark the update of a branchmap
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2292
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2293
    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
  2294
    """
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2295
    opts = _byteskwargs(opts)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2296
    full = opts.get(b"full", False)
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2297
    clear_revbranch = opts.get(b"clear_revbranch", False)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  2298
    timer, fm = gettimer(ui, opts)
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2299
    def getbranchmap(filtername):
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2300
        """generate a benchmark function for the filtername"""
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2301
        if filtername is None:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2302
            view = repo
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2303
        else:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2304
            view = repo.filtered(filtername)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2305
        def d():
32730
326c0e2c1a1d perfbranchmap: add an option to purge the revbranch cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32565
diff changeset
  2306
            if clear_revbranch:
326c0e2c1a1d perfbranchmap: add an option to purge the revbranch cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32565
diff changeset
  2307
                repo.revbranchcache()._clear()
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2308
            if full:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2309
                view._branchcaches.clear()
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2310
            else:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2311
                view._branchcaches.pop(filtername, None)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2312
            view.branchmap()
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2313
        return d
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2314
    # 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
  2315
    possiblefilters = set(repoview.filtertable)
36393
c25290b98190 perfbranchmap: allow to select the filter to benchmark
Boris Feld <boris.feld@octobus.net>
parents: 36392
diff changeset
  2316
    if filternames:
c25290b98190 perfbranchmap: allow to select the filter to benchmark
Boris Feld <boris.feld@octobus.net>
parents: 36392
diff changeset
  2317
        possiblefilters &= set(filternames)
30144
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
  2318
    subsettable = getbranchmapsubsettable()
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2319
    allfilters = []
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2320
    while possiblefilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2321
        for name in possiblefilters:
30144
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
  2322
            subset = subsettable.get(name)
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2323
            if subset not in possiblefilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2324
                break
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2325
        else:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2326
            assert False, b'subset cycle %s!' % possiblefilters
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2327
        allfilters.append(name)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2328
        possiblefilters.remove(name)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2329
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2330
    # warm the cache
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2331
    if not full:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2332
        for name in allfilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2333
            repo.filtered(name).branchmap()
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2334
    if not filternames or b'unfiltered' in filternames:
36393
c25290b98190 perfbranchmap: allow to select the filter to benchmark
Boris Feld <boris.feld@octobus.net>
parents: 36392
diff changeset
  2335
        # add unfiltered
c25290b98190 perfbranchmap: allow to select the filter to benchmark
Boris Feld <boris.feld@octobus.net>
parents: 36392
diff changeset
  2336
        allfilters.append(None)
30145
113aa6145020 perf: avoid actual writing branch cache out correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30144
diff changeset
  2337
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2338
    branchcacheread = safeattrsetter(branchmap, b'read')
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2339
    branchcachewrite = safeattrsetter(branchmap.branchcache, b'write')
30145
113aa6145020 perf: avoid actual writing branch cache out correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30144
diff changeset
  2340
    branchcacheread.set(lambda repo: None)
113aa6145020 perf: avoid actual writing branch cache out correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30144
diff changeset
  2341
    branchcachewrite.set(lambda bc, repo: None)
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2342
    try:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2343
        for name in allfilters:
36392
df3f7f00a3fc perfbranchmap: display 'unfiltered' for unfiltered performance
Boris Feld <boris.feld@octobus.net>
parents: 36216
diff changeset
  2344
            printname = name
df3f7f00a3fc perfbranchmap: display 'unfiltered' for unfiltered performance
Boris Feld <boris.feld@octobus.net>
parents: 36216
diff changeset
  2345
            if name is None:
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2346
                printname = b'unfiltered'
36392
df3f7f00a3fc perfbranchmap: display 'unfiltered' for unfiltered performance
Boris Feld <boris.feld@octobus.net>
parents: 36216
diff changeset
  2347
            timer(getbranchmap(name), title=str(printname))
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  2348
    finally:
30145
113aa6145020 perf: avoid actual writing branch cache out correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30144
diff changeset
  2349
        branchcacheread.restore()
113aa6145020 perf: avoid actual writing branch cache out correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30144
diff changeset
  2350
        branchcachewrite.restore()
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  2351
    fm.end()
23485
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
  2352
40802
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2353
@command(b'perfbranchmapupdate', [
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2354
     (b'', b'base', [], b'subset of revision to start from'),
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2355
     (b'', b'target', [], b'subset of revision to end with'),
40806
5cbb74999040 perf: add a `--clear-caches` to `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40805
diff changeset
  2356
     (b'', b'clear-caches', False, b'clear cache between each runs')
40802
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2357
    ] + formatteropts)
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2358
def perfbranchmapupdate(ui, repo, base=(), target=(), **opts):
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2359
    """benchmark branchmap update from for <base> revs to <target> revs
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2360
40806
5cbb74999040 perf: add a `--clear-caches` to `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40805
diff changeset
  2361
    If `--clear-caches` is passed, the following items will be reset before
5cbb74999040 perf: add a `--clear-caches` to `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40805
diff changeset
  2362
    each update:
5cbb74999040 perf: add a `--clear-caches` to `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40805
diff changeset
  2363
        * the changelog instance and associated indexes
5cbb74999040 perf: add a `--clear-caches` to `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40805
diff changeset
  2364
        * the rev-branch-cache instance
5cbb74999040 perf: add a `--clear-caches` to `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40805
diff changeset
  2365
40802
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2366
    Examples:
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2367
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2368
       # update for the one last revision
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2369
       $ hg perfbranchmapupdate --base 'not tip' --target 'tip'
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2370
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2371
       $ update for change coming with a new branch
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2372
       $ hg perfbranchmapupdate --base 'stable' --target 'default'
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2373
    """
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2374
    from mercurial import branchmap
40804
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2375
    from mercurial import repoview
40802
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2376
    opts = _byteskwargs(opts)
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2377
    timer, fm = gettimer(ui, opts)
40806
5cbb74999040 perf: add a `--clear-caches` to `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40805
diff changeset
  2378
    clearcaches = opts[b'clear_caches']
40804
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2379
    unfi = repo.unfiltered()
40802
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2380
    x = [None] # used to pass data between closure
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2381
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2382
    # we use a `list` here to avoid possible side effect from smartset
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2383
    baserevs = list(scmutil.revrange(repo, base))
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2384
    targetrevs = list(scmutil.revrange(repo, target))
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2385
    if not baserevs:
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2386
        raise error.Abort(b'no revisions selected for --base')
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2387
    if not targetrevs:
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2388
        raise error.Abort(b'no revisions selected for --target')
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2389
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2390
    # make sure the target branchmap also contains the one in the base
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2391
    targetrevs = list(set(baserevs) | set(targetrevs))
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2392
    targetrevs.sort()
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2393
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2394
    cl = repo.changelog
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2395
    allbaserevs = list(cl.ancestors(baserevs, inclusive=True))
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2396
    allbaserevs.sort()
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2397
    alltargetrevs = frozenset(cl.ancestors(targetrevs, inclusive=True))
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2398
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2399
    newrevs = list(alltargetrevs.difference(allbaserevs))
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2400
    newrevs.sort()
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2401
40804
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2402
    allrevs = frozenset(unfi.changelog.revs())
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2403
    basefilterrevs = frozenset(allrevs.difference(allbaserevs))
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2404
    targetfilterrevs = frozenset(allrevs.difference(alltargetrevs))
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2405
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2406
    def basefilter(repo, visibilityexceptions=None):
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2407
        return basefilterrevs
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2408
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2409
    def targetfilter(repo, visibilityexceptions=None):
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2410
        return targetfilterrevs
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2411
40802
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2412
    msg = b'benchmark of branchmap with %d revisions with %d new ones\n'
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2413
    ui.status(msg % (len(allbaserevs), len(newrevs)))
40804
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2414
    if targetfilterrevs:
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2415
        msg = b'(%d revisions still filtered)\n'
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2416
        ui.status(msg % len(targetfilterrevs))
40802
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2417
40804
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2418
    try:
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2419
        repoview.filtertable[b'__perf_branchmap_update_base'] = basefilter
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2420
        repoview.filtertable[b'__perf_branchmap_update_target'] = targetfilter
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2421
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2422
        baserepo = repo.filtered(b'__perf_branchmap_update_base')
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2423
        targetrepo = repo.filtered(b'__perf_branchmap_update_target')
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2424
40805
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2425
        # try to find an existing branchmap to reuse
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2426
        subsettable = getbranchmapsubsettable()
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2427
        candidatefilter = subsettable.get(None)
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2428
        while candidatefilter is not None:
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2429
            candidatebm = repo.filtered(candidatefilter).branchmap()
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2430
            if candidatebm.validfor(baserepo):
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2431
                filtered = repoview.filterrevs(repo, candidatefilter)
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2432
                missing = [r for r in allbaserevs if r in filtered]
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2433
                base = candidatebm.copy()
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2434
                base.update(baserepo, missing)
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2435
                break
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2436
            candidatefilter = subsettable.get(candidatefilter)
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2437
        else:
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2438
            # no suitable subset where found
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2439
            base = branchmap.branchcache()
58355a1de6b3 perf: start from an existing branchmap if possible
Boris Feld <boris.feld@octobus.net>
parents: 40804
diff changeset
  2440
            base.update(baserepo, allbaserevs)
40802
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2441
40803
95f35c873463 perf: pre-indent some code in `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40802
diff changeset
  2442
        def setup():
95f35c873463 perf: pre-indent some code in `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40802
diff changeset
  2443
            x[0] = base.copy()
40806
5cbb74999040 perf: add a `--clear-caches` to `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40805
diff changeset
  2444
            if clearcaches:
5cbb74999040 perf: add a `--clear-caches` to `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40805
diff changeset
  2445
                unfi._revbranchcache = None
5cbb74999040 perf: add a `--clear-caches` to `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40805
diff changeset
  2446
                clearchangelog(repo)
40802
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2447
40803
95f35c873463 perf: pre-indent some code in `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40802
diff changeset
  2448
        def bench():
40804
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2449
            x[0].update(targetrepo, newrevs)
40803
95f35c873463 perf: pre-indent some code in `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40802
diff changeset
  2450
95f35c873463 perf: pre-indent some code in `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40802
diff changeset
  2451
        timer(bench, setup=setup)
95f35c873463 perf: pre-indent some code in `perfbranchmapupdate`
Boris Feld <boris.feld@octobus.net>
parents: 40802
diff changeset
  2452
        fm.end()
40804
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2453
    finally:
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2454
        repoview.filtertable.pop(b'__perf_branchmap_update_base', None)
b059388d976c perf: rely on repoview for perfbranchmapupdate
Boris Feld <boris.feld@octobus.net>
parents: 40803
diff changeset
  2455
        repoview.filtertable.pop(b'__perf_branchmap_update_target', None)
40802
f723014677a5 perf: add a `perfbranchmapupdate` command
Boris Feld <boris.feld@octobus.net>
parents: 40784
diff changeset
  2456
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2457
@command(b'perfbranchmapload', [
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2458
     (b'f', b'filter', b'', b'Specify repoview filter'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2459
     (b'', b'list', False, b'List brachmap filter caches'),
40741
4240a1da4188 perf: add --clear-revlog flag to branchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40740
diff changeset
  2460
     (b'', b'clear-revlogs', False, b'refresh changelog and manifest'),
4240a1da4188 perf: add --clear-revlog flag to branchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40740
diff changeset
  2461
39151
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 39015
diff changeset
  2462
    ] + formatteropts)
40738
94d76ddac40a perf: update function name to match `perfbranchmapload` command
Boris Feld <boris.feld@octobus.net>
parents: 40737
diff changeset
  2463
def perfbranchmapload(ui, repo, filter=b'', list=False, **opts):
39151
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 39015
diff changeset
  2464
    """benchmark reading the branchmap"""
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2465
    opts = _byteskwargs(opts)
40741
4240a1da4188 perf: add --clear-revlog flag to branchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40740
diff changeset
  2466
    clearrevlogs = opts[b'clear_revlogs']
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2467
39151
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 39015
diff changeset
  2468
    if list:
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 39015
diff changeset
  2469
        for name, kind, st in repo.cachevfs.readdir(stat=True):
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2470
            if name.startswith(b'branch2'):
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2471
                filtername = name.partition(b'-')[2] or b'unfiltered'
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2472
                ui.status(b'%s - %s\n'
39151
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 39015
diff changeset
  2473
                          % (filtername, util.bytecount(st.st_size)))
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 39015
diff changeset
  2474
        return
40759
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2475
    if not filter:
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2476
        filter = None
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2477
    subsettable = getbranchmapsubsettable()
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2478
    if filter is None:
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2479
        repo = repo.unfiltered()
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2480
    else:
39151
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 39015
diff changeset
  2481
        repo = repoview.repoview(repo, filter)
40758
578646b1e2b6 perf: prewarm the branchmap in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40752
diff changeset
  2482
578646b1e2b6 perf: prewarm the branchmap in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40752
diff changeset
  2483
    repo.branchmap() # make sure we have a relevant, up to date branchmap
578646b1e2b6 perf: prewarm the branchmap in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40752
diff changeset
  2484
40759
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2485
    currentfilter = filter
39151
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 39015
diff changeset
  2486
    # try once without timer, the filter may not be cached
40759
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2487
    while branchmap.read(repo) is None:
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2488
        currentfilter = subsettable.get(currentfilter)
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2489
        if currentfilter is None:
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2490
            raise error.Abort(b'No branchmap cached for %s repo'
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2491
                              % (filter or b'unfiltered'))
0a3cc351d718 perf: fallback to subset if ondisk cache is missing in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40758
diff changeset
  2492
        repo = repo.filtered(currentfilter)
39151
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 39015
diff changeset
  2493
    timer, fm = gettimer(ui, opts)
40741
4240a1da4188 perf: add --clear-revlog flag to branchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40740
diff changeset
  2494
    def setup():
4240a1da4188 perf: add --clear-revlog flag to branchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40740
diff changeset
  2495
        if clearrevlogs:
4240a1da4188 perf: add --clear-revlog flag to branchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40740
diff changeset
  2496
            clearchangelog(repo)
40739
30f443d34a7d perf: use an explicit function in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40738
diff changeset
  2497
    def bench():
30f443d34a7d perf: use an explicit function in perfbranchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40738
diff changeset
  2498
        branchmap.read(repo)
40741
4240a1da4188 perf: add --clear-revlog flag to branchmapload
Boris Feld <boris.feld@octobus.net>
parents: 40740
diff changeset
  2499
    timer(bench, setup=setup)
39151
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 39015
diff changeset
  2500
    fm.end()
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 39015
diff changeset
  2501
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2502
@command(b'perfloadmarkers')
23485
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
  2503
def perfloadmarkers(ui, repo):
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
  2504
    """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
  2505
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
  2506
    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
  2507
    timer, fm = gettimer(ui)
30146
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
  2508
    svfs = getsvfs(repo)
148ccd1d9f2f perf: add functions to get vfs-like object for Mercurial earlier than 2.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30145
diff changeset
  2509
    timer(lambda: len(obsolete.obsstore(svfs)))
23485
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
  2510
    fm.end()
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2511
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2512
@command(b'perflrucachedict', formatteropts +
39584
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2513
    [(b'', b'costlimit', 0, b'maximum total cost of items in cache'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2514
     (b'', b'mincost', 0, b'smallest cost of items in cache'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2515
     (b'', b'maxcost', 100, b'maximum cost of items in cache'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2516
     (b'', b'size', 4, b'size of cache'),
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2517
     (b'', b'gets', 10000, b'number of key lookups'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2518
     (b'', b'sets', 10000, b'number of key sets'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2519
     (b'', b'mixed', 10000, b'number of mixed mode operations'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2520
     (b'', b'mixedgetfreq', 50, b'frequency of get vs set ops in mixed mode')],
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2521
    norepo=True)
39584
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2522
def perflrucache(ui, mincost=0, maxcost=100, costlimit=0, size=4,
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2523
                 gets=10000, sets=10000, mixed=10000, mixedgetfreq=50, **opts):
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2524
    opts = _byteskwargs(opts)
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2525
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2526
    def doinit():
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  2527
        for i in _xrange(10000):
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2528
            util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2529
39584
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2530
    costrange = list(range(mincost, maxcost + 1))
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2531
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2532
    values = []
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  2533
    for i in _xrange(size):
39828
c4ab9fa81377 py3: work around the lack of sys.maxint in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39827
diff changeset
  2534
        values.append(random.randint(0, _maxint))
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2535
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2536
    # 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
  2537
    # eviction.
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2538
    getseq = []
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  2539
    for i in _xrange(gets):
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2540
        getseq.append(random.choice(values))
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2541
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2542
    def dogets():
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2543
        d = util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2544
        for v in values:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2545
            d[v] = v
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2546
        for key in getseq:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2547
            value = d[key]
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2548
            value # silence pyflakes warning
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2549
39584
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2550
    def dogetscost():
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2551
        d = util.lrucachedict(size, maxcost=costlimit)
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2552
        for i, v in enumerate(values):
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2553
            d.insert(v, v, cost=costs[i])
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2554
        for key in getseq:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2555
            try:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2556
                value = d[key]
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2557
                value # silence pyflakes warning
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2558
            except KeyError:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2559
                pass
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2560
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2561
    # Set mode tests insertion speed with cache eviction.
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2562
    setseq = []
39584
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2563
    costs = []
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  2564
    for i in _xrange(sets):
39828
c4ab9fa81377 py3: work around the lack of sys.maxint in contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39827
diff changeset
  2565
        setseq.append(random.randint(0, _maxint))
39584
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2566
        costs.append(random.choice(costrange))
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2567
39583
ee087f0d7db5 util: allow lrucachedict to track cost of entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39389
diff changeset
  2568
    def doinserts():
ee087f0d7db5 util: allow lrucachedict to track cost of entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39389
diff changeset
  2569
        d = util.lrucachedict(size)
ee087f0d7db5 util: allow lrucachedict to track cost of entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39389
diff changeset
  2570
        for v in setseq:
ee087f0d7db5 util: allow lrucachedict to track cost of entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39389
diff changeset
  2571
            d.insert(v, v)
ee087f0d7db5 util: allow lrucachedict to track cost of entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39389
diff changeset
  2572
39584
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2573
    def doinsertscost():
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2574
        d = util.lrucachedict(size, maxcost=costlimit)
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2575
        for i, v in enumerate(setseq):
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2576
            d.insert(v, v, cost=costs[i])
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2577
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2578
    def dosets():
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2579
        d = util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2580
        for v in setseq:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2581
            d[v] = v
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2582
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2583
    # Mixed mode randomly performs gets and sets with eviction.
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2584
    mixedops = []
39827
86dbeb7c9a11 py3: switch contrib/perf from xrange to pycompat.xrange
Matt Harbison <matt_harbison@yahoo.com>
parents: 39826
diff changeset
  2585
    for i in _xrange(mixed):
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2586
        r = random.randint(0, 100)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2587
        if r < mixedgetfreq:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2588
            op = 0
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2589
        else:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2590
            op = 1
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2591
39584
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2592
        mixedops.append((op,
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2593
                         random.randint(0, size * 2),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2594
                         random.choice(costrange)))
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2595
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2596
    def domixed():
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2597
        d = util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2598
39584
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2599
        for op, v, cost in mixedops:
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2600
            if op == 0:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2601
                try:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2602
                    d[v]
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2603
                except KeyError:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2604
                    pass
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2605
            else:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2606
                d[v] = v
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2607
39584
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2608
    def domixedcost():
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2609
        d = util.lrucachedict(size, maxcost=costlimit)
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2610
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2611
        for op, v, cost in mixedops:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2612
            if op == 0:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2613
                try:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2614
                    d[v]
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2615
                except KeyError:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2616
                    pass
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2617
            else:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2618
                d.insert(v, v, cost=cost)
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2619
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2620
    benches = [
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2621
        (doinit, b'init'),
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2622
    ]
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2623
39584
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2624
    if costlimit:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2625
        benches.extend([
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2626
            (dogetscost, b'gets w/ cost limit'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2627
            (doinsertscost, b'inserts w/ cost limit'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2628
            (domixedcost, b'mixed w/ cost limit'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2629
        ])
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2630
    else:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2631
        benches.extend([
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2632
            (dogets, b'gets'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2633
            (doinserts, b'inserts'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2634
            (dosets, b'sets'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2635
            (domixed, b'mixed')
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2636
        ])
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39583
diff changeset
  2637
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2638
    for fn, title in benches:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2639
        timer, fm = gettimer(ui, opts)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2640
        timer(fn, title=title)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  2641
        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
  2642
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2643
@command(b'perfwrite', formatteropts)
30997
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30995
diff changeset
  2644
def perfwrite(ui, repo, **opts):
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30995
diff changeset
  2645
    """microbenchmark ui.write
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30995
diff changeset
  2646
    """
39830
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2647
    opts = _byteskwargs(opts)
874712506b07 py3: apply byteskwargs to contrib/perf
Matt Harbison <matt_harbison@yahoo.com>
parents: 39829
diff changeset
  2648
30997
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30995
diff changeset
  2649
    timer, fm = gettimer(ui, opts)
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30995
diff changeset
  2650
    def write():
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30995
diff changeset
  2651
        for i in range(100000):
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2652
            ui.write((b'Testing write performance\n'))
30997
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30995
diff changeset
  2653
    timer(write)
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30995
diff changeset
  2654
    fm.end()
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30995
diff changeset
  2655
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
  2656
def uisetup(ui):
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2657
    if (util.safehasattr(cmdutil, b'openrevlog') and
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2658
        not util.safehasattr(commands, b'debugrevlogopts')):
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
  2659
        # 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
  2660
        # 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
  2661
        # 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
  2662
        # 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
  2663
        # 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
  2664
        def openrevlog(orig, repo, cmd, file_, opts):
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2665
            if opts.get(b'dir') and not util.safehasattr(repo, b'dirlog'):
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2666
                raise error.Abort(b"This version doesn't support --dir option",
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2667
                                  hint=b"use 3.5 or later")
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
  2668
            return orig(repo, cmd, file_, opts)
39389
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39346
diff changeset
  2669
        extensions.wrapfunction(cmdutil, b'openrevlog', openrevlog)
40943
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2670
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2671
@command(b'perfprogress', formatteropts + [
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2672
    (b'', b'topic', b'topic', b'topic for progress messages'),
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2673
    (b'c', b'total', 1000000, b'total value we are progressing to'),
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2674
], norepo=True)
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2675
def perfprogress(ui, topic=None, total=None, **opts):
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2676
    """printing of progress bars"""
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2677
    opts = _byteskwargs(opts)
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2678
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2679
    timer, fm = gettimer(ui, opts)
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2680
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2681
    def doprogress():
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2682
        with ui.makeprogress(topic, total=total) as progress:
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2683
            for i in pycompat.xrange(total):
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2684
                progress.increment()
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2685
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2686
    timer(doprogress)
008f3491dc53 perf: add perfprogress command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40818
diff changeset
  2687
    fm.end()