contrib/revsetbenchmarks.py
author Pierre-Yves David <pierre-yves.david@fb.com>
Wed, 26 Mar 2014 18:14:15 -0700
changeset 20850 d0c2535c7aba
parent 20849 5abc2562106a
child 20851 4130ec938c84
permissions -rwxr-xr-x
revsetbenchmark: convert update to proper subprocess call
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
     1
#!/usr/bin/env python
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
     2
20746
47fc466825da contrib: have the revset benchmark test script take a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20745
diff changeset
     3
# Measure the performance of a list of revsets against multiple revisions
47fc466825da contrib: have the revset benchmark test script take a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20745
diff changeset
     4
# defined by parameter. Checkout one by one and run perfrevset with every
47fc466825da contrib: have the revset benchmark test script take a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20745
diff changeset
     5
# revset in the list to benchmark its performance.
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
     6
#
20747
8c89433ccdcf contrib: make revset benchmark script able to read from stdin
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20746
diff changeset
     7
# - First argument is a revset of mercurial own repo to runs against.
8c89433ccdcf contrib: make revset benchmark script able to read from stdin
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20746
diff changeset
     8
# - Second argument is the file from which the revset array will be taken
8c89433ccdcf contrib: make revset benchmark script able to read from stdin
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20746
diff changeset
     9
#   If second argument is omitted read it from standard input
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    10
#
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    11
# You should run this from the root of your mercurial repository.
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    12
#
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    13
# This script also does one run of the current version of mercurial installed
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    14
# to compare performance.
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    15
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    16
import sys
20850
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    17
from subprocess import check_call, check_output, CalledProcessError
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    18
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    19
20850
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    20
def update(rev):
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    21
    """update the repo to a revision"""
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    22
    try:
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    23
        check_call(['hg', 'update', '--quiet', '--check', str(rev)])
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    24
    except CalledProcessError, exc:
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    25
        print >> sys.stderr, 'update to revision %s failed, aborting' % rev
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    26
        sys.exit(exc.returncode)
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    27
20830
44e80bf2688f contrib: explicitly enable perf extension for revset tests
Olle Lundberg <geek@nerd.sh>
parents: 20747
diff changeset
    28
PERF="./hg --config extensions.perf=contrib/perf.py perfrevset"
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    29
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    30
target_rev = sys.argv[1]
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    31
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    32
revsetsfile = sys.stdin
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    33
if len(sys.argv) > 2:
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    34
    revsetsfile = open(sys.argv[2])
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    35
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    36
revsets = [l.strip() for l in revsetsfile]
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    37
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    38
print "Revsets to benchmark"
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    39
print "----------------------------"
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    40
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    41
for idx, rset in enumerate(revsets):
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    42
    print "%i) %s" % (idx, rset)
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    43
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    44
print "----------------------------"
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    45
print
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    46
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    47
revs = check_output("hg log --template='{rev}\n' --rev " + target_rev,
20849
5abc2562106a revsetbenchmark: fix semicolon
Matt Mackall <mpm@selenic.com>
parents: 20848
diff changeset
    48
                    shell=True)
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    49
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    50
revs = [r for r in revs.split() if r]
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    51
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    52
# Benchmark revisions
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    53
for r in revs:
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    54
    print "----------------------------"
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    55
    sys.stdout.write("Revision: ")
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    56
    sys.stdout.flush()
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    57
    check_call('hg log -r %s --template "{desc|firstline}\n"' % r, shell=True)
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    58
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    59
    print "----------------------------"
20850
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    60
    update(r)
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    61
    for idx, rset in enumerate(revsets):
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    62
        sys.stdout.write("%i) " % idx)
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    63
        sys.stdout.flush()
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    64
        check_call(PERF + ' "%s"' % rset, shell=True)
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    65
    print "----------------------------"
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    66