contrib/perf.py
author Gregory Szorc <gregory.szorc@gmail.com>
Thu, 06 Sep 2018 14:04:46 -0700
changeset 39568 842cd0bdda75
parent 39567 ee087f0d7db5
child 39763 5ccd791344f3
permissions -rw-r--r--
util: teach lrucachedict to enforce a max total cost Now that lrucachedict entries can have a numeric cost associated with them and we can easily pop the oldest item in the cache, it now becomes relatively trivial to implement support for enforcing a high water mark on the total cost of items in the cache. This commit teaches lrucachedict instances to have a max cost associated with them. When items are inserted, we pop old items until enough "cost" frees up to make room for the new item. This feature is close to zero cost when not used (modulo the insertion regressed introduced by the previous commit): $ ./hg perflrucachedict --size 4 --gets 1000000 --sets 1000000 --mixed 1000000 ! gets ! wall 0.607444 comb 0.610000 user 0.610000 sys 0.000000 (best of 17) ! wall 0.601653 comb 0.600000 user 0.600000 sys 0.000000 (best of 17) ! inserts ! wall 0.678261 comb 0.680000 user 0.680000 sys 0.000000 (best of 14) ! wall 0.685042 comb 0.680000 user 0.680000 sys 0.000000 (best of 15) ! sets ! wall 0.808770 comb 0.800000 user 0.800000 sys 0.000000 (best of 13) ! wall 0.834241 comb 0.830000 user 0.830000 sys 0.000000 (best of 12) ! mixed ! wall 0.782441 comb 0.780000 user 0.780000 sys 0.000000 (best of 13) ! wall 0.803804 comb 0.800000 user 0.800000 sys 0.000000 (best of 13) $ hg perflrucachedict --size 1000 --gets 1000000 --sets 1000000 --mixed 1000000 ! init ! wall 0.006952 comb 0.010000 user 0.010000 sys 0.000000 (best of 418) ! gets ! wall 0.613350 comb 0.610000 user 0.610000 sys 0.000000 (best of 17) ! wall 0.617415 comb 0.620000 user 0.620000 sys 0.000000 (best of 17) ! inserts ! wall 0.701270 comb 0.700000 user 0.700000 sys 0.000000 (best of 15) ! wall 0.700516 comb 0.700000 user 0.700000 sys 0.000000 (best of 15) ! sets ! wall 0.825720 comb 0.830000 user 0.830000 sys 0.000000 (best of 13) ! wall 0.837946 comb 0.840000 user 0.830000 sys 0.010000 (best of 12) ! mixed ! wall 0.821644 comb 0.820000 user 0.820000 sys 0.000000 (best of 13) ! wall 0.850559 comb 0.850000 user 0.850000 sys 0.000000 (best of 12) I reckon the slight slowdown on insert is due to added if checks. For caches with total cost limiting enabled: $ hg perflrucachedict --size 4 --gets 1000000 --sets 1000000 --mixed 1000000 --costlimit 100 ! gets w/ cost limit ! wall 0.598737 comb 0.590000 user 0.590000 sys 0.000000 (best of 17) ! inserts w/ cost limit ! wall 1.694282 comb 1.700000 user 1.700000 sys 0.000000 (best of 6) ! mixed w/ cost limit ! wall 1.157655 comb 1.150000 user 1.150000 sys 0.000000 (best of 9) $ hg perflrucachedict --size 1000 --gets 1000000 --sets 1000000 --mixed 1000000 --costlimit 10000 ! gets w/ cost limit ! wall 0.598526 comb 0.600000 user 0.600000 sys 0.000000 (best of 17) ! inserts w/ cost limit ! wall 37.838315 comb 37.840000 user 37.840000 sys 0.000000 (best of 3) ! mixed w/ cost limit ! wall 18.060198 comb 18.060000 user 18.060000 sys 0.000000 (best of 3) $ hg perflrucachedict --size 1000 --gets 1000000 --sets 1000000 --mixed 1000000 --costlimit 10000 --mixedgetfreq 90 ! gets w/ cost limit ! wall 0.600024 comb 0.600000 user 0.600000 sys 0.000000 (best of 17) ! inserts w/ cost limit ! wall 37.154547 comb 37.120000 user 37.120000 sys 0.000000 (best of 3) ! mixed w/ cost limit ! wall 4.381602 comb 4.380000 user 4.370000 sys 0.010000 (best of 3) The functions we're benchmarking are slightly different, which could move numbers by a few milliseconds. But the slowdown on insert is too great to be explained by that. The slowness is due to insert heavy operations needing to call popoldest() repeatedly when the cache is at capacity. The next commit will address this. Differential Revision: https://phab.mercurial-scm.org/D4503
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
# perf.py - performance test routines
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8656
diff changeset
     2
'''helper extension to measure performance'''
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
29493
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     4
# "historical portability" policy of perf.py:
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     5
#
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     6
# We have to do:
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     7
# - make perf.py "loadable" with as wide Mercurial version as possible
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     8
#   This doesn't mean that perf commands work correctly with that Mercurial.
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
     9
#   BTW, perf.py itself has been available since 1.1 (or eb240755386d).
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    10
# - make historical perf command work correctly with as wide Mercurial
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    11
#   version as possible
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    12
#
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    13
# We have to do, if possible with reasonable cost:
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    14
# - make recent perf command for historical feature work correctly
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    15
#   with early Mercurial
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    16
#
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    17
# We don't have to do:
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    18
# - make perf command for recent feature work correctly with early
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    19
#   Mercurial
4533f5b47949 perf: add historical portability policy for future reference
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28561
diff changeset
    20
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    21
from __future__ import absolute_import
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    22
import functools
31397
8f5ed8fa39f8 perf: perform a garbage collection before each iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30977
diff changeset
    23
import gc
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    24
import os
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
    25
import random
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
    26
import struct
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    27
import sys
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
    28
import threading
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    29
import time
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    30
from mercurial import (
30018
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
    31
    changegroup,
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    32
    cmdutil,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    33
    commands,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    34
    copies,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    35
    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
    36
    extensions,
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    37
    mdiff,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    38
    merge,
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
    39
    revlog,
28561
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    40
    util,
330584235c22 contrib: make perf.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27649
diff changeset
    41
)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    42
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
    43
# for "historical portability":
29567
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    44
# 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
    45
# 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
    46
try:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    47
    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
    48
except ImportError:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    49
    pass
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 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
    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:
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32297
diff changeset
    55
    from mercurial import registrar # since 3.7 (or 37d50250b696)
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32297
diff changeset
    56
    dir(registrar) # forcibly load it
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32297
diff changeset
    57
except ImportError:
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32297
diff changeset
    58
    registrar = None
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32297
diff changeset
    59
try:
29567
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    60
    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
    61
except ImportError:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    62
    pass
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    63
try:
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    64
    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
    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
36178
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35951
diff changeset
    67
try:
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35951
diff changeset
    68
    from mercurial import pycompat
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35951
diff changeset
    69
    getargspec = pycompat.getargspec  # added to module after 4.5
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35951
diff changeset
    70
except (ImportError, AttributeError):
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35951
diff changeset
    71
    import inspect
646002338365 py3: introduce and use pycompat.getargspec
Augie Fackler <augie@google.com>
parents: 35951
diff changeset
    72
    getargspec = inspect.getargspec
29567
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    73
37844
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
    74
try:
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
    75
    # 4.7+
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
    76
    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
    77
except (AttributeError, ImportError):
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
    78
    # <4.7.
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
    79
    try:
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
    80
        queue = pycompat.queue
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
    81
    except (AttributeError, ImportError):
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
    82
        queue = util.queue
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
    83
38257
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
    84
try:
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
    85
    from mercurial import logcmdutil
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
    86
    makelogtemplater = logcmdutil.maketemplater
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
    87
except (AttributeError, ImportError):
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
    88
    try:
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
    89
        makelogtemplater = cmdutil.makelogtemplater
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
    90
    except (AttributeError, ImportError):
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
    91
        makelogtemplater = None
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
    92
29567
7e2b389418da perf: import newer modules separately for earlier Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29497
diff changeset
    93
# 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
    94
# 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
    95
# 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
    96
_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
    97
def safehasattr(thing, attr):
3b5389ef5cfe perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29493
diff changeset
    98
    return getattr(thing, attr, _undefined) is not _undefined
3b5389ef5cfe perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29493
diff changeset
    99
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
   100
29496
7299370cf304 perf: avoid using formatteropts for Mercurial earlier than 3.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29495
diff changeset
   101
# for "historical portability":
31823
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31476
diff changeset
   102
# 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: 31476
diff changeset
   103
# since ae5d60bb70c9
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31476
diff changeset
   104
if safehasattr(time, 'perf_counter'):
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31476
diff changeset
   105
    util.timer = time.perf_counter
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   106
elif os.name == b'nt':
31823
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31476
diff changeset
   107
    util.timer = time.clock
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31476
diff changeset
   108
else:
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31476
diff changeset
   109
    util.timer = time.time
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31476
diff changeset
   110
f6d77af84ef3 perf: add historical portability for util.timer
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 31476
diff changeset
   111
# 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
   112
# 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
   113
# 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
   114
# 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
   115
# available since 2.2 (or ae5f92e154d3)
32375
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
   116
formatteropts = getattr(cmdutil, "formatteropts",
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
   117
                        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
   118
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
   119
# 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
   120
# 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
   121
# 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
   122
# 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
   123
# since 1.9 (or a79fea6b3e77).
32375
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
   124
revlogopts = getattr(cmdutil, "debugrevlogopts",
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
   125
                     getattr(commands, "debugrevlogopts", [
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   126
        (b'c', b'changelog', False, (b'open changelog')),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   127
        (b'm', b'manifest', False, (b'open manifest')),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   128
        (b'', b'dir', False, (b'open directory manifest')),
32375
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
   129
        ]))
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   130
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   131
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
   132
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   133
# 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
   134
# 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
   135
# 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
   136
def parsealiases(cmd):
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   137
    return cmd.lstrip(b"^").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
   138
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32297
diff changeset
   139
if safehasattr(registrar, 'command'):
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32297
diff changeset
   140
    command = registrar.command(cmdtable)
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32297
diff changeset
   141
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
   142
    command = cmdutil.command(cmdtable)
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   143
    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
   144
        # 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
   145
        # 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
   146
        # 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
   147
        _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
   148
        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
   149
            if norepo:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   150
                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
   151
            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
   152
else:
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   153
    # 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
   154
    # 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
   155
    # 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
   156
    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
   157
        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
   158
            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
   159
                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
   160
            else:
ee2027195847 perf: define command annotation locally for Mercurial earlier than 3.1
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29496
diff changeset
   161
                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
   162
            if norepo:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   163
                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
   164
            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
   165
        return decorator
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   166
34494
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34343
diff changeset
   167
try:
34749
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   168
    import mercurial.registrar
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   169
    import mercurial.configitems
34494
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34343
diff changeset
   170
    configtable = {}
34749
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   171
    configitem = mercurial.registrar.configitem(configtable)
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   172
    configitem(b'perf', b'presleep',
34749
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   173
        default=mercurial.configitems.dynamicdefault,
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   174
    )
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   175
    configitem(b'perf', b'stub',
34749
acdc574cb8d7 contrib-perf: update the config registration
Boris Feld <boris.feld@octobus.net>
parents: 34678
diff changeset
   176
        default=mercurial.configitems.dynamicdefault,
34494
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34343
diff changeset
   177
    )
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   178
    configitem(b'perf', b'parentscount',
34750
caf6c446cbe3 contrib-perf: register the 'parentscount' config item
Boris Feld <boris.feld@octobus.net>
parents: 34749
diff changeset
   179
        default=mercurial.configitems.dynamicdefault,
caf6c446cbe3 contrib-perf: register the 'parentscount' config item
Boris Feld <boris.feld@octobus.net>
parents: 34749
diff changeset
   180
    )
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   181
    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
   182
        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
   183
    )
34494
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34343
diff changeset
   184
except (ImportError, AttributeError):
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34343
diff changeset
   185
    pass
bbb5687e5140 configitems: register the 'perf.stub' config
Boris Feld <boris.feld@octobus.net>
parents: 34343
diff changeset
   186
27307
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   187
def getlen(ui):
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   188
    if ui.configbool(b"perf", b"stub", False):
