contrib/perf.py
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
Mon, 04 Mar 2013 10:05:52 +0100
branchstable
changeset 18754 d420ac09f866
parent 18304 9b6ae29d4801
child 18644 3e92772d5383
permissions -rw-r--r--
setup.py: ignore warnings from obsolete Fix version detection with recent hg versions.
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
18240
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
     4
from mercurial import cmdutil, scmutil, util, match, commands, obsolete
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
     5
from mercurial import repoview, branchmap
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     6
import time, os, sys
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     7
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
     8
cmdtable = {}
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
     9
command = cmdutil.command(cmdtable)
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
    10
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
    11
def timer(func, title=None):
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    12
    results = []
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    13
    begin = time.time()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    14
    count = 0
14494
1ffeeb91c55d check-code: flag 0/1 used as constant Boolean expression
Martin Geisler <mg@lazybytes.net>
parents: 14322
diff changeset
    15
    while True:
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    16
        ostart = os.times()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    17
        cstart = time.time()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    18
        r = func()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    19
        cstop = time.time()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    20
        ostop = os.times()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    21
        count += 1
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    22
        a, b = ostart, ostop
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    23
        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
    24
        if cstop - begin > 3 and count >= 100:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    25
            break
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    26
        if cstop - begin > 10 and count >= 3:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    27
            break
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
    28
    if title:
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
    29
        sys.stderr.write("! %s\n" % title)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    30
    if r:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    31
        sys.stderr.write("! result: %s\n" % r)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    32
    m = min(results)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    33
    sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n"
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    34
                     % (m[0], m[1] + m[2], m[1], m[2], count))
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    35
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
    36
@command('perfwalk')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    37
def perfwalk(ui, repo, *pats):
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    38
    try:
14671
35c2cc322ba8 scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents: 14494
diff changeset
    39
        m = scmutil.match(repo[None], pats, {})
10176
24ce8f0c0a39 dirstate: don't check state of subrepo directories
Augie Fackler <durin42@gmail.com>
parents: 9932
diff changeset
    40
        timer(lambda: len(list(repo.dirstate.walk(m, [], True, False))))
16689
f366d4c2ff34 cleanup: replace naked excepts with except Exception: ...
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
    41
    except Exception:
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    42
        try:
14671
35c2cc322ba8 scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents: 14494
diff changeset
    43
            m = scmutil.match(repo[None], pats, {})
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10176
diff changeset
    44
            timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)]))
16689
f366d4c2ff34 cleanup: replace naked excepts with except Exception: ...
Brodie Rao <brodie@sf.io>
parents: 16683
diff changeset
    45
        except Exception:
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    46
            timer(lambda: len(list(cmdutil.walk(repo, pats, {}))))
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    47
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
    48
@command('perfstatus',
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
    49
         [('u', 'unknown', False,
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
    50
           'ask status to look for unknown files')])
18033
00ac420f24ee perf: add option to perfstatus to get the status of unknown files
Siddharth Agarwal <sid0@fb.com>
parents: 17780
diff changeset
    51
def perfstatus(ui, repo, **opts):
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    52
    #m = match.always(repo.root, repo.getcwd())
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 16414
diff changeset
    53
    #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
    54
    #                                                False))))
18033
00ac420f24ee perf: add option to perfstatus to get the status of unknown files
Siddharth Agarwal <sid0@fb.com>
parents: 17780
diff changeset
    55
    timer(lambda: sum(map(len, repo.status(**opts))))
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    56
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    57
def clearcaches(cl):
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    58
    # behave somewhat consistently across internal API changes
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    59
    if util.safehasattr(cl, 'clearcaches'):
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    60
        cl.clearcaches()
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    61
    elif util.safehasattr(cl, '_nodecache'):
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    62
        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
    63
        cl._nodecache = {nullid: nullrev}
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    64
        cl._nodepos = None
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    65
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
    66
@command('perfheads')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    67
def perfheads(ui, repo):
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    68
    cl = repo.changelog
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    69
    def d():
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    70
        len(cl.headrevs())
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    71
        clearcaches(cl)
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
    72
    timer(d)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    73
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
    74
@command('perftags')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    75
def perftags(ui, repo):
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    76
    import mercurial.changelog, mercurial.manifest
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    77
    def t():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    78
        repo.changelog = mercurial.changelog.changelog(repo.sopener)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    79
        repo.manifest = mercurial.manifest.manifest(repo.sopener)
