Show More
@@ -1,143 +1,148 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | |
|
3 | 3 | # Measure the performance of a list of revsets against multiple revisions |
|
4 | 4 | # defined by parameter. Checkout one by one and run perfrevset with every |
|
5 | 5 | # revset in the list to benchmark its performance. |
|
6 | 6 | # |
|
7 | 7 | # - First argument is a revset of mercurial own repo to runs against. |
|
8 | 8 | # - Second argument is the file from which the revset array will be taken |
|
9 | 9 | # If second argument is omitted read it from standard input |
|
10 | 10 | # |
|
11 | 11 | # You should run this from the root of your mercurial repository. |
|
12 | 12 | # |
|
13 | 13 | # This script also does one run of the current version of mercurial installed |
|
14 | 14 | # to compare performance. |
|
15 | 15 | |
|
16 | 16 | import sys |
|
17 | 17 | import os |
|
18 | 18 | from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE |
|
19 | 19 | # cannot use argparse, python 2.7 only |
|
20 | 20 | from optparse import OptionParser |
|
21 | 21 | |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | def check_output(*args, **kwargs): |
|
25 | 25 | kwargs.setdefault('stderr', PIPE) |
|
26 | 26 | kwargs.setdefault('stdout', PIPE) |
|
27 | 27 | proc = Popen(*args, **kwargs) |
|
28 | 28 | output, error = proc.communicate() |
|
29 | 29 | if proc.returncode != 0: |
|
30 | 30 | raise CalledProcessError(proc.returncode, ' '.join(args[0])) |
|
31 | 31 | return output |
|
32 | 32 | |
|
33 | 33 | def update(rev): |
|
34 | 34 | """update the repo to a revision""" |
|
35 | 35 | try: |
|
36 | 36 | check_call(['hg', 'update', '--quiet', '--check', str(rev)]) |
|
37 | 37 | except CalledProcessError, exc: |
|
38 | 38 | print >> sys.stderr, 'update to revision %s failed, aborting' % rev |
|
39 | 39 | sys.exit(exc.returncode) |
|
40 | 40 | |
|
41 | def perf(revset): | |
|
41 | def perf(revset, target=None): | |
|
42 | 42 | """run benchmark for this very revset""" |
|
43 | 43 | try: |
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 | stderr=STDOUT) | |
|
44 | cmd = ['./hg', | |
|
45 | '--config', | |
|
46 | 'extensions.perf=' | |
|
47 | + os.path.join(contribdir, 'perf.py'), | |
|
48 | 'perfrevset', | |
|
49 | revset] | |
|
50 | if target is not None: | |
|
51 | cmd.append('-R') | |
|
52 | cmd.append(target) | |
|
53 | output = check_output(cmd, stderr=STDOUT) | |
|
51 | 54 | output = output.lstrip('!') # remove useless ! in this context |
|
52 | 55 | return output.strip() |
|
53 | 56 | except CalledProcessError, exc: |
|
54 | 57 | print >> sys.stderr, 'abort: cannot run revset benchmark' |
|
55 | 58 | sys.exit(exc.returncode) |
|
56 | 59 | |
|
57 | 60 | def printrevision(rev): |
|
58 | 61 | """print data about a revision""" |
|
59 | 62 | sys.stdout.write("Revision: ") |
|
60 | 63 | sys.stdout.flush() |
|
61 | 64 | check_call(['hg', 'log', '--rev', str(rev), '--template', |
|
62 | 65 | '{desc|firstline}\n']) |
|
63 | 66 | |
|
64 | 67 | def getrevs(spec): |
|
65 | 68 | """get the list of rev matched by a revset""" |
|
66 | 69 | try: |
|
67 | 70 | out = check_output(['hg', 'log', '--template={rev}\n', '--rev', spec]) |
|
68 | 71 | except CalledProcessError, exc: |
|
69 | 72 | print >> sys.stderr, "abort, can't get revision from %s" % spec |
|
70 | 73 | sys.exit(exc.returncode) |
|
71 | 74 | return [r for r in out.split() if r] |
|
72 | 75 | |
|
73 | 76 | |
|
74 | 77 | parser = OptionParser(usage="usage: %prog [options] <revs>") |
|
75 | 78 | parser.add_option("-f", "--file", |
|
76 | 79 | help="read revset from FILE", metavar="FILE") |
|
80 | parser.add_option("-R", "--repo", | |
|
81 | help="run benchmark on REPO", metavar="REPO") | |
|
77 | 82 | |
|
78 | 83 | (options, args) = parser.parse_args() |
|
79 | 84 | |
|
80 | 85 | if len(sys.argv) < 2: |
|
81 | 86 | parser.print_help() |
|
82 | 87 | sys.exit(255) |
|
83 | 88 | |
|
84 | 89 | # the directory where both this script and the perf.py extension live. |
|
85 | 90 | contribdir = os.path.dirname(__file__) |
|
86 | 91 | |
|
87 | 92 | target_rev = args[0] |
|
88 | 93 | |
|
89 | 94 | revsetsfile = sys.stdin |
|
90 | 95 | if options.file: |
|
91 | 96 | revsetsfile = open(options.file) |
|
92 | 97 | |
|
93 | 98 | revsets = [l.strip() for l in revsetsfile] |
|
94 | 99 | |
|
95 | 100 | print "Revsets to benchmark" |
|
96 | 101 | print "----------------------------" |
|
97 | 102 | |
|
98 | 103 | for idx, rset in enumerate(revsets): |
|
99 | 104 | print "%i) %s" % (idx, rset) |
|
100 | 105 | |
|
101 | 106 | print "----------------------------" |
|
102 | 107 | |
|
103 | 108 | |
|
104 | 109 | |
|
105 | 110 | revs = getrevs(target_rev) |
|
106 | 111 | |
|
107 | 112 | results = [] |
|
108 | 113 | for r in revs: |
|
109 | 114 | print "----------------------------" |
|
110 | 115 | printrevision(r) |
|
111 | 116 | print "----------------------------" |
|
112 | 117 | update(r) |
|
113 | 118 | res = [] |
|
114 | 119 | results.append(res) |
|
115 | 120 | for idx, rset in enumerate(revsets): |
|
116 | data = perf(rset) | |
|
121 | data = perf(rset, target=options.repo) | |
|
117 | 122 | res.append(data) |
|
118 | 123 | print "%i)" % idx, data |
|
119 | 124 | sys.stdout.flush() |
|
120 | 125 | print "----------------------------" |
|
121 | 126 | |
|
122 | 127 | |
|
123 | 128 | print """ |
|
124 | 129 | |
|
125 | 130 | Result by revset |
|
126 | 131 | ================ |
|
127 | 132 | """ |
|
128 | 133 | |
|
129 | 134 | print 'Revision:', revs |
|
130 | 135 | for idx, rev in enumerate(revs): |
|
131 | 136 | sys.stdout.write('%i) ' % idx) |
|
132 | 137 | sys.stdout.flush() |
|
133 | 138 | printrevision(rev) |
|
134 | 139 | |
|
135 | 140 | |
|
136 | 141 | |
|
137 | 142 | |
|
138 | 143 | for ridx, rset in enumerate(revsets): |
|
139 | 144 | |
|
140 | 145 | print "revset #%i: %s" % (ridx, rset) |
|
141 | 146 | for idx, data in enumerate(results): |
|
142 | 147 | print '%i) %s' % (idx, data[ridx]) |
|
143 | 148 |
General Comments 0
You need to be logged in to leave comments.
Login now