27307
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   189
        return lambda x: 1
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   190
    return len
f36dc0062b1a perf: add getlen
timeless <timeless@mozdev.org>
parents: 27306
diff changeset
   191
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   192
def gettimer(ui, opts=None):
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   193
    """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
   194
27303
57bd9c5431a5 perf: improve grammar of gettimer comment
timeless <timeless@mozdev.org>
parents: 27286
diff changeset
   195
    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
   196
    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
   197
316ad725a1dd perf: add a configurable sleep on startup
Matt Mackall <mpm@selenic.com>
parents: 23537
diff changeset
   198
    # 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
   199
    # experimental config: perf.presleep
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   200
    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
   201
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   202
    if opts is None:
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   203
        opts = {}
30405
e77e8876886f perf: omit copying ui and redirect to ferr if buffer API is in use
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 30370
diff changeset
   204
    # 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: 30370
diff changeset
   205
    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: 30370
diff changeset
   206
        ui = ui.copy()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   207
        uifout = safeattrsetter(ui, b'fout', ignoremissing=True)
30405
e77e8876886f perf: omit copying ui and redirect to ferr if buffer API is in use
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 30370
diff changeset
   208
        if uifout:
e77e8876886f perf: omit copying ui and redirect to ferr if buffer API is in use
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents: 30370
diff changeset
   209
            # 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: 30370
diff changeset
   210
            # 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: 30370
diff changeset
   211
            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
   212
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   213
    # 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
   214
    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
   215
    if uiformatter:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   216
        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
   217
    else:
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   218
        # 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
   219
        # 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
   220
        # 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
   221
        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
   222
        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
   223
            """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
   224
            """
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   225
            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
   226
                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
   227
                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
   228
                    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
   229
                else:
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   230
                    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
   231
            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
   232
                return False
31476
413b44003462 py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31397
diff changeset
   233
            __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
   234
            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
   235
                pass
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   236
            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
   237
                pass
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   238
            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
   239
                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
   240
            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
   241
                if cond:
423bf74d2e5b perf: define formatter locally for Mercurial earlier than 2.2
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30146
diff changeset
   242
                    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
   243
            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
   244
                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
   245
            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
   246
                pass
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   247
        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
   248
27304
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   249
    # 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
   250
    # experimental config: perf.stub
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   251
    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
   252
        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
   253
55101513ed94 perf: add a 'perf.all-timing' option to display more than best time
Boris Feld <boris.feld@octobus.net>
parents: 38693
diff changeset
   254
    # experimental config: perf.all-timing
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   255
    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
   256
    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
   257
27304
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   258
def stub_timer(fm, func, title=None):
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   259
    func()
a6fd79495770 perf: offer perf.stub to only run one loop
timeless <timeless@mozdev.org>
parents: 27303
diff changeset
   260
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
   261
def _timer(fm, func, title=None, displayall=False):
31397
8f5ed8fa39f8 perf: perform a garbage collection before each iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30977
diff changeset
   262
    gc.collect()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   263
    results = []
30975
22fbca1d11ed mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents: 30882
diff changeset
   264
    begin = util.timer()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   265
    count = 0
14494
1ffeeb91c55d check-code: flag 0/1 used as constant Boolean expression
Martin Geisler <mg@lazybytes.net>
parents: 14322
diff changeset
   266
    while True:
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   267
        ostart = os.times()
30975
22fbca1d11ed mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents: 30882
diff changeset
   268
        cstart = util.timer()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   269
        r = func()
30975
22fbca1d11ed mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents: 30882
diff changeset
   270
        cstop = util.timer()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   271
        ostop = os.times()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   272
        count += 1
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   273
        a, b = ostart, ostop
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   274
        results.append((cstop - cstart, b[0] - a[0], b[1]-a[1]))
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   275
        if cstop - begin > 3 and count >= 100:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   276
            break
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   277
        if cstop - begin > 10 and count >= 3:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   278
            break
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   279
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   280
    fm.startitem()
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   281
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   282
    if title:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   283
        fm.write(b'title', b'! %s\n', title)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   284
    if r:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   285
        fm.write(b'result', b'! result: %s\n', r)
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
   286
    def display(role, entry):
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   287
        prefix = b''
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   288
        if role != b'best':
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   289
            prefix = b'%s.' % role
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   290
        fm.plain(b'!')
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   291
        fm.write(prefix + b'wall', b' wall %f', entry[0])
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   292
        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: 39319
diff changeset
   293
        fm.write(prefix + b'user', b' user %f', entry[1])
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   294
        fm.write(prefix + b'sys',  b' sys %f', entry[2])
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   295
        fm.write(prefix + b'count',  b' (%s of %d)', role, count)
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   296
        fm.plain(b'\n')
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
   297
    results.sort()
55101513ed94 perf: add a 'perf.all-timing' option to display more than best time
Boris Feld <boris.feld@octobus.net>
parents: 38693
diff changeset
   298
    min_val = results[0]
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   299
    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
   300
    if displayall:
55101513ed94 perf: add a 'perf.all-timing' option to display more than best time
Boris Feld <boris.feld@octobus.net>
parents: 38693
diff changeset
   301
        max_val = results[-1]
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   302
        display(b'max', max_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
   303
        avg = tuple([sum(x) / count for x in zip(*results)])
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   304
        display(b'avg', avg)
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
   305
        median = results[len(results) // 2]
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   306
        display(b'median', median)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   307
30143
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   308
# utilities for historical portability
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   309
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
   310
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
   311
    # 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
   312
    # 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
   313
    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
   314
    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
   315
        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
   316
    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
   317
        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
   318
    except ValueError:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   319
        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
   320
                                % (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
   321
30143
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   322
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
   323
    """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
   324
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   325
    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
   326
    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
   327
    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
   328
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   329
    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
   330
    (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
   331
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   332
    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
   333
    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
   334
    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
   335
    versions.
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   336
    """
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   337
    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
   338
        if ignoremissing:
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   339
            return None
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   340
        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: 39319
diff changeset
   341
                           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
   342
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   343
    origvalue = getattr(obj, name)
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   344
    class attrutil(object):
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   345
        def set(self, newvalue):
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   346
            setattr(obj, name, newvalue)
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   347
        def restore(self):
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   348
            setattr(obj, name, origvalue)
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   349
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   350
    return attrutil()
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   351
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
   352
# 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
   353
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   354
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
   355
    # 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
   356
    # 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
   357
    # - 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
   358
    # - 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
   359
    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
   360
        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
   361
        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
   362
            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
   363
14031d183048 perf: get subsettable from appropriate module for Mercurial earlier than 2.9
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30143
diff changeset
   364
    # 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
   365
    # 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
   366
    # doesn't)
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   367
    raise error.Abort((b"perfbranchmap not available with this Mercurial"),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   368
                      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
   369
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
   370
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
   371
    """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
   372
    """
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
   373
    # 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
   374
    # 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
   375
    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
   376
    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
   377
        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
   378
    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
   379
        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
   380
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
   381
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
   382
    """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
   383
    """
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
   384
    # 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
   385
    # 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
   386
    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
   387
    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
   388
        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
   389
    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
   390
        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
   391
30150
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   392
def repocleartagscachefunc(repo):
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   393
    """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
   394
    """
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   395
    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
   396
        # 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
   397
        # 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
   398
        # 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
   399
        def clearcache():
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   400
            # _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
   401
            # 98c867ac1330), and delattr() can't work in such case
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   402
            if b'_tagscache' in vars(repo):
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   403
                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
   404
        return clearcache
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   405
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   406
    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
   407
    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
   408
        return lambda : repotags.set(None)
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   409
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   410
    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
   411
    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
   412
        return lambda : repotagscache.set(None)
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   413
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   414
    # 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
   415
    # 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
   416
    # - 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
   417
    #   in perftags() causes failure soon
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   418
    # - perf.py itself has been available since 1.1 (or eb240755386d)
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   419
    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
   420
32731
6f791ca70640 perf: have a generic "clearstorecache" function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32710
diff changeset
   421
# utilities to clear cache
6f791ca70640 perf: have a generic "clearstorecache" function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32710
diff changeset
   422
6f791ca70640 perf: have a generic "clearstorecache" function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32710
diff changeset
   423
def clearfilecache(repo, attrname):
6f791ca70640 perf: have a generic "clearstorecache" function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32710
diff changeset
   424
    unfi = repo.unfiltered()
6f791ca70640 perf: have a generic "clearstorecache" function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32710
diff changeset
   425
    if attrname in vars(unfi):
6f791ca70640 perf: have a generic "clearstorecache" function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32710
diff changeset
   426
        delattr(unfi, attrname)
6f791ca70640 perf: have a generic "clearstorecache" function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32710
diff changeset
   427
    unfi._filecache.pop(attrname, None)
6f791ca70640 perf: have a generic "clearstorecache" function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32710
diff changeset
   428
30143
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   429
# perf commands
2d858c771760 perf: introduce safeattrsetter to replace direct attribute assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30069
diff changeset
   430
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   431
@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
   432
def perfwalk(ui, repo, *pats, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   433
    timer, fm = gettimer(ui, opts)
34342
b3538c03a804 perf: remove fallbacks to ancient versions of dirstate.walk()
Martin von Zweigbergk <martinvonz@google.com>
parents: 32888
diff changeset
   434
    m = scmutil.match(repo[None], pats, {})
34343
255c761a52db dirstate: use keyword arguments to clarify walk()'s callers
Martin von Zweigbergk <martinvonz@google.com>
parents: 34342
diff changeset
   435
    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: 34342
diff changeset
   436
                                              ignored=False))))
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   437
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   438
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   439
@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
   440
def perfannotate(ui, repo, f, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   441
    timer, fm = gettimer(ui, opts)
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   442
    fc = repo[b'.'][f]
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 18877
diff changeset
   443
    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
   444
    fm.end()
19292
e0aa6fff8f02 annotate: simplify annotate parent function
Durham Goode <durham@fb.com>
parents: 18877
diff changeset
   445
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   446
@command(b'perfstatus',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   447
         [(b'u', b'unknown', False,
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   448
           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
   449
def perfstatus(ui, repo, **opts):
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   450
    #m = match.always(repo.root, repo.getcwd())
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16414
diff changeset
   451
    #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
   452
    #                                                False))))
27017
cdc3e437b481 perf: un-bitrot perfstatus
Matt Mackall <mpm@selenic.com>
parents: 26748
diff changeset
   453
    timer, fm = gettimer(ui, opts)
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   454
    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
   455
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   456
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   457
@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
   458
def perfaddremove(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   459
    timer, fm = gettimer(ui, opts)
18871
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   460
    try:
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   461
        oldquiet = repo.ui.quiet
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   462
        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
   463
        matcher = scmutil.match(repo[None])
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   464
        opts[b'dry_run'] = True
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   465
        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
   466
    finally:
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   467
        repo.ui.quiet = oldquiet
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   468
        fm.end()
18871
a2d4ab4f575d perf: add a command to test addremove performance
Siddharth Agarwal <sid0@fb.com>
parents: 18845
diff changeset
   469
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   470
def clearcaches(cl):
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   471
    # behave somewhat consistently across internal API changes
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   472
    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
   473
        cl.clearcaches()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   474
    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
   475
        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
   476
        cl._nodecache = {nullid: nullrev}
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   477
        cl._nodepos = None
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   478
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   479
@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
   480
def perfheads(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   481
    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
   482
    cl = repo.changelog
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   483
    def d():
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   484
        len(cl.headrevs())
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   485
        clearcaches(cl)
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   486
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   487
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   488
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   489
@command(b'perftags', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   490
def perftags(ui, repo, **opts):
19786
fe8795dee77d perf: rearrange imports of changelong and manifest to appease check-code
Augie Fackler <raf@durin42.com>
parents: 19712
diff changeset
   491
    import mercurial.changelog
fe8795dee77d perf: rearrange imports of changelong and manifest to appease check-code
Augie Fackler <raf@durin42.com>
parents: 19712
diff changeset
   492
    import mercurial.manifest
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   493
    timer, fm = gettimer(ui, opts)
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
   494
    svfs = getsvfs(repo)
30150
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   495
    repocleartagscache = repocleartagscachefunc(repo)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   496
    def t():
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
   497
        repo.changelog = mercurial.changelog.changelog(svfs)
30219
3c8811efdddc manifest: make manifestlog a storecache
Durham Goode <durham@fb.com>
parents: 30150
diff changeset
   498
        repo.manifestlog = mercurial.manifest.manifestlog(svfs, repo)
30150
c0410814002f perf: make perftags clear tags cache correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30149
diff changeset
   499
        repocleartagscache()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   500
        return len(repo.tags())
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   501
    timer(t)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   502
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   503
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   504
@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
   505
def perfancestors(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   506
    timer, fm = gettimer(ui, opts)
16802
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   507
    heads = repo.changelog.headrevs()
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   508
    def d():
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16858
diff changeset
   509
        for a in repo.changelog.ancestors(heads):
16802
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   510
            pass
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   511
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   512
    fm.end()
16802
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
   513
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   514
@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
   515
def perfancestorset(ui, repo, revset, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   516
    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
   517
    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
   518
    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
   519
    def d():
18091
f7f8159caad3 ancestor: add lazy membership testing to lazyancestors
Siddharth Agarwal <sid0@fb.com>
parents: 18080
diff changeset
   520
        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
   521
        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
   522
            rev in s
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   523
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   524
    fm.end()
18080
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   525
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   526
@command(b'perfbookmarks', formatteropts)
32733
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32732
diff changeset
   527
def perfbookmarks(ui, repo, **opts):
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32732
diff changeset
   528
    """benchmark parsing bookmarks from disk to memory"""
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32732
diff changeset
   529
    timer, fm = gettimer(ui, opts)
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32732
diff changeset
   530
    def d():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   531
        clearfilecache(repo, b'_bookmarks')
32733
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32732
diff changeset
   532
        repo._bookmarks
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32732
diff changeset
   533
    timer(d)
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32732
diff changeset
   534
    fm.end()
2b0a8b0f3435 perf: add a perfbookmarks command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32732
diff changeset
   535
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   536
@command(b'perfbundleread', formatteropts, b'BUNDLE')
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   537
def perfbundleread(ui, repo, bundlepath, **opts):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   538
    """Benchmark reading of bundle files.
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   539
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   540
    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: 35084
diff changeset
   541
    much as possible.
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   542
    """
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   543
    from mercurial import (
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   544
        bundle2,
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   545
        exchange,
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   546
        streamclone,
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   547
    )
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   548
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   549
    def makebench(fn):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   550
        def run():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   551
            with open(bundlepath, b'rb') as fh:
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   552
                bundle = exchange.readbundle(ui, fh, bundlepath)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   553
                fn(bundle)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   554
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   555
        return run
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   556
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   557
    def makereadnbytes(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   558
        def run():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   559
            with open(bundlepath, b'rb') as fh:
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   560
                bundle = exchange.readbundle(ui, fh, bundlepath)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   561
                while bundle.read(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   562
                    pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   563
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   564
        return run
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   565
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   566
    def makestdioread(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   567
        def run():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   568
            with open(bundlepath, b'rb') as fh:
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   569
                while fh.read(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   570
                    pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   571
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   572
        return run
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   573
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   574
    # bundle1
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   575
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   576
    def deltaiter(bundle):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   577
        for delta in bundle.deltaiter():
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   578
            pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   579
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   580
    def iterchunks(bundle):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   581
        for chunk in bundle.getchunks():
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   582
            pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   583
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   584
    # bundle2
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   585
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   586
    def forwardchunks(bundle):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   587
        for chunk in bundle._forwardchunks():
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   588
            pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   589
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   590
    def iterparts(bundle):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   591
        for part in bundle.iterparts():
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   592
            pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   593
35116
da91e7309daf bundle2: don't use seekable bundle2 parts by default (issue5691)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35109
diff changeset
   594
    def iterpartsseekable(bundle):
da91e7309daf bundle2: don't use seekable bundle2 parts by default (issue5691)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35109
diff changeset
   595
        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: 35109
diff changeset
   596
            pass
da91e7309daf bundle2: don't use seekable bundle2 parts by default (issue5691)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35109
diff changeset
   597
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   598
    def seek(bundle):
35116
da91e7309daf bundle2: don't use seekable bundle2 parts by default (issue5691)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35109
diff changeset
   599
        for part in bundle.iterparts(seekable=True):
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   600
            part.seek(0, os.SEEK_END)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   601
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   602
    def makepartreadnbytes(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   603
        def run():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   604
            with open(bundlepath, b'rb') as fh:
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   605
                bundle = exchange.readbundle(ui, fh, bundlepath)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   606
                for part in bundle.iterparts():
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   607
                    while part.read(size):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   608
                        pass
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   609
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   610
        return run
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   611
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   612
    benches = [
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   613
        (makestdioread(8192), b'read(8k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   614
        (makestdioread(16384), b'read(16k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   615
        (makestdioread(32768), b'read(32k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   616
        (makestdioread(131072), b'read(128k)'),
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   617
    ]
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   618
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   619
    with open(bundlepath, b'rb') as fh:
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   620
        bundle = exchange.readbundle(ui, fh, bundlepath)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   621
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   622
        if isinstance(bundle, changegroup.cg1unpacker):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   623
            benches.extend([
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   624
                (makebench(deltaiter), b'cg1 deltaiter()'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   625
                (makebench(iterchunks), b'cg1 getchunks()'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   626
                (makereadnbytes(8192), b'cg1 read(8k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   627
                (makereadnbytes(16384), b'cg1 read(16k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   628
                (makereadnbytes(32768), b'cg1 read(32k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   629
                (makereadnbytes(131072), b'cg1 read(128k)'),
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   630
            ])
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   631
        elif isinstance(bundle, bundle2.unbundle20):
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   632
            benches.extend([
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   633
                (makebench(forwardchunks), b'bundle2 forwardchunks()'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   634
                (makebench(iterparts), b'bundle2 iterparts()'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   635
                (makebench(iterpartsseekable), b'bundle2 iterparts() seekable'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   636
                (makebench(seek), b'bundle2 part seek()'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   637
                (makepartreadnbytes(8192), b'bundle2 part read(8k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   638
                (makepartreadnbytes(16384), b'bundle2 part read(16k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   639
                (makepartreadnbytes(32768), b'bundle2 part read(32k)'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   640
                (makepartreadnbytes(131072), b'bundle2 part read(128k)'),
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   641
            ])
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   642
        elif isinstance(bundle, streamclone.streamcloneapplier):
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   643
            raise error.Abort(b'stream clone bundles not supported')
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   644
        else:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   645
            raise error.Abort(b'unhandled bundle type: %s' % type(bundle))
35109
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   646
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   647
    for fn, title in benches:
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   648
        timer, fm = gettimer(ui, opts)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   649
        timer(fn, title=title)
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   650
        fm.end()
e96613048bdd perf: add command to benchmark bundle reading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35084
diff changeset
   651
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   652
@command(b'perfchangegroupchangelog', formatteropts +
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   653
         [(b'', b'version', b'02', b'changegroup version'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   654
          (b'r', b'rev', b'', b'revisions to add to changegroup')])
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   655
def perfchangegroupchangelog(ui, repo, version=b'02', rev=None, **opts):
30018
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   656
    """Benchmark producing a changelog group for a changegroup.
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   657
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   658
    This measures the time spent processing the changelog during a
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   659
    bundle operation. This occurs during `hg bundle` and on a server
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   660
    processing a `getbundle` wire protocol request (handles clones
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   661
    and pull requests).
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   662
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   663
    By default, all revisions are added to the changegroup.
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   664
    """
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   665
    cl = repo.changelog
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   666
    nodes = [cl.lookup(r) for r in repo.revs(rev or b'all()')]
30018
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   667
    bundler = changegroup.getbundler(version, repo)
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   668
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   669
    def d():
38977
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38969
diff changeset
   670
        state, chunks = bundler._generatechangelog(cl, nodes)
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38969
diff changeset
   671
        for chunk in chunks:
30018
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   672
            pass
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   673
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   674
    timer, fm = gettimer(ui, opts)
38977
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38969
diff changeset
   675
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38969
diff changeset
   676
    # Terminal printing can interfere with timing. So disable it.
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   677
    with ui.configoverride({(b'progress', b'disable'): True}):
38977
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38969
diff changeset
   678
        timer(d)
a1f694779b2f perf: call _generatechangelog() instead of group()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38969
diff changeset
   679
30018
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   680
    fm.end()
bd6df07ccc24 perf: add perfchangegroupchangelog command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30017
diff changeset
   681
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   682
@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
   683
def perfdirs(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   684
    timer, fm = gettimer(ui, opts)
18845
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   685
    dirstate = repo.dirstate
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   686
    b'a' in dirstate
18845
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   687
    def d():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   688
        dirstate.hasdir(b'a')
35084
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 34750
diff changeset
   689
        del dirstate._map._dirs
18845
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   690
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   691
    fm.end()
18845
c1f416e4bc80 perf: add perfdirs command
Bryan O'Sullivan <bryano@fb.com>
parents: 18837
diff changeset
   692
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   693
@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
   694
def perfdirstate(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   695
    timer, fm = gettimer(ui, opts)
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   696
    b"a" in repo.dirstate
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   697
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   698
        repo.dirstate.invalidate()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   699
        b"a" in repo.dirstate
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   700
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   701
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   702
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   703
@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
   704
def perfdirstatedirs(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   705
    timer, fm = gettimer(ui, opts)
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   706
    b"a" in repo.dirstate
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   707
    def d():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   708
        repo.dirstate.hasdir(b"a")
35084
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 34750
diff changeset
   709
        del repo.dirstate._map._dirs
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   710
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   711
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   712
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   713
@command(b'perfdirstatefoldmap', formatteropts)
27095
aaf4e2d77148 contrib/perf: name functions to match decorators
timeless <timeless@mozdev.org>
parents: 27072
diff changeset
   714
def perfdirstatefoldmap(ui, repo, **opts):
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   715
    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
   716
    dirstate = repo.dirstate
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   717
    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
   718
    def d():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   719
        dirstate._map.filefoldmap.get(b'a')
34676
bfddc3d678ae dirstate: remove _filefoldmap property cache
Durham Goode <durham@fb.com>
parents: 34494
diff changeset
   720
        del dirstate._map.filefoldmap
24607
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   721
    timer(d)
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   722
    fm.end()
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   723
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   724
@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
   725
def perfdirfoldmap(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   726
    timer, fm = gettimer(ui, opts)
24607
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   727
    dirstate = repo.dirstate
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   728
    b'a' in dirstate
24607
f5b527024fcc perf: make measuring foldmap perf work again
Siddharth Agarwal <sid0@fb.com>
parents: 24349
diff changeset
   729
    def d():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   730
        dirstate._map.dirfoldmap.get(b'a')
34678
e8a89ed7ce96 dirstate: move the _dirfoldmap to dirstatemap
Durham Goode <durham@fb.com>
parents: 34677
diff changeset
   731
        del dirstate._map.dirfoldmap
35084
61888bd0b300 dirstate: add explicit methods for querying directories (API)
Mark Thomas <mbthomas@fb.com>
parents: 34750
diff changeset
   732
        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
   733
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   734
    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
   735
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   736
@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
   737
def perfdirstatewrite(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   738
    timer, fm = gettimer(ui, opts)
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   739
    ds = repo.dirstate
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   740
    b"a" in ds
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   741
    def d():
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   742
        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
   743
        ds.write(repo.currenttransaction())
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   744
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   745
    fm.end()
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   746
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   747
@command(b'perfmergecalculate',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   748
         [(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
   749
def perfmergecalculate(ui, repo, rev, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   750
    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
   751
    wctx = repo[None]
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   752
    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
   753
    ancestor = wctx.ancestor(rctx)
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   754
    # 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
   755
    # that cache
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   756
    wctx.dirty()
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   757
    def d():
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   758
        # 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
   759
        # our benchmark
27098
64cb281d23a5 contrib/perf: fix perfmergecalculate
timeless <timeless@mozdev.org>
parents: 27097
diff changeset
   760
        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
   761
                               acceptremote=True, followcopies=True)
18817
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   762
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   763
    fm.end()
18817
c760acc6f69d perf: add a command to measure merge.calculateupdates perf
Siddharth Agarwal <sid0@fb.com>
parents: 18644
diff changeset
   764
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   765
@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
   766
def perfpathcopies(ui, repo, rev1, rev2, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   767
    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
   768
    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
   769
    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
   770
    def d():
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   771
        copies.pathcopies(ctx1, ctx2)
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   772
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   773
    fm.end()
18877
2e9fe9e2671f perf: add a command to test copies.pathcopies perf
Siddharth Agarwal <sid0@fb.com>
parents: 18871
diff changeset
   774
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   775
@command(b'perfphases',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   776
         [(b'', b'full', False, b'include file reading time too'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   777
          ], b"")
32467
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32390
diff changeset
   778
def perfphases(ui, repo, **opts):
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32390
diff changeset
   779
    """benchmark phasesets computation"""
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32390
diff changeset
   780
    timer, fm = gettimer(ui, opts)
32732
e36569bd9e28 perfphases: add a flag to also include file access time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32731
diff changeset
   781
    _phases = repo._phasecache
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   782
    full = opts.get(b'full')
32467
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32390
diff changeset
   783
    def d():
32732
e36569bd9e28 perfphases: add a flag to also include file access time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32731
diff changeset
   784
        phases = _phases
e36569bd9e28 perfphases: add a flag to also include file access time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32731
diff changeset
   785
        if full:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   786
            clearfilecache(repo, b'_phasecache')
32732
e36569bd9e28 perfphases: add a flag to also include file access time
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32731
diff changeset
   787
            phases = repo._phasecache
32467
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32390
diff changeset
   788
        phases.invalidate()
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32390
diff changeset
   789
        phases.loadphaserevs(repo)
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32390
diff changeset
   790
    timer(d)
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32390
diff changeset
   791
    fm.end()
ad37c569ec81 perfphases: add 'perfphases' command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32390
diff changeset
   792
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   793
@command(b'perfphasesremote',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   794
         [], b"[DEST]")
39140
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   795
def perfphasesremote(ui, repo, dest=None, **opts):
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   796
    """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
   797
    from mercurial.node import (
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   798
        bin,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   799
    )
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   800
    from mercurial import (
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   801
        exchange,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   802
        hg,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   803
        phases,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   804
    )
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   805
    timer, fm = gettimer(ui, opts)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   806
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   807
    path = ui.paths.getpath(dest, default=(b'default-push', b'default'))
39140
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   808
    if not path:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   809
        raise error.Abort((b'default repository not configured!'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   810
                          hint=(b"see 'hg help config.paths'"))
39140
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   811
    dest = path.pushloc or path.loc
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   812
    branches = (path.branch, opts.get(b'branch') or [])
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   813
    ui.status((b'analysing phase of %s\n') % util.hidepassword(dest))
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   814
    revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get(b'rev'))
39140
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   815
    other = hg.peer(repo, opts, dest)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   816
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   817
    # easier to perform discovery through the operation
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   818
    op = exchange.pushoperation(repo, other)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   819
    exchange._pushdiscoverychangeset(op)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   820
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   821
    remotesubset = op.fallbackheads
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   822
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   823
    with other.commandexecutor() as e:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   824
        remotephases = e.callcommand(b'listkeys',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   825
                       {b'namespace': b'phases'}).result()
39140
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   826
    del other
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   827
    publishing = remotephases.get(b'publishing', False)
39140
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   828
    if publishing:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   829
        ui.status((b'publishing: yes\n'))
39140
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   830
    else:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   831
        ui.status((b'publishing: no\n'))
39140
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   832
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   833
    nodemap = repo.changelog.nodemap
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   834
    nonpublishroots = 0
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   835
    for nhex, phase in remotephases.iteritems():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   836
        if nhex == b'publishing': # ignore data related to publish option
39140
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   837
            continue
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   838
        node = bin(nhex)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   839
        if node in nodemap and int(phase):
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   840
            nonpublishroots += 1
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   841
    ui.status((b'number of roots: %d\n') % len(remotephases))
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   842
    ui.status((b'number of known non public roots: %d\n') % nonpublishroots)
39140
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   843
    def d():
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   844
        phases.remotephasessummary(repo,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   845
                                   remotesubset,
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   846
                                   remotephases)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   847
    timer(d)
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   848
    fm.end()
1732db2f8210 perf: add a perfphasesremote command
Boris Feld <boris.feld@octobus.net>
parents: 38695
diff changeset
   849
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   850
@command(b'perfmanifest',[
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   851
            (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: 39319
diff changeset
   852
            (b'', b'clear-disk', False, b'clear on-disk caches too'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   853
         ], b'REV|NODE')
38780
ddb15a83ae0b debug: allow specifying a manifest node rather than a revision
Martijn Pieters <mj@zopatista.com>
parents: 38778
diff changeset
   854
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: 38273
diff changeset
   855
    """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: 38273
diff changeset
   856
    dict-like object
9b6a708f2263 perf: document the perfmanifest command
Boris Feld <boris.feld@octobus.net>
parents: 38273
diff changeset
   857
9b6a708f2263 perf: document the perfmanifest command
Boris Feld <boris.feld@octobus.net>
parents: 38273
diff changeset
   858
    Manifest caches are cleared before retrieval."""
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   859
    timer, fm = gettimer(ui, opts)
38780
ddb15a83ae0b debug: allow specifying a manifest node rather than a revision
Martijn Pieters <mj@zopatista.com>
parents: 38778
diff changeset
   860
    if not manifest_rev:
ddb15a83ae0b debug: allow specifying a manifest node rather than a revision
Martijn Pieters <mj@zopatista.com>
parents: 38778
diff changeset
   861
        ctx = scmutil.revsingle(repo, rev, rev)
ddb15a83ae0b debug: allow specifying a manifest node rather than a revision
Martijn Pieters <mj@zopatista.com>
parents: 38778
diff changeset
   862
        t = ctx.manifestnode()
ddb15a83ae0b debug: allow specifying a manifest node rather than a revision
Martijn Pieters <mj@zopatista.com>
parents: 38778
diff changeset
   863
    else:
39318
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   864
        from mercurial.node import bin
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   865
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   866
        if len(rev) == 40:
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   867
            t = bin(rev)
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   868
        else:
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   869
            try:
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   870
                rev = int(rev)
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   871
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   872
                if util.safehasattr(repo.manifestlog, b'getstorage'):
39318
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   873
                    t = repo.manifestlog.getstorage(b'').node(rev)
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   874
                else:
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   875
                    t = repo.manifestlog._revlog.lookup(rev)
c03c5f528e9b perf: use storage API for resolving manifest node
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39194
diff changeset
   876
            except ValueError:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   877
                raise error.Abort(b'manifest revision must be integer or full '
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   878
                                  b'node')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   879
    def d():
38781
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38780
diff changeset
   880
        repo.manifestlog.clearcaches(clear_persisted_data=clear_disk)
30369
d79c141fdf41 manifest: remove usages of manifest.read
Durham Goode <durham@fb.com>
parents: 30337
diff changeset
   881
        repo.manifestlog[t].read()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   882
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   883
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   884
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   885
@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
   886
def perfchangeset(ui, repo, rev, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   887
    timer, fm = gettimer(ui, opts)
37355
5bcd5859b505 perf: make perfmanifest and perfnodelookup work with revsets
Martin von Zweigbergk <martinvonz@google.com>
parents: 37269
diff changeset
   888
    n = scmutil.revsingle(repo, rev).node()
16262
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   889
    def d():
19378
9de689d20230 cleanup: drop unused variables and an unused import
Simon Heimberg <simohe@besonet.ch>
parents: 19322
diff changeset
   890
        repo.changelog.read(n)
16266
77d56a5e74a5 perf: add a changeset test
Matt Mackall <mpm@selenic.com>
parents: 16262
diff changeset
   891
        #repo.changelog._cache = None
16262
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   892
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   893
    fm.end()
16262
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   894
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   895
@command(b'perfindex', formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   896
def perfindex(ui, repo, **opts):
13255
2696730ca233 perf: make perfindex results useful on hg with lazyparser
Matt Mackall <mpm@selenic.com>
parents: 13254
diff changeset
   897
    import mercurial.revlog
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   898
    timer, fm = gettimer(ui, opts)
13277
9f707b297b0f perf: restore lazyindex hack
Matt Mackall <mpm@selenic.com>
parents: 13262
diff changeset
   899
    mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   900
    n = repo[b"tip"].node()
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
   901
    svfs = getsvfs(repo)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   902
    def d():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   903
        cl = mercurial.revlog.revlog(svfs, b"00changelog.i")
16260
33fcad3cfbbc perf: tweak tests for testing index performance improvements
Matt Mackall <mpm@selenic.com>
parents: 14671
diff changeset
   904
        cl.rev(n)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   905
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   906
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   907
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   908
@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
   909
def perfstartup(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   910
    timer, fm = gettimer(ui, opts)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   911
    cmd = sys.argv[0]
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   912
    def d():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   913
        if os.name != b'nt':
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   914
            os.system(b"HGRCPATH= %s version -q > /dev/null" % cmd)
27382
de7bcbc68042 perf: adjust perfstartup() for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 27345
diff changeset
   915
        else:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   916
            os.environ[b'HGRCPATH'] = b' '
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   917
            os.system(b"%s version -q > NUL" % cmd)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   918
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   919
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   920
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   921
@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
   922
def perfparents(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   923
    timer, fm = gettimer(ui, opts)
27305
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
   924
    # control the number of commits perfparents iterates over
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
   925
    # experimental config: perf.parentscount
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   926
    count = getint(ui, b"perf", b"parentscount", 1000)
27305
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
   927
    if len(repo.changelog) < count:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   928
        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
   929
    repo = repo.unfiltered()
27305
5831cfbf0e33 perf: perfparents honor config perf.parentscount
timeless <timeless@mozdev.org>
parents: 27304
diff changeset
   930
    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
   931
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   932
        for n in nl:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   933
            repo.changelog.parents(n)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   934
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
   935
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   936
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   937
@command(b'perfctxfiles', formatteropts)
27095
aaf4e2d77148 contrib/perf: name functions to match decorators
timeless <timeless@mozdev.org>
parents: 27072
diff changeset
   938
def perfctxfiles(ui, repo, x, **opts):
24349
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   939
    x = int(x)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   940
    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
   941
    def d():
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   942
        len(repo[x].files())
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   943
    timer(d)
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   944
    fm.end()
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   945
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   946
@command(b'perfrawfiles', formatteropts)
27095
aaf4e2d77148 contrib/perf: name functions to match decorators
timeless <timeless@mozdev.org>
parents: 27072
diff changeset
   947
def perfrawfiles(ui, repo, x, **opts):
24349
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   948
    x = int(x)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   949
    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
   950
    cl = repo.changelog
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   951
    def d():
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   952
        len(cl.read(x)[3])
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   953
    timer(d)
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   954
    fm.end()
389693a245fa perf: add methods for timing changeset file list reading
Matt Mackall <mpm@selenic.com>
parents: 23878
diff changeset
   955
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   956
@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
   957
def perflookup(ui, repo, rev, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   958
    timer, fm = gettimer(ui, opts)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   959
    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
   960
    fm.end()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   961
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   962
@command(b'perflinelogedits',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   963
         [(b'n', b'edits', 10000, b'number of edits'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   964
          (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: 39319
diff changeset
   965
          ], norepo=True)
38969
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   966
def perflinelogedits(ui, **opts):
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   967
    from mercurial import linelog
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   968
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   969
    edits = opts[b'edits']
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   970
    maxhunklines = opts[b'max_hunk_lines']
38969
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   971
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   972
    maxb1 = 100000
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   973
    random.seed(0)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   974
    randint = random.randint
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   975
    currentlines = 0
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   976
    arglist = []
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   977
    for rev in xrange(edits):
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   978
        a1 = randint(0, currentlines)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   979
        a2 = randint(a1, min(currentlines, a1 + maxhunklines))
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   980
        b1 = randint(0, maxb1)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   981
        b2 = randint(b1, b1 + maxhunklines)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   982
        currentlines += (b2 - b1) - (a2 - a1)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   983
        arglist.append((rev, a1, a2, b1, b2))
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   984
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   985
    def d():
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   986
        ll = linelog.linelog()
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   987
        for args in arglist:
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   988
            ll.replacelines(*args)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   989
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   990
    timer, fm = gettimer(ui, opts)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   991
    timer(d)
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   992
    fm.end()
1601afbb573c perf: add a command to benchmark linelog edits
Jun Wu <quark@fb.com>
parents: 38781
diff changeset
   993
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
   994
@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
   995
def perfrevrange(ui, repo, *specs, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
   996
    timer, fm = gettimer(ui, opts)
16858
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
   997
    revrange = scmutil.revrange
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
   998
    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
   999
    fm.end()
16858
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
  1000
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1001
@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
  1002
def perfnodelookup(ui, repo, rev, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1003
    timer, fm = gettimer(ui, opts)
16309
e0c1b3ef7c36 perf: node lookup
Matt Mackall <mpm@selenic.com>
parents: 16266
diff changeset
  1004
    import mercurial.revlog
e0c1b3ef7c36 perf: node lookup
Matt Mackall <mpm@selenic.com>
parents: 16266
diff changeset
  1005
    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: 37269
diff changeset
  1006
    n = scmutil.revsingle(repo, rev).node()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1007
    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
  1008
    def d():
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
  1009
        cl.rev(n)
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
  1010
        clearcaches(cl)
16414
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
  1011
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1012
    fm.end()
16414
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
  1013
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1014
@command(b'perflog',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1015
         [(b'', b'rename', False, b'ask log to follow renames')
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1016
         ] + formatteropts)
27306
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
  1017
def perflog(ui, repo, rev=None, **opts):
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
  1018
    if rev is None:
bafb1235f505 perf: add optional rev for perflog and perftemplating
timeless <timeless@mozdev.org>
parents: 27305
diff changeset
  1019
        rev=[]
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1020
    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
  1021
    ui.pushbuffer()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1022
    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: 39319
diff changeset
  1023
                               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
  1024
    ui.popbuffer()
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1025
    fm.end()
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
  1026
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1027
@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
  1028
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
  1029
    """benchmark walking the changelog backwards
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
  1030
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
  1031
    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
  1032
    """
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1033
    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
  1034
    def moonwalk():
38778
a4d847cea6f8 perfmoonwalk: make work with filtered repo
Martin von Zweigbergk <martinvonz@google.com>
parents: 38695
diff changeset
  1035
        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
  1036
            ctx = repo[i]
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
  1037
            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
  1038
    timer(moonwalk)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1039
    fm.end()
20178
74aea4be8e78 perf: add perfmoonwalk command to walk the changelog backwards
Brodie Rao <brodie@sf.io>
parents: 20032
diff changeset
  1040
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1041
@command(b'perftemplating',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1042
         [(b'r', b'rev', [], b'revisions to run the template on'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1043
          ] + formatteropts)
38258
ae6e02fcee24 perftemplating: allow to specify the template to test
Boris Feld <boris.feld@octobus.net>
parents: 38257
diff changeset
  1044
def perftemplating(ui, repo, testedtemplate=None, **opts):
ae6e02fcee24 perftemplating: allow to specify the template to test
Boris Feld <boris.feld@octobus.net>
parents: 38257
diff changeset
  1045
    """test the rendering time of a given template"""
38257
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
  1046
    if makelogtemplater is None:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1047
        raise error.Abort((b"perftemplating not available with this Mercurial"),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1048
                          hint=b"use 4.3 or later")
38257
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
  1049
38255
71d59b487d0c perftemplating: drop usage of buffer
Boris Feld <boris.feld@octobus.net>
parents: 38254
diff changeset
  1050
    nullui = ui.copy()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1051
    nullui.fout = open(os.devnull, b'wb')
38255
71d59b487d0c perftemplating: drop usage of buffer
Boris Feld <boris.feld@octobus.net>
parents: 38254
diff changeset
  1052
    nullui.disablepager()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1053
    revs = opts.get(b'rev')
38257
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
  1054
    if not revs:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1055
        revs = [b'all()']
38257
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
  1056
    revs = list(scmutil.revrange(repo, revs))
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
  1057
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1058
    defaulttemplate = (b'{date|shortdate} [{rev}:{node|short}]'
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1059
                       b' {author|person}: {desc|firstline}\n')
38258
ae6e02fcee24 perftemplating: allow to specify the template to test
Boris Feld <boris.feld@octobus.net>
parents: 38257
diff changeset
  1060
    if testedtemplate is None:
ae6e02fcee24 perftemplating: allow to specify the template to test
Boris Feld <boris.feld@octobus.net>
parents: 38257
diff changeset
  1061
        testedtemplate = defaulttemplate
ae6e02fcee24 perftemplating: allow to specify the template to test
Boris Feld <boris.feld@octobus.net>
parents: 38257
diff changeset
  1062
    displayer = makelogtemplater(nullui, repo, testedtemplate)
38254
6b91815fcdce perftemplating: move template formating into its own function
Boris Feld <boris.feld@octobus.net>
parents: 38253
diff changeset
  1063
    def format():
38257
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
  1064
        for r in revs:
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
  1065
            ctx = repo[r]
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
  1066
            displayer.show(ctx)
a577a199983c perftemplating: stop going through the log command
Boris Feld <boris.feld@octobus.net>
parents: 38256
diff changeset
  1067
            displayer.flush(ctx)
38254
6b91815fcdce perftemplating: move template formating into its own function
Boris Feld <boris.feld@octobus.net>
parents: 38253
diff changeset
  1068
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1069
    timer, fm = gettimer(ui, opts)
38254
6b91815fcdce perftemplating: move template formating into its own function
Boris Feld <boris.feld@octobus.net>
parents: 38253
diff changeset
  1070
    timer(format)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1071
    fm.end()
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
  1072
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1073
@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
  1074
def perfcca(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1075
    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
  1076
    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
  1077
    fm.end()
16386
ccc173d0914e perf: add case collision auditor perf
Matt Mackall <mpm@selenic.com>
parents: 16309
diff changeset
  1078
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1079
@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
  1080
def perffncacheload(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1081
    timer, fm = gettimer(ui, opts)
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
  1082
    s = repo.store
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1083
    def d():
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1084
        s.fncache._load()
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1085
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1086
    fm.end()
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1087
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1088
@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
  1089
def perffncachewrite(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1090
    timer, fm = gettimer(ui, opts)
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
  1091
    s = repo.store
38695
2cdb82e8fb44 perffncachewrite: load fncache after lock is acquired
Boris Feld <boris.feld@octobus.net>
parents: 38694
diff changeset
  1092
    lock = repo.lock()
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1093
    s.fncache._load()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1094
    tr = repo.transaction(b'perffncachewrite')
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1095
    tr.addbackup(b'fncache')
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1096
    def d():
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1097
        s.fncache._dirty = True
27097
b3e24a9c5f9b contrib/perf: fix perffncachewrite
timeless <timeless@mozdev.org>
parents: 27096
diff changeset
  1098
        s.fncache.write(tr)
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1099
    timer(d)
30069
98b9846a131e perf: release lock after transaction in perffncachewrite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30018
diff changeset
  1100
    tr.close()
27097
b3e24a9c5f9b contrib/perf: fix perffncachewrite
timeless <timeless@mozdev.org>
parents: 27096
diff changeset
  1101
    lock.release()
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1102
    fm.end()
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
  1103
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1104
@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
  1105
def perffncacheencode(ui, repo, **opts):
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1106
    timer, fm = gettimer(ui, opts)
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
  1107
    s = repo.store
17553
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1108
    s.fncache._load()
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1109
    def d():
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1110
        for p in s.fncache.entries:
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1111
            s.encode(p)
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1112
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1113
    fm.end()
17553
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
  1114
36766
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1115
def _bdiffworker(q, blocks, xdiff, ready, done):
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1116
    while not done.is_set():
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1117
        pair = q.get()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1118
        while pair is not None:
36766
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1119
            if xdiff:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1120
                mdiff.bdiff.xdiffblocks(*pair)
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1121
            elif blocks:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1122
                mdiff.bdiff.blocks(*pair)
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1123
            else:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1124
                mdiff.textdiff(*pair)
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1125
            q.task_done()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1126
            pair = q.get()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1127
        q.task_done() # for the None one
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1128
        with ready:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1129
            ready.wait()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1130
39319
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1131
def _manifestrevision(repo, mnode):
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1132
    ml = repo.manifestlog
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1133
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1134
    if util.safehasattr(ml, b'getstorage'):
39319
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1135
        store = ml.getstorage(b'')
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1136
    else:
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1137
        store = ml._revlog
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1138
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1139
    return store.revision(mnode)
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1140
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1141
@command(b'perfbdiff', revlogopts + formatteropts + [
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1142
    (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: 39319
diff changeset
  1143
    (b'', b'alldata', False, b'test bdiffs for all associated revisions'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1144
    (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: 39319
diff changeset
  1145
    (b'', b'blocks', False, b'test computing diffs into blocks'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1146
    (b'', b'xdiff', False, b'use xdiff algorithm'),
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1147
    ],
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1148
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1149
    b'-c|-m|FILE REV')
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1150
def perfbdiff(ui, repo, file_, rev=None, count=None, threads=0, **opts):
30336
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30335
diff changeset
  1151
    """benchmark a bdiff between revisions
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30335
diff changeset
  1152
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30335
diff changeset
  1153
    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: 30335
diff changeset
  1154
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30335
diff changeset
  1155
    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: 30335
diff changeset
  1156
    revisions starting at the specified revision.
30337
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1157
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1158
    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: 30336
diff changeset
  1159
    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: 30336
diff changeset
  1160
    and filelogs).
30336
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30335
diff changeset
  1161
    """
36766
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1162
    opts = pycompat.byteskwargs(opts)
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1163
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1164
    if opts[b'xdiff'] and not opts[b'blocks']:
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1165
        raise error.CommandError(b'perfbdiff', b'--xdiff requires --blocks')
36766
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1166
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1167
    if opts[b'alldata']:
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1168
        opts[b'changelog'] = True
30337
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1169
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1170
    if opts.get(b'changelog') or opts.get(b'manifest'):
30307
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1171
        file_, rev = None, file_
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1172
    elif rev is None:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1173
        raise error.CommandError(b'perfbdiff', b'invalid arguments')
30307
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1174
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1175
    blocks = opts[b'blocks']
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1176
    xdiff = opts[b'xdiff']
30335
7d91a085ebe6 perf: prepare to handle multiple pairs in perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30307
diff changeset
  1177
    textpairs = []
7d91a085ebe6 perf: prepare to handle multiple pairs in perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30307
diff changeset
  1178
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1179
    r = cmdutil.openrevlog(repo, b'perfbdiff', file_, opts)
30307
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1180
30336
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30335
diff changeset
  1181
    startrev = r.rev(r.lookup(rev))
7ddc8f8d7712 perf: support bdiffing multiple revisions in a single revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30335
diff changeset
  1182
    for rev in range(startrev, min(startrev + count, len(r) - 1)):
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1183
        if opts[b'alldata']:
30337
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1184
            # Load revisions associated with changeset.
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1185
            ctx = repo[rev]
39319
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1186
            mtext = _manifestrevision(repo, ctx.manifestnode())
30337
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1187
            for pctx in ctx.parents():
39319
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1188
                pman = _manifestrevision(repo, pctx.manifestnode())
30337
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1189
                textpairs.append((pman, mtext))
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1190
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1191
            # Load filelog revisions by iterating manifest delta.
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1192
            man = ctx.manifest()
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1193
            pman = ctx.p1().manifest()
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1194
            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: 30336
diff changeset
  1195
                fctx = repo.file(filename)
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1196
                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: 30336
diff changeset
  1197
                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: 30336
diff changeset
  1198
                textpairs.append((f1, f2))
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1199
        else:
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1200
            dp = r.deltaparent(rev)
6ecad4b73569 perf: support measuring bdiff for all changeset related data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30336
diff changeset
  1201
            textpairs.append((r.revision(dp), r.revision(rev)))
30307
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1202
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1203
    withthreads = threads > 0
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1204
    if not withthreads:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1205
        def d():
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1206
            for pair in textpairs:
36766
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1207
                if xdiff:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1208
                    mdiff.bdiff.xdiffblocks(*pair)
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1209
                elif blocks:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1210
                    mdiff.bdiff.blocks(*pair)
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1211
                else:
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1212
                    mdiff.textdiff(*pair)
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1213
    else:
37844
8fb9985382be pycompat: export queue module instead of symbols in module (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37355
diff changeset
  1214
        q = queue()
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1215
        for i in xrange(threads):
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1216
            q.put(None)
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1217
        ready = threading.Condition()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1218
        done = threading.Event()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1219
        for i in xrange(threads):
36766
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1220
            threading.Thread(target=_bdiffworker,
d382344c69aa perf: teach perfbdiff to call blocks() and to use xdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36360
diff changeset
  1221
                             args=(q, blocks, xdiff, ready, done)).start()
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1222
        q.join()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1223
        def d():
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1224
            for pair in textpairs:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1225
                q.put(pair)
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1226
            for i in xrange(threads):
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1227
                q.put(None)
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1228
            with ready:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1229
                ready.notify_all()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1230
            q.join()
30307
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1231
    timer, fm = gettimer(ui, opts)
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1232
    timer(d)
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1233
    fm.end()
c8fa7ad1ff90 perf: add perfbdiff
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30219
diff changeset
  1234
35599
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1235
    if withthreads:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1236
        done.set()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1237
        for i in xrange(threads):
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1238
            q.put(None)
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1239
        with ready:
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1240
            ready.notify_all()
af25237be091 perf: add threading capability to perfbdiff
Boris Feld <boris.feld@octobus.net>
parents: 35116
diff changeset
  1241
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1242
@command(b'perfunidiff', revlogopts + formatteropts + [
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1243
    (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: 39319
diff changeset
  1244
    (b'', b'alldata', False, b'test unidiffs for all associated revisions'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1245
    ], b'-c|-m|FILE REV')
35861
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1246
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
  1247
    """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
  1248
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1249
    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
  1250
    of the texts.
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1251
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1252
    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
  1253
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1254
    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
  1255
    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
  1256
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1257
    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
  1258
    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
  1259
    and filelogs).
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1260
    """
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1261
    if opts[b'alldata']:
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1262
        opts[b'changelog'] = True
35861
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1263
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1264
    if opts.get(b'changelog') or opts.get(b'manifest'):
35861
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1265
        file_, rev = None, file_
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1266
    elif rev is None:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1267
        raise error.CommandError(b'perfunidiff', b'invalid arguments')
35861
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1268
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1269
    textpairs = []
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1270
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1271
    r = cmdutil.openrevlog(repo, b'perfunidiff', file_, opts)
35861
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1272
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1273
    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
  1274
    for rev in range(startrev, min(startrev + count, len(r) - 1)):
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1275
        if opts[b'alldata']:
35861
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1276
            # 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
  1277
            ctx = repo[rev]
39319
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1278
            mtext = _manifestrevision(repo, ctx.manifestnode())
35861
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1279
            for pctx in ctx.parents():
39319
862d23bc5749 perf: add function for obtaining manifest revision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39318
diff changeset
  1280
                pman = _manifestrevision(repo, pctx.manifestnode())
35861
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1281
                textpairs.append((pman, mtext))
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1282
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1283
            # 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
  1284
            man = ctx.manifest()
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1285
            pman = ctx.p1().manifest()
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1286
            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
  1287
                fctx = repo.file(filename)
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1288
                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
  1289
                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
  1290
                textpairs.append((f1, f2))
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1291
        else:
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1292
            dp = r.deltaparent(rev)
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1293
            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
  1294
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1295
    def d():
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1296
        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
  1297
            # 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
  1298
            headerlines, hunks = mdiff.unidiff(
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1299
                left, b'', right, b'', b'left', b'right', binary=False)
35861
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1300
            # 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
  1301
            b'\n'.join(headerlines)
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1302
            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
  1303
    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
  1304
    timer(d)
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1305
    fm.end()
ed939545edd0 perf: add a perfunidiff command for benchmarking unified diff speed
Augie Fackler <augie@google.com>
parents: 35602
diff changeset
  1306
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1307
@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
  1308
def perfdiffwd(ui, repo, **opts):
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1309
    """Profile diff of working directory changes"""
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1310
    timer, fm = gettimer(ui, opts)
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1311
    options = {
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1312
        b'w': b'ignore_all_space',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1313
        b'b': b'ignore_space_change',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1314
        b'B': b'ignore_blank_lines',
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1315
        }
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1316
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1317
    for diffopt in (b'', b'w', b'b', b'B', b'wB'):
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1318
        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
  1319
        def d():
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1320
            ui.pushbuffer()
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1321
            commands.diff(ui, repo, **opts)
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1322
            ui.popbuffer()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1323
        title = b'diffopts: %s' % (diffopt and (b'-' + diffopt) or b'none')
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1324
        timer(d, title)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1325
    fm.end()
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
  1326
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1327
@command(b'perfrevlogindex', revlogopts + formatteropts,
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1328
         b'-c|-m|FILE')
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1329
def perfrevlogindex(ui, repo, file_=None, **opts):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1330
    """Benchmark operations against a revlog index.
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1331
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1332
    This tests constructing a revlog instance, reading index data,
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1333
    parsing index data, and performing various operations related to
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1334
    index data.
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1335
    """
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1336
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1337
    rl = cmdutil.openrevlog(repo, b'perfrevlogindex', file_, opts)
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1338
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1339
    opener = getattr(rl, 'opener')  # trick linter
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1340
    indexfile = rl.indexfile
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1341
    data = opener.read(indexfile)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1342
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1343
    header = struct.unpack(b'>I', data[0:4])[0]
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1344
    version = header & 0xFFFF
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1345
    if version == 1:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1346
        revlogio = revlog.revlogio()
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1347
        inline = header & (1 << 16)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1348
    else:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1349
        raise error.Abort((b'unsupported revlog version: %d') % version)
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1350
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1351
    rllen = len(rl)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1352
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1353
    node0 = rl.node(0)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1354
    node25 = rl.node(rllen // 4)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1355
    node50 = rl.node(rllen // 2)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1356
    node75 = rl.node(rllen // 4 * 3)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1357
    node100 = rl.node(rllen - 1)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1358
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1359
    allrevs = range(rllen)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1360
    allrevsrev = list(reversed(allrevs))
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1361
    allnodes = [rl.node(rev) for rev in range(rllen)]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1362
    allnodesrev = list(reversed(allnodes))
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1363
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1364
    def constructor():
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1365
        revlog.revlog(opener, indexfile)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1366
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1367
    def read():
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1368
        with opener(indexfile) as fh:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1369
            fh.read()
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1370
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1371
    def parseindex():
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1372
        revlogio.parseindex(data, inline)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1373
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1374
    def getentry(revornode):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1375
        index = revlogio.parseindex(data, inline)[0]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1376
        index[revornode]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1377
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1378
    def getentries(revs, count=1):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1379
        index = revlogio.parseindex(data, inline)[0]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1380
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1381
        for i in range(count):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1382
            for rev in revs:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1383
                index[rev]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1384
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1385
    def resolvenode(node):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1386
        nodemap = revlogio.parseindex(data, inline)[1]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1387
        # This only works for the C code.
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1388
        if nodemap is None:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1389
            return
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1390
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1391
        try:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1392
            nodemap[node]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1393
        except error.RevlogError:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1394
            pass
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1395
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1396
    def resolvenodes(nodes, count=1):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1397
        nodemap = revlogio.parseindex(data, inline)[1]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1398
        if nodemap is None:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1399
            return
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1400
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1401
        for i in range(count):
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1402
            for node in nodes:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1403
                try:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1404
                    nodemap[node]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1405
                except error.RevlogError:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1406
                    pass
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1407
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1408
    benches = [
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1409
        (constructor, b'revlog constructor'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1410
        (read, b'read'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1411
        (parseindex, b'create index object'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1412
        (lambda: getentry(0), b'retrieve index entry for rev 0'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1413
        (lambda: resolvenode(b'a' * 20), b'look up missing node'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1414
        (lambda: resolvenode(node0), b'look up node at rev 0'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1415
        (lambda: resolvenode(node25), b'look up node at 1/4 len'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1416
        (lambda: resolvenode(node50), b'look up node at 1/2 len'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1417
        (lambda: resolvenode(node75), b'look up node at 3/4 len'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1418
        (lambda: resolvenode(node100), b'look up node at tip'),
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1419
        # 2x variation is to measure caching impact.
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1420
        (lambda: resolvenodes(allnodes),
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1421
         b'look up all nodes (forward)'),
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1422
        (lambda: resolvenodes(allnodes, 2),
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1423
         b'look up all nodes 2x (forward)'),
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1424
        (lambda: resolvenodes(allnodesrev),
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1425
         b'look up all nodes (reverse)'),
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1426
        (lambda: resolvenodes(allnodesrev, 2),
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1427
         b'look up all nodes 2x (reverse)'),
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1428
        (lambda: getentries(allrevs),
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1429
         b'retrieve all index entries (forward)'),
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1430
        (lambda: getentries(allrevs, 2),
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1431
         b'retrieve all index entries 2x (forward)'),
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1432
        (lambda: getentries(allrevsrev),
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1433
         b'retrieve all index entries (reverse)'),
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1434
        (lambda: getentries(allrevsrev, 2),
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1435
         b'retrieve all index entries 2x (reverse)'),
32532
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1436
    ]
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1437
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1438
    for fn, title in benches:
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1439
        timer, fm = gettimer(ui, opts)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1440
        timer(fn, title=title)
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1441
        fm.end()
e4f514627514 perf: benchmark command for revlog indexes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32531
diff changeset
  1442
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1443
@command(b'perfrevlogrevisions', revlogopts + formatteropts +
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1444
         [(b'd', b'dist', 100, b'distance between the revisions'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1445
          (b's', b'startrev', 0, b'revision to start reading at'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1446
          (b'', b'reverse', False, b'read in reverse')],
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1447
         b'-c|-m|FILE')
32531
7236facefd4f perf: rename perfrevlog to perfrevlogrevisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32467
diff changeset
  1448
def perfrevlogrevisions(ui, repo, file_=None, startrev=0, reverse=False,
7236facefd4f perf: rename perfrevlog to perfrevlogrevisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32467
diff changeset
  1449
                        **opts):
27492
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
  1450
    """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
  1451
ac549d7fbc2b perf: use standard arguments for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27472
diff changeset
  1452
    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
  1453
    the specified revlog.
27493
14b0930105da perf: make start revision configurable for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27492
diff changeset
  1454
14b0930105da perf: make start revision configurable for perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27492
diff changeset
  1455
    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
  1456
    """
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1457
    rl = cmdutil.openrevlog(repo, b'perfrevlogrevisions', file_, opts)
32232
4c6b2076d292 perf: move revlog construction and length calculation out of benchmark
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32231
diff changeset
  1458
    rllen = getlen(ui)(rl)
30017
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1459
11694
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
  1460
    def d():
32232
4c6b2076d292 perf: move revlog construction and length calculation out of benchmark
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32231
diff changeset
  1461
        rl.clearcaches()
30017
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1462
32224
6b582f9b6e5e perf: don't clobber startrev variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32202
diff changeset
  1463
        beginrev = startrev
32232
4c6b2076d292 perf: move revlog construction and length calculation out of benchmark
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32231
diff changeset
  1464
        endrev = rllen
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1465
        dist = opts[b'dist']
30017
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1466
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1467
        if reverse:
32224
6b582f9b6e5e perf: don't clobber startrev variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32202
diff changeset
  1468
            beginrev, endrev = endrev, beginrev
30017
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1469
            dist = -1 * dist
973cf6c3de30 perf: add --reverse to perfrevlog
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29567
diff changeset
  1470
32224
6b582f9b6e5e perf: don't clobber startrev variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32202
diff changeset
  1471
        for x in xrange(beginrev, endrev, dist):
32297
d7efaf6275a7 perf: always pass node to revlog.revision()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32232
diff changeset
  1472
            # Old revisions don't support passing int.
d7efaf6275a7 perf: always pass node to revlog.revision()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32232
diff changeset
  1473
            n = rl.node(x)
d7efaf6275a7 perf: always pass node to revlog.revision()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32232
diff changeset
  1474
            rl.revision(n)
11694
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
  1475
32225
c68c400d0a2d perf: move gettimer() call
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32224
diff changeset
  1476
    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
  1477
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1478
    fm.end()
11694
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
  1479
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1480
@command(b'perfrevlogchunks', revlogopts + formatteropts +
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1481
         [(b'e', b'engines', b'', b'compression engines to use'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1482
          (b's', b'startrev', 0, b'revision to start at')],
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1483
         b'-c|-m|FILE')
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1484
def perfrevlogchunks(ui, repo, file_=None, engines=None, startrev=0, **opts):
30451
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1485
    """Benchmark operations on revlog chunks.
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1486
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1487
    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: 30426
diff changeset
  1488
    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: 30426
diff changeset
  1489
    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: 30426
diff changeset
  1490
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1491
    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: 30426
diff changeset
  1492
    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: 30426
diff changeset
  1493
    For measurements of higher-level operations like resolving revisions,
32531
7236facefd4f perf: rename perfrevlog to perfrevlogrevisions
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32467
diff changeset
  1494
    see ``perfrevlogrevisions`` and ``perfrevlogrevision``.
30451
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1495
    """
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1496
    rl = cmdutil.openrevlog(repo, b'perfrevlogchunks', file_, opts)
32229
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1497
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1498
    # _chunkraw was renamed to _getsegmentforrevs.
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1499
    try:
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1500
        segmentforrevs = rl._getsegmentforrevs
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1501
    except AttributeError:
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1502
        segmentforrevs = rl._chunkraw
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1503
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1504
    # Verify engines argument.
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1505
    if engines:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1506
        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
  1507
        for engine in engines:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1508
            try:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1509
                util.compressionengines[engine]
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1510
            except KeyError:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1511
                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
  1512
    else:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1513
        engines = []
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1514
        for e in util.compengines:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1515
            engine = util.compengines[e]
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1516
            try:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1517
                if engine.available():
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1518
                    engine.revlogcompressor().compress(b'dummy')
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1519
                    engines.append(e)
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1520
            except NotImplementedError:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1521
                pass
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1522
30451
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1523
    revs = list(rl.revs(startrev, len(rl) - 1))
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1524
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1525
    def rlfh(rl):
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1526
        if rl._inline:
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1527
            return getsvfs(repo)(rl.indexfile)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1528
        else:
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1529
            return getsvfs(repo)(rl.datafile)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1530
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1531
    def doread():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1532
        rl.clearcaches()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1533
        for rev in revs:
32228
112ba1c7d65d perf: store reference to revlog._chunkraw in a local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32225
diff changeset
  1534
            segmentforrevs(rev, rev)
30451
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1535
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1536
    def doreadcachedfh():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1537
        rl.clearcaches()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1538
        fh = rlfh(rl)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1539
        for rev in revs:
32228
112ba1c7d65d perf: store reference to revlog._chunkraw in a local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32225
diff changeset
  1540
            segmentforrevs(rev, rev, df=fh)
30451
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1541
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1542
    def doreadbatch():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1543
        rl.clearcaches()
32228
112ba1c7d65d perf: store reference to revlog._chunkraw in a local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32225
diff changeset
  1544
        segmentforrevs(revs[0], revs[-1])
30451
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1545
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1546
    def doreadbatchcachedfh():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1547
        rl.clearcaches()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1548
        fh = rlfh(rl)
32228
112ba1c7d65d perf: store reference to revlog._chunkraw in a local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32225
diff changeset
  1549
        segmentforrevs(revs[0], revs[-1], df=fh)
30451
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1550
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1551
    def dochunk():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1552
        rl.clearcaches()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1553
        fh = rlfh(rl)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1554
        for rev in revs:
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1555
            rl._chunk(rev, df=fh)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1556
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1557
    chunks = [None]
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1558
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1559
    def dochunkbatch():
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1560
        rl.clearcaches()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1561
        fh = rlfh(rl)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1562
        # Save chunks as a side-effect.
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1563
        chunks[0] = rl._chunks(revs, df=fh)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1564
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1565
    def docompress(compressor):
30451
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1566
        rl.clearcaches()
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1567
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1568
        try:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1569
            # Swap in the requested compression engine.
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1570
            oldcompressor = rl._compressor
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1571
            rl._compressor = compressor
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1572
            for chunk in chunks[0]:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1573
                rl.compress(chunk)
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1574
        finally:
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1575
            rl._compressor = oldcompressor
30451
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1576
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1577
    benches = [
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1578
        (lambda: doread(), b'read'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1579
        (lambda: doreadcachedfh(), b'read w/ reused fd'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1580
        (lambda: doreadbatch(), b'read batch'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1581
        (lambda: doreadbatchcachedfh(), b'read batch w/ reused fd'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1582
        (lambda: dochunk(), b'chunk'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1583
        (lambda: dochunkbatch(), b'chunk batch'),
30451
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1584
    ]
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1585
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1586
    for engine in sorted(engines):
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1587
        compressor = util.compengines[engine].revlogcompressor()
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1588
        benches.append((functools.partial(docompress, compressor),
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1589
                        b'compress w/ %s' % engine))
30796
168ef0a4eb3b perf: support multiple compression engines in perfrevlogchunks
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30793
diff changeset
  1590
30451
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1591
    for fn, title in benches:
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1592
        timer, fm = gettimer(ui, opts)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1593
        timer(fn, title=title)
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1594
        fm.end()
94ca0e13d1fc perf: add command for measuring revlog chunk operations
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30426
diff changeset
  1595
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1596
@command(b'perfrevlogrevision', revlogopts + formatteropts +
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1597
         [(b'', b'cache', False, b'use caches instead of clearing')],
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1598
         b'-c|-m|FILE REV')
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1599
def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1600
    """Benchmark obtaining a revlog revision.
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1601
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1602
    Obtaining a revlog revision consists of roughly the following steps:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1603
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1604
    1. Compute the delta chain
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1605
    2. Obtain the raw chunks for that delta chain
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1606
    3. Decompress each raw chunk
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1607
    4. Apply binary patches to obtain fulltext
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1608
    5. Verify hash of fulltext
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1609
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1610
    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
  1611
    """
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1612
    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
  1613
        file_, rev = None, file_
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1614
    elif rev is None:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1615
        raise error.CommandError(b'perfrevlogrevision', b'invalid arguments')
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1616
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1617
    r = cmdutil.openrevlog(repo, b'perfrevlogrevision', file_, opts)
32229
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1618
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1619
    # _chunkraw was renamed to _getsegmentforrevs.
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1620
    try:
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1621
        segmentforrevs = r._getsegmentforrevs
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1622
    except AttributeError:
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1623
        segmentforrevs = r._chunkraw
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32228
diff changeset
  1624
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1625
    node = r.lookup(rev)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1626
    rev = r.rev(node)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1627
30882
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1628
    def getrawchunks(data, chain):
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1629
        start = r.start
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1630
        length = r.length
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1631
        inline = r._inline
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1632
        iosize = r._io.size
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1633
        buffer = util.buffer
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1634
        offset = start(chain[0])
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1635
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1636
        chunks = []
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1637
        ladd = chunks.append
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1638
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1639
        for rev in chain:
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1640
            chunkstart = start(rev)
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1641
            if inline:
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1642
                chunkstart += (rev + 1) * iosize
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1643
            chunklength = length(rev)
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1644
            ladd(buffer(data, chunkstart - offset, chunklength))
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1645
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1646
        return chunks
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1647
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1648
    def dodeltachain(rev):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1649
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1650
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1651
        r._deltachain(rev)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1652
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1653
    def doread(chain):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1654
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1655
            r.clearcaches()
32228
112ba1c7d65d perf: store reference to revlog._chunkraw in a local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32225
diff changeset
  1656
        segmentforrevs(chain[0], chain[-1])
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1657
30882
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1658
    def dorawchunks(data, chain):
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1659
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1660
            r.clearcaches()
30882
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1661
        getrawchunks(data, chain)
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1662
30882
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1663
    def dodecompress(chunks):
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1664
        decomp = r.decompress
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1665
        for chunk in chunks:
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1666
            decomp(chunk)
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1667
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1668
    def dopatch(text, bins):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1669
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1670
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1671
        mdiff.patches(text, bins)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1672
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1673
    def dohash(text):
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1674
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1675
            r.clearcaches()
30584
be5b2098a817 revlog: merge hash checking subfunctions
Remi Chaintron <remi@fb.com>
parents: 30451
diff changeset
  1676
        r.checkhash(text, node, rev=rev)
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1677
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1678
    def dorevision():
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1679
        if not cache:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1680
            r.clearcaches()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1681
        r.revision(node)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1682
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1683
    chain = r._deltachain(rev)[0]
32228
112ba1c7d65d perf: store reference to revlog._chunkraw in a local variable
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32225
diff changeset
  1684
    data = segmentforrevs(chain[0], chain[-1])[1]
30882
74cfc4357c64 perf: split obtaining chunks from decompression
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30796
diff changeset
  1685
    rawchunks = getrawchunks(data, chain)
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1686
    bins = r._chunks(chain)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1687
    text = str(bins[0])
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1688
    bins = bins[1:]
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1689
    text = mdiff.patches(text, bins)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1690
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1691
    benches = [
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1692
        (lambda: dorevision(), b'full'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1693
        (lambda: dodeltachain(rev), b'deltachain'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1694
        (lambda: doread(chain), b'read'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1695
        (lambda: dorawchunks(data, chain), b'rawchunks'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1696
        (lambda: dodecompress(rawchunks), b'decompress'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1697
        (lambda: dopatch(text, bins), b'patch'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1698
        (lambda: dohash(text), b'hash'),
27470
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1699
    ]
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1700
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1701
    for fn, title in benches:
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1702
        timer, fm = gettimer(ui, opts)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1703
        timer(fn, title=title)
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1704
        fm.end()
d394a1a3708a perf: add perfrevlogrevision
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27467
diff changeset
  1705
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1706
@command(b'perfrevset',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1707
         [(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: 39319
diff changeset
  1708
          (b'', b'contexts', False, b'obtain changectx for each revision')]
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1709
         + formatteropts, b"REVSET")
27072
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
  1710
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
  1711
    """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
  1712
18644
3e92772d5383 spelling: fix some minor issues found by spell checker
Mads Kiilerich <mads@kiilerich.com>
parents: 18304
diff changeset
  1713
    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
  1714
    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
  1715
    and obsolete related cache."""
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1716
    timer, fm = gettimer(ui, opts)
18062
1471f5e83686 perf: add a command to measure revset performance
Siddharth Agarwal <sid0@fb.com>
parents: 18033
diff changeset
  1717
    def d():
18239
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
  1718
        if clear:
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
  1719
            repo.invalidatevolatilesets()
27072
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
  1720
        if contexts:
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
  1721
            for ctx in repo.set(expr): pass
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
  1722
        else:
e18a9ceade3b perf: support obtaining contexts from perfrevset
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27017
diff changeset
  1723
            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
  1724
    timer(d)
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1725
    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
  1726
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1727
@command(b'perfvolatilesets',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1728
         [(b'', b'clear-obsstore', False, b'drop obsstore between each call.'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1729
          ] + formatteropts)
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1730
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
  1731
    """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
  1732
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
  1733
    Volatile set computes element related to filtering and obsolescence."""
25494
e8eb3ecdaa0c perf: support -T for every perf commands
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24607
diff changeset
  1734
    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
  1735
    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
  1736
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
  1737
    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
  1738
        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
  1739
            repo.invalidatevolatilesets()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1740
            if opts[b'clear_obsstore']:
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1741
                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
  1742
            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
  1743
        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
  1744
18241
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  1745
    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
  1746
    if names:
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  1747
        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
  1748
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  1749
    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
  1750
        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
  1751
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
  1752
    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
  1753
        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
  1754
            repo.invalidatevolatilesets()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1755
            if opts[b'clear_obsstore']:
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1756
                clearfilecache(repo, b'obsstore')
20205
d67a7758da6d perf: fix perfvolatilesets
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20178
diff changeset
  1757
            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
  1758
        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
  1759
18241
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  1760
    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
  1761
    if names:
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  1762
        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
  1763
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
  1764
    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
  1765
        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
  1766
    fm.end()
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1767
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1768
@command(b'perfbranchmap',
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1769
         [(b'f', b'full', False,
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1770
           b'Includes build time of subset'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1771
          (b'', b'clear-revbranch', False,
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1772
           b'purge the revbranch cache between computation'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1773
          ] + formatteropts)
36360
c25290b98190 perfbranchmap: allow to select the filter to benchmark
Boris Feld <boris.feld@octobus.net>
parents: 36359
diff changeset
  1774
def perfbranchmap(ui, repo, *filternames, **opts):
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1775
    """benchmark the update of a branchmap
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1776
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1777
    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
  1778
    """
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1779
    full = opts.get(b"full", False)
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1780
    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
  1781
    timer, fm = gettimer(ui, opts)
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1782
    def getbranchmap(filtername):
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1783
        """generate a benchmark function for the filtername"""
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1784
        if filtername is None:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1785
            view = repo
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1786
        else:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1787
            view = repo.filtered(filtername)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1788
        def d():
32710
326c0e2c1a1d perfbranchmap: add an option to purge the revbranch cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32532
diff changeset
  1789
            if clear_revbranch:
326c0e2c1a1d perfbranchmap: add an option to purge the revbranch cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32532
diff changeset
  1790
                repo.revbranchcache()._clear()
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1791
            if full:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1792
                view._branchcaches.clear()
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1793
            else:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1794
                view._branchcaches.pop(filtername, None)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1795
            view.branchmap()
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1796
        return d
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1797
    # 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
  1798
    possiblefilters = set(repoview.filtertable)
36360
c25290b98190 perfbranchmap: allow to select the filter to benchmark
Boris Feld <boris.feld@octobus.net>
parents: 36359
diff changeset
  1799
    if filternames:
c25290b98190 perfbranchmap: allow to select the filter to benchmark
Boris Feld <boris.feld@octobus.net>
parents: 36359
diff changeset
  1800
        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
  1801
    subsettable = getbranchmapsubsettable()
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1802
    allfilters = []
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1803
    while possiblefilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1804
        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
  1805
            subset = subsettable.get(name)
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1806
            if subset not in possiblefilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1807
                break
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1808
        else:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1809
            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
  1810
        allfilters.append(name)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1811
        possiblefilters.remove(name)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1812
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1813
    # warm the cache
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1814
    if not full:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1815
        for name in allfilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1816
            repo.filtered(name).branchmap()
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1817
    if not filternames or b'unfiltered' in filternames:
36360
c25290b98190 perfbranchmap: allow to select the filter to benchmark
Boris Feld <boris.feld@octobus.net>
parents: 36359
diff changeset
  1818
        # add unfiltered
c25290b98190 perfbranchmap: allow to select the filter to benchmark
Boris Feld <boris.feld@octobus.net>
parents: 36359
diff changeset
  1819
        allfilters.append(None)
30145
113aa6145020 perf: avoid actual writing branch cache out correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30144
diff changeset
  1820
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1821
    branchcacheread = safeattrsetter(branchmap, b'read')
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1822
    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
  1823
    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
  1824
    branchcachewrite.set(lambda bc, repo: None)
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1825
    try:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1826
        for name in allfilters:
36359
df3f7f00a3fc perfbranchmap: display 'unfiltered' for unfiltered performance
Boris Feld <boris.feld@octobus.net>
parents: 36178
diff changeset
  1827
            printname = name
df3f7f00a3fc perfbranchmap: display 'unfiltered' for unfiltered performance
Boris Feld <boris.feld@octobus.net>
parents: 36178
diff changeset
  1828
            if name is None:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1829
                printname = b'unfiltered'
36359
df3f7f00a3fc perfbranchmap: display 'unfiltered' for unfiltered performance
Boris Feld <boris.feld@octobus.net>
parents: 36178
diff changeset
  1830
            timer(getbranchmap(name), title=str(printname))
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
  1831
    finally:
30145
113aa6145020 perf: avoid actual writing branch cache out correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30144
diff changeset
  1832
        branchcacheread.restore()
113aa6145020 perf: avoid actual writing branch cache out correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 30144
diff changeset
  1833
        branchcachewrite.restore()
23171
8afae1d5d108 perf: use a formatter for output
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22780
diff changeset
  1834
    fm.end()
23485
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
  1835
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1836
@command(b'perfbranchmapload', [
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1837
     (b'f', b'filter', b'', b'Specify repoview filter'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1838
     (b'', b'list', False, b'List brachmap filter caches'),
39114
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1839
    ] + formatteropts)
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1840
def perfbranchmapread(ui, repo, filter=b'', list=False, **opts):
39114
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1841
    """benchmark reading the branchmap"""
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1842
    if list:
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1843
        for name, kind, st in repo.cachevfs.readdir(stat=True):
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1844
            if name.startswith(b'branch2'):
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1845
                filtername = name.partition(b'-')[2] or b'unfiltered'
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1846
                ui.status(b'%s - %s\n'
39114
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1847
                          % (filtername, util.bytecount(st.st_size)))
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1848
        return
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1849
    if filter:
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1850
        repo = repoview.repoview(repo, filter)
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1851
    else:
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1852
        repo = repo.unfiltered()
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1853
    # try once without timer, the filter may not be cached
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1854
    if branchmap.read(repo) is None:
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1855
        raise error.Abort(b'No brachmap cached for %s repo'
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1856
                          % (filter or b'unfiltered'))
39114
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1857
    timer, fm = gettimer(ui, opts)
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1858
    timer(lambda: branchmap.read(repo) and None)
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1859
    fm.end()
222aba766015 perf: time loading branchmap caches
Martijn Pieters <mj@octobus.net>
parents: 38977
diff changeset
  1860
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1861
@command(b'perfloadmarkers')
23485
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
  1862
def perfloadmarkers(ui, repo):
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
  1863
    """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
  1864
ccb93e9affc1 perf: add a perfloadmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23171
diff changeset
  1865
    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
  1866
    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
  1867
    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
  1868
    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
  1869
    fm.end()
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1870
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1871
@command(b'perflrucachedict', formatteropts +
39568
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1872
    [(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: 39567
diff changeset
  1873
     (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: 39567
diff changeset
  1874
     (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: 39567
diff changeset
  1875
     (b'', b'size', 4, b'size of cache'),
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1876
     (b'', b'gets', 10000, b'number of key lookups'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1877
     (b'', b'sets', 10000, b'number of key sets'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1878
     (b'', b'mixed', 10000, b'number of mixed mode operations'),
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1879
     (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
  1880
    norepo=True)
39568
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1881
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: 39567
diff changeset
  1882
                 gets=10000, sets=10000, mixed=10000, mixedgetfreq=50, **opts):
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1883
    def doinit():
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1884
        for i in xrange(10000):
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1885
            util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1886
39568
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1887
    costrange = list(range(mincost, maxcost + 1))
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1888
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1889
    values = []
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1890
    for i in xrange(size):
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1891
        values.append(random.randint(0, sys.maxint))
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1892
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1893
    # 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
  1894
    # eviction.
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1895
    getseq = []
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1896
    for i in xrange(gets):
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1897
        getseq.append(random.choice(values))
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1898
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1899
    def dogets():
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1900
        d = util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1901
        for v in values:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1902
            d[v] = v
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1903
        for key in getseq:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1904
            value = d[key]
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1905
            value # silence pyflakes warning
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1906
39568
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1907
    def dogetscost():
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1908
        d = util.lrucachedict(size, maxcost=costlimit)
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1909
        for i, v in enumerate(values):
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1910
            d.insert(v, v, cost=costs[i])
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1911
        for key in getseq:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1912
            try:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1913
                value = d[key]
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1914
                value # silence pyflakes warning
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1915
            except KeyError:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1916
                pass
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1917
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1918
    # Set mode tests insertion speed with cache eviction.
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1919
    setseq = []
39568
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1920
    costs = []
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1921
    for i in xrange(sets):
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1922
        setseq.append(random.randint(0, sys.maxint))
39568
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1923
        costs.append(random.choice(costrange))
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1924
39567
ee087f0d7db5 util: allow lrucachedict to track cost of entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39362
diff changeset
  1925
    def doinserts():
ee087f0d7db5 util: allow lrucachedict to track cost of entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39362
diff changeset
  1926
        d = util.lrucachedict(size)
ee087f0d7db5 util: allow lrucachedict to track cost of entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39362
diff changeset
  1927
        for v in setseq:
ee087f0d7db5 util: allow lrucachedict to track cost of entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39362
diff changeset
  1928
            d.insert(v, v)
ee087f0d7db5 util: allow lrucachedict to track cost of entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39362
diff changeset
  1929
39568
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1930
    def doinsertscost():
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1931
        d = util.lrucachedict(size, maxcost=costlimit)
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1932
        for i, v in enumerate(setseq):
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1933
            d.insert(v, v, cost=costs[i])
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1934
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1935
    def dosets():
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1936
        d = util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1937
        for v in setseq:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1938
            d[v] = v
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1939
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1940
    # Mixed mode randomly performs gets and sets with eviction.
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1941
    mixedops = []
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1942
    for i in xrange(mixed):
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1943
        r = random.randint(0, 100)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1944
        if r < mixedgetfreq:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1945
            op = 0
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1946
        else:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1947
            op = 1
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1948
39568
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1949
        mixedops.append((op,
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1950
                         random.randint(0, size * 2),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1951
                         random.choice(costrange)))
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1952
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1953
    def domixed():
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1954
        d = util.lrucachedict(size)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1955
39568
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1956
        for op, v, cost in mixedops:
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1957
            if op == 0:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1958
                try:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1959
                    d[v]
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1960
                except KeyError:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1961
                    pass
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1962
            else:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1963
                d[v] = v
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1964
39568
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1965
    def domixedcost():
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1966
        d = util.lrucachedict(size, maxcost=costlimit)
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1967
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1968
        for op, v, cost in mixedops:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1969
            if op == 0:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1970
                try:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1971
                    d[v]
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1972
                except KeyError:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1973
                    pass
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1974
            else:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1975
                d.insert(v, v, cost=cost)
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1976
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1977
    benches = [
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  1978
        (doinit, b'init'),
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1979
    ]
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1980
39568
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1981
    if costlimit:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1982
        benches.extend([
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1983
            (dogetscost, b'gets w/ cost limit'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1984
            (doinsertscost, b'inserts w/ cost limit'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1985
            (domixedcost, b'mixed w/ cost limit'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1986
        ])
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1987
    else:
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1988
        benches.extend([
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1989
            (dogets, b'gets'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1990
            (doinserts, b'inserts'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1991
            (dosets, b'sets'),
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1992
            (domixed, b'mixed')
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1993
        ])
842cd0bdda75 util: teach lrucachedict to enforce a max total cost
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39567
diff changeset
  1994
27286
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1995
    for fn, title in benches:
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1996
        timer, fm = gettimer(ui, opts)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1997
        timer(fn, title=title)
528cf1a73ae5 perf: add perflrucachedict command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27100
diff changeset
  1998
        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
  1999
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  2000
@command(b'perfwrite', formatteropts)
30977
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30975
diff changeset
  2001
def perfwrite(ui, repo, **opts):
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30975
diff changeset
  2002
    """microbenchmark ui.write
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30975
diff changeset
  2003
    """
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30975
diff changeset
  2004
    timer, fm = gettimer(ui, opts)
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30975
diff changeset
  2005
    def write():
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30975
diff changeset
  2006
        for i in range(100000):
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  2007
            ui.write((b'Testing write performance\n'))
30977
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30975
diff changeset
  2008
    timer(write)
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30975
diff changeset
  2009
    fm.end()
5a9e4dc8e4fd contrib: add a write microbenchmark to perf.py
Simon Farnsworth <simonfar@fb.com>
parents: 30975
diff changeset
  2010
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
  2011
def uisetup(ui):
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  2012
    if (util.safehasattr(cmdutil, b'openrevlog') and
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  2013
        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
  2014
        # 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
  2015
        # 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
  2016
        # 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
  2017
        # 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
  2018
        # 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
  2019
        def openrevlog(orig, repo, cmd, file_, opts):
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  2020
            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: 39319
diff changeset
  2021
                raise error.Abort(b"This version doesn't support --dir option",
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  2022
                                  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
  2023
            return orig(repo, cmd, file_, opts)
39362
438f3932a432 contrib: byteify perf.py file
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39319
diff changeset
  2024
        extensions.wrapfunction(cmdutil, b'openrevlog', openrevlog)