9146
5614a628d173 localrepo: rename in-memory tag cache instance attributes (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 8873
diff changeset
    80
        repo._tags = None
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    81
        return len(repo.tags())
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    82
    timer(t)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    83
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
    84
@command('perfancestors')
16802
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
    85
def perfancestors(ui, repo):
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
    86
    heads = repo.changelog.headrevs()
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
    87
    def d():
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16858
diff changeset
    88
        for a in repo.changelog.ancestors(heads):
16802
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
    89
            pass
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
    90
    timer(d)
7e5d94381cd1 perf: add a perfancestors benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16788
diff changeset
    91
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
    92
@command('perfancestorset')
18080
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
    93
def perfancestorset(ui, repo, revset):
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
    94
    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
    95
    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
    96
    def d():
18091
f7f8159caad3 ancestor: add lazy membership testing to lazyancestors
Siddharth Agarwal <sid0@fb.com>
parents: 18080
diff changeset
    97
        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
    98
        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
    99
            rev in s
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   100
    timer(d)
486bfb200b3f perf: add command to test performance of membership in ancestor set
Siddharth Agarwal <sid0@fb.com>
parents: 18062
diff changeset
   101
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   102
@command('perfdirstate')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   103
def perfdirstate(ui, repo):
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   104
    "a" in repo.dirstate
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   105
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   106
        repo.dirstate.invalidate()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   107
        "a" in repo.dirstate
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   108
    timer(d)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   109
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   110
@command('perfdirstatedirs')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   111
def perfdirstatedirs(ui, repo):
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   112
    "a" in repo.dirstate
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   113
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   114
        "a" in repo.dirstate._dirs
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   115
        del repo.dirstate._dirs
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   116
    timer(d)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   117
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   118
@command('perfdirstatewrite')
16788
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   119
def perfdirstatewrite(ui, repo):
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   120
    ds = repo.dirstate
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   121
    "a" in ds
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   122
    def d():
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   123
        ds._dirty = True
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   124
        ds.write()
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   125
    timer(d)
7e72c1609862 perf: add a perfdirstatewrite benchmark
Bryan O'Sullivan <bryano@fb.com>
parents: 16785
diff changeset
   126
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   127
@command('perfmanifest')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   128
def perfmanifest(ui, repo):
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   129
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   130
        t = repo.manifest.tip()
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   131
        m = repo.manifest.read(t)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   132
        repo.manifest.mapcache = None
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   133
        repo.manifest._cache = None
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   134
    timer(d)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   135
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   136
@command('perfchangeset')
16262
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   137
def perfchangeset(ui, repo, rev):
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   138
    n = repo[rev].node()
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   139
    def d():
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   140
        c = repo.changelog.read(n)
16266
77d56a5e74a5 perf: add a changeset test
Matt Mackall <mpm@selenic.com>
parents: 16262
diff changeset
   141
        #repo.changelog._cache = None
16262
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   142
    timer(d)
bf7a6c3b2a4a perf: add perfchangeset to time changeset parsing
Matt Mackall <mpm@selenic.com>
parents: 16260
diff changeset
   143
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   144
@command('perfindex')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   145
def perfindex(ui, repo):
13255
2696730ca233 perf: make perfindex results useful on hg with lazyparser
Matt Mackall <mpm@selenic.com>
parents: 13254
diff changeset
   146
    import mercurial.revlog
13277
9f707b297b0f perf: restore lazyindex hack
Matt Mackall <mpm@selenic.com>
parents: 13262
diff changeset
   147
    mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
13254
5ef5eb1f3515 revlog: only build the nodemap on demand
Matt Mackall <mpm@selenic.com>
parents: 13253
diff changeset
   148
    n = repo["tip"].node()
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   149
    def d():
16260
33fcad3cfbbc perf: tweak tests for testing index performance improvements
Matt Mackall <mpm@selenic.com>
parents: 14671
diff changeset
   150
        cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
33fcad3cfbbc perf: tweak tests for testing index performance improvements
Matt Mackall <mpm@selenic.com>
parents: 14671
diff changeset
   151
        cl.rev(n)
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   152
    timer(d)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   153
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   154
@command('perfstartup')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   155
def perfstartup(ui, repo):
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   156
    cmd = sys.argv[0]
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   157
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   158
        os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   159
    timer(d)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   160
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   161
@command('perfparents')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   162
def perfparents(ui, repo):
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   163
    nl = [repo.changelog.node(i) for i in xrange(1000)]
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   164
    def d():
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   165
        for n in nl:
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   166
            repo.changelog.parents(n)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   167
    timer(d)
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   168
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   169
@command('perflookup')
7366
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   170
def perflookup(ui, repo, rev):
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   171
    timer(lambda: len(repo.lookup(rev)))
eb240755386d Add contrib/perf.py for performance testing
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
   172
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   173
@command('perfrevrange')
16858
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
   174
def perfrevrange(ui, repo, *specs):
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
   175
    revrange = scmutil.revrange
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
   176
    timer(lambda: len(revrange(repo, specs)))
fdf99e0f60f3 perf: add a benchmark for revrange
Bryan O'Sullivan <bryano@fb.com>
parents: 16802
diff changeset
   177
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   178
@command('perfnodelookup')
16309
e0c1b3ef7c36 perf: node lookup
Matt Mackall <mpm@selenic.com>
parents: 16266
diff changeset
   179
def perfnodelookup(ui, repo, rev):
e0c1b3ef7c36 perf: node lookup
Matt Mackall <mpm@selenic.com>
parents: 16266
diff changeset
   180
    import mercurial.revlog
e0c1b3ef7c36 perf: node lookup
Matt Mackall <mpm@selenic.com>
parents: 16266
diff changeset
   181
    mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
e0c1b3ef7c36 perf: node lookup
Matt Mackall <mpm@selenic.com>
parents: 16266
diff changeset
   182
    n = repo[rev].node()
16414
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
   183
    cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
   184
    def d():
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
   185
        cl.rev(n)
16785
1dc08dc63c09 perf: rework perfheads and perftags to clear caches
Bryan O'Sullivan <bryano@fb.com>
parents: 16689
diff changeset
   186
        clearcaches(cl)
16414
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
   187
    timer(d)
e8d37b78acfb parsers: use base-16 trie for faster node->rev mapping
Bryan O'Sullivan <bryano@fb.com>
parents: 16403
diff changeset
   188
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   189
@command('perflog',
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   190
         [('', 'rename', False, 'ask log to follow renames')])
9932
2fcbef9a349a perf.perflog: add option to follow renames
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9826
diff changeset
   191
def perflog(ui, repo, **opts):
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   192
    ui.pushbuffer()
9932
2fcbef9a349a perf.perflog: add option to follow renames
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9826
diff changeset
   193
    timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
2fcbef9a349a perf.perflog: add option to follow renames
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9826
diff changeset
   194
                               copies=opts.get('rename')))
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   195
    ui.popbuffer()
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   196
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   197
@command('perftemplating')
7872
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   198
def perftemplating(ui, repo):
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   199
    ui.pushbuffer()
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   200
    timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   201
                               template='{date|shortdate} [{rev}:{node|short}]'
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   202
                               ' {author|person}: {desc|firstline}\n'))
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   203
    ui.popbuffer()
