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