Show More
@@ -1,78 +1,85 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 |
|
2 | |||
3 | # Measure the performance of a list of revsets against multiple revisions |
|
3 | # Measure the performance of a list of revsets against multiple revisions | |
4 | # defined by parameter. Checkout one by one and run perfrevset with every |
|
4 | # defined by parameter. Checkout one by one and run perfrevset with every | |
5 | # revset in the list to benchmark its performance. |
|
5 | # revset in the list to benchmark its performance. | |
6 | # |
|
6 | # | |
7 | # - First argument is a revset of mercurial own repo to runs against. |
|
7 | # - First argument is a revset of mercurial own repo to runs against. | |
8 | # - Second argument is the file from which the revset array will be taken |
|
8 | # - Second argument is the file from which the revset array will be taken | |
9 | # If second argument is omitted read it from standard input |
|
9 | # If second argument is omitted read it from standard input | |
10 | # |
|
10 | # | |
11 | # You should run this from the root of your mercurial repository. |
|
11 | # You should run this from the root of your mercurial repository. | |
12 | # |
|
12 | # | |
13 | # This script also does one run of the current version of mercurial installed |
|
13 | # This script also does one run of the current version of mercurial installed | |
14 | # to compare performance. |
|
14 | # to compare performance. | |
15 |
|
15 | |||
16 | import sys |
|
16 | import sys | |
17 | from subprocess import check_call, check_output, CalledProcessError |
|
17 | from subprocess import check_call, check_output, CalledProcessError | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | def update(rev): |
|
20 | def update(rev): | |
21 | """update the repo to a revision""" |
|
21 | """update the repo to a revision""" | |
22 | try: |
|
22 | try: | |
23 | check_call(['hg', 'update', '--quiet', '--check', str(rev)]) |
|
23 | check_call(['hg', 'update', '--quiet', '--check', str(rev)]) | |
24 | except CalledProcessError, exc: |
|
24 | except CalledProcessError, exc: | |
25 | print >> sys.stderr, 'update to revision %s failed, aborting' % rev |
|
25 | print >> sys.stderr, 'update to revision %s failed, aborting' % rev | |
26 | sys.exit(exc.returncode) |
|
26 | sys.exit(exc.returncode) | |
27 |
|
27 | |||
28 | def perf(revset): |
|
28 | def perf(revset): | |
29 | """run benchmark for this very revset""" |
|
29 | """run benchmark for this very revset""" | |
30 | try: |
|
30 | try: | |
31 | check_call(['./hg', '--config', 'extensions.perf=contrib/perf.py', |
|
31 | check_call(['./hg', '--config', 'extensions.perf=contrib/perf.py', | |
32 | 'perfrevset', revset]) |
|
32 | 'perfrevset', revset]) | |
33 | except CalledProcessError, exc: |
|
33 | except CalledProcessError, exc: | |
34 | print >> sys.stderr, 'abort: cannot run revset benchmark' |
|
34 | print >> sys.stderr, 'abort: cannot run revset benchmark' | |
35 | sys.exit(exc.returncode) |
|
35 | sys.exit(exc.returncode) | |
36 |
|
36 | |||
37 | def printrevision(rev): |
|
37 | def printrevision(rev): | |
38 | """print data about a revision""" |
|
38 | """print data about a revision""" | |
39 | sys.stdout.write("Revision: ") |
|
39 | sys.stdout.write("Revision: ") | |
40 | sys.stdout.flush() |
|
40 | sys.stdout.flush() | |
41 | check_call(['hg', 'log', '--rev', str(rev), '--template', |
|
41 | check_call(['hg', 'log', '--rev', str(rev), '--template', | |
42 | '{desc|firstline}\n']) |
|
42 | '{desc|firstline}\n']) | |
43 |
|
43 | |||
|
44 | def getrevs(spec): | |||
|
45 | """get the list of rev matched by a revset""" | |||
|
46 | try: | |||
|
47 | out = check_output(['hg', 'log', '--template={rev}\n', '--rev', spec]) | |||
|
48 | except CalledProcessError, exc: | |||
|
49 | print >> sys.stderr, "abort, can't get revision from %s" % spec | |||
|
50 | sys.exit(exc.returncode) | |||
|
51 | return [r for r in out.split() if r] | |||
|
52 | ||||
|
53 | ||||
44 |
|
54 | |||
45 | target_rev = sys.argv[1] |
|
55 | target_rev = sys.argv[1] | |
46 |
|
56 | |||
47 | revsetsfile = sys.stdin |
|
57 | revsetsfile = sys.stdin | |
48 | if len(sys.argv) > 2: |
|
58 | if len(sys.argv) > 2: | |
49 | revsetsfile = open(sys.argv[2]) |
|
59 | revsetsfile = open(sys.argv[2]) | |
50 |
|
60 | |||
51 | revsets = [l.strip() for l in revsetsfile] |
|
61 | revsets = [l.strip() for l in revsetsfile] | |
52 |
|
62 | |||
53 | print "Revsets to benchmark" |
|
63 | print "Revsets to benchmark" | |
54 | print "----------------------------" |
|
64 | print "----------------------------" | |
55 |
|
65 | |||
56 | for idx, rset in enumerate(revsets): |
|
66 | for idx, rset in enumerate(revsets): | |
57 | print "%i) %s" % (idx, rset) |
|
67 | print "%i) %s" % (idx, rset) | |
58 |
|
68 | |||
59 | print "----------------------------" |
|
69 | print "----------------------------" | |
60 |
|
70 | |||
61 |
|
71 | |||
62 | revs = check_output("hg log --template='{rev}\n' --rev " + target_rev, |
|
|||
63 | shell=True) |
|
|||
64 |
|
72 | |||
65 | revs = [r for r in revs.split() if r] |
|
73 | revs = getrevs(target_rev) | |
66 |
|
74 | |||
67 | # Benchmark revisions |
|
|||
68 | for r in revs: |
|
75 | for r in revs: | |
69 | print "----------------------------" |
|
76 | print "----------------------------" | |
70 | printrevision(r) |
|
77 | printrevision(r) | |
71 | print "----------------------------" |
|
78 | print "----------------------------" | |
72 | update(r) |
|
79 | update(r) | |
73 | for idx, rset in enumerate(revsets): |
|
80 | for idx, rset in enumerate(revsets): | |
74 | sys.stdout.write("%i) " % idx) |
|
81 | sys.stdout.write("%i) " % idx) | |
75 | sys.stdout.flush() |
|
82 | sys.stdout.flush() | |
76 | perf(rset) |
|
83 | perf(rset) | |
77 | print "----------------------------" |
|
84 | print "----------------------------" | |
78 |
|
85 |
General Comments 0
You need to be logged in to leave comments.
Login now