f680a1bd679b contrib: add perflog and perftemplating commands to perf extension
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7366
diff changeset
   204
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   205
@command('perfcca')
16386
ccc173d0914e perf: add case collision auditor perf
Matt Mackall <mpm@selenic.com>
parents: 16309
diff changeset
   206
def perfcca(ui, repo):
17216
01c1ee4bd1dd perf: fix perfcca to work with new casecollisionauditor interface
Joshua Redstone <joshua.redstone@fb.com>
parents: 16866
diff changeset
   207
    timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
16386
ccc173d0914e perf: add case collision auditor perf
Matt Mackall <mpm@selenic.com>
parents: 16309
diff changeset
   208
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   209
@command('perffncacheload')
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   210
def perffncacheload(ui, repo):
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
   211
    s = repo.store
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   212
    def d():
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   213
        s.fncache._load()
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   214
    timer(d)
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   215
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   216
@command('perffncachewrite')
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   217
def perffncachewrite(ui, repo):
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
   218
    s = repo.store
16403
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   219
    s.fncache._load()
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   220
    def d():
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   221
        s.fncache._dirty = True
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   222
        s.fncache.write()
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   223
    timer(d)
efae1fea4bbd perf: time fncache read and write performance
Bryan O'Sullivan <bryano@fb.com>
parents: 16386
diff changeset
   224
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   225
@command('perffncacheencode')
17553
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   226
def perffncacheencode(ui, repo):
17780
769f66861eb8 perf: simply use repo.store for perffncache* commands
Adrian Buehlmann <adrian@cadifra.com>
parents: 17553
diff changeset
   227
    s = repo.store
17553
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   228
    s.fncache._load()
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   229
    def d():
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   230
        for p in s.fncache.entries:
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   231
            s.encode(p)
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   232
    timer(d)
5ab863922e0f perf: add perffncacheencode
Adrian Buehlmann <adrian@cadifra.com>
parents: 17216
diff changeset
   233
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   234
@command('perfdiffwd')
9826
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   235
def perfdiffwd(ui, repo):
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   236
    """Profile diff of working directory changes"""
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   237
    options = {
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   238
        'w': 'ignore_all_space',
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   239
        'b': 'ignore_space_change',
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   240
        'B': 'ignore_blank_lines',
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   241
        }
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   242
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   243
    for diffopt in ('', 'w', 'b', 'B', 'wB'):
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   244
        opts = dict((options[c], '1') for c in diffopt)
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   245
        def d():
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   246
            ui.pushbuffer()
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   247
            commands.diff(ui, repo, **opts)
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   248
            ui.popbuffer()
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   249
        title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   250
        timer(d, title)
d768614578dd contrib/perf: profile diff of working directory changes
Patrick Mezard <pmezard@gmail.com>
parents: 9146
diff changeset
   251
18237
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   252
@command('perfrevlog',
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   253
         [('d', 'dist', 100, 'distance between the revisions')],
4132dc9bd5c4 perftest: migrate to new style command declaration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18236
diff changeset
   254
         "[INDEXFILE]")
11694
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   255
def perfrevlog(ui, repo, file_, **opts):
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   256
    from mercurial import revlog
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   257
    dist = opts['dist']
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   258
    def d():
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   259
        r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   260
        for x in xrange(0, len(r), dist):
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   261
            r.revision(r.node(x))
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   262
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   263
    timer(d)
bf49d48e4602 perf: add perfrevlog function to check performance of revlog
Pradeepkumar Gayam <in3xes@gmail.com>
parents: 10493
diff changeset
   264
18239
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   265
@command('perfrevset',
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   266
         [('C', 'clear', False, 'clear volatile cache between each call.')],
18238
1f991e625d01 perftest: document the perfrevset command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18237
diff changeset
   267
         "REVSET")
18239
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   268
def perfrevset(ui, repo, expr, clear=False):
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   269
    """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
   270
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   271
    Use the --clean option if need to evaluate the impact of build volative
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   272
    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
   273
    and obsolete related cache."""
18062
1471f5e83686 perf: add a command to measure revset performance
Siddharth Agarwal <sid0@fb.com>
parents: 18033
diff changeset
   274
    def d():
18239
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   275
        if clear:
a95f1d619bb7 perftest: add an option to invalidate volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18238
diff changeset
   276
            repo.invalidatevolatilesets()
18062
1471f5e83686 perf: add a command to measure revset performance
Siddharth Agarwal <sid0@fb.com>
parents: 18033
diff changeset
   277
        repo.revs(expr)
1471f5e83686 perf: add a command to measure revset performance
Siddharth Agarwal <sid0@fb.com>
parents: 18033
diff changeset
   278
    timer(d)
18240
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   279
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   280
@command('perfvolatilesets')
18241
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   281
def perfvolatilesets(ui, repo, *names):
18240
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   282
    """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
   283
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   284
    Volatile set computes element related to filtering and obsolescence."""
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   285
    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
   286
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   287
    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
   288
        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
   289
            repo.invalidatevolatilesets()
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   290
            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
   291
        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
   292
18241
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   293
    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
   294
    if names:
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   295
        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
   296
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   297
    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
   298
        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
   299
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   300
    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
   301
        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
   302
            repo.invalidatevolatilesets()
a8318715d8bb perftest: add a command to benchmark construction of volatile cache
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18239
diff changeset
   303
            repoview.filteredrevs(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
   304
        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
   305
18241
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   306
    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
   307
    if names:
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   308
        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
   309
f5ed27c51995 perftest: allow selection of volatile set to benchmark
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18240
diff changeset
   310
    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
   311
        timer(getfiltered(name), title=name)
18304
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   312
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   313
@command('perfbranchmap',
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   314
         [('f', 'full', False,
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   315
           'Includes build time of subset'),
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   316
         ])
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   317
def perfbranchmap(ui, repo, full=False):
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   318
    """benchmark the update of a branchmap
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   319
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   320
    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
   321
    """
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   322
    def getbranchmap(filtername):
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   323
        """generate a benchmark function for the filtername"""
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   324
        if filtername is None:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   325
            view = repo
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   326
        else:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   327
            view = repo.filtered(filtername)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   328
        def d():
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   329
            if full:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   330
                view._branchcaches.clear()
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   331
            else:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   332
                view._branchcaches.pop(filtername, None)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   333
            view.branchmap()
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   334
        return d
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   335
    # 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
   336
    possiblefilters = set(repoview.filtertable)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   337
    allfilters = []
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   338
    while possiblefilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   339
        for name in possiblefilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   340
            subset = repoview.subsettable.get(name)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   341
            if subset not in possiblefilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   342
                break
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   343
        else:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   344
            assert False, 'subset cycle %s!' % possiblefilters
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   345
        allfilters.append(name)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   346
        possiblefilters.remove(name)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   347
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   348
    # warm the cache
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   349
    if not full:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   350
        for name in allfilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   351
            repo.filtered(name).branchmap()
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   352
    # add unfiltered
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   353
    allfilters.append(None)
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   354
    oldread = branchmap.read
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   355
    oldwrite = branchmap.branchcache.write
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   356
    try:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   357
        branchmap.read = lambda repo: None
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   358
        branchmap.write = lambda repo: None
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   359
        for name in allfilters:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   360
            timer(getbranchmap(name), title=str(name))
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   361
    finally:
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   362
        branchmap.read = oldread
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   363
        branchmap.branchcache.write = oldwrite
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   364
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   365
9b6ae29d4801 perf: add perfbranchmap command
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18241
diff changeset
   366