Show More
@@ -15,6 +15,7 b'' | |||||
15 |
|
15 | |||
16 | import sys |
|
16 | import sys | |
17 | import os |
|
17 | import os | |
|
18 | import re | |||
18 | from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE |
|
19 | from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE | |
19 | # cannot use argparse, python 2.7 only |
|
20 | # cannot use argparse, python 2.7 only | |
20 | from optparse import OptionParser |
|
21 | from optparse import OptionParser | |
@@ -54,8 +55,7 b' def perf(revset, target=None):' | |||||
54 | """run benchmark for this very revset""" |
|
55 | """run benchmark for this very revset""" | |
55 | try: |
|
56 | try: | |
56 | output = hg(['perfrevset', revset], repo=target) |
|
57 | output = hg(['perfrevset', revset], repo=target) | |
57 | output = output.lstrip('!') # remove useless ! in this context |
|
58 | return parseoutput(output) | |
58 | return output.strip() |
|
|||
59 | except CalledProcessError, exc: |
|
59 | except CalledProcessError, exc: | |
60 | print >> sys.stderr, 'abort: cannot run revset benchmark: %s' % exc.cmd |
|
60 | print >> sys.stderr, 'abort: cannot run revset benchmark: %s' % exc.cmd | |
61 | if exc.output is None: |
|
61 | if exc.output is None: | |
@@ -64,6 +64,27 b' def perf(revset, target=None):' | |||||
64 | print >> sys.stderr, exc.output |
|
64 | print >> sys.stderr, exc.output | |
65 | sys.exit(exc.returncode) |
|
65 | sys.exit(exc.returncode) | |
66 |
|
66 | |||
|
67 | outputre = re.compile(r'! wall (\d+.\d+) comb (\d+.\d+) user (\d+.\d+) ' | |||
|
68 | 'sys (\d+.\d+) \(best of (\d+)\)') | |||
|
69 | ||||
|
70 | def parseoutput(output): | |||
|
71 | """parse a textual output into a dict | |||
|
72 | ||||
|
73 | We cannot just use json because we want to compare with old | |||
|
74 | versions of Mercurial that may not support json output. | |||
|
75 | """ | |||
|
76 | match = outputre.search(output) | |||
|
77 | if not match: | |||
|
78 | print >> sys.stderr, 'abort: invalid output:' | |||
|
79 | print >> sys.stderr, output | |||
|
80 | sys.exit(1) | |||
|
81 | return {'comb': float(match.group(2)), | |||
|
82 | 'count': int(match.group(5)), | |||
|
83 | 'sys': float(match.group(3)), | |||
|
84 | 'user': float(match.group(4)), | |||
|
85 | 'wall': float(match.group(1)), | |||
|
86 | } | |||
|
87 | ||||
67 | def printrevision(rev): |
|
88 | def printrevision(rev): | |
68 | """print data about a revision""" |
|
89 | """print data about a revision""" | |
69 | sys.stdout.write("Revision: ") |
|
90 | sys.stdout.write("Revision: ") | |
@@ -71,6 +92,13 b' def printrevision(rev):' | |||||
71 | check_call(['hg', 'log', '--rev', str(rev), '--template', |
|
92 | check_call(['hg', 'log', '--rev', str(rev), '--template', | |
72 | '{desc|firstline}\n']) |
|
93 | '{desc|firstline}\n']) | |
73 |
|
94 | |||
|
95 | def formatresult(data): | |||
|
96 | """format the data dict into a line of text for humans""" | |||
|
97 | return ("wall %f comb %f user %f sys %f (best of %d)" | |||
|
98 | % (data['wall'], data['comb'], data['user'], | |||
|
99 | data['sys'], data['count'])) | |||
|
100 | ||||
|
101 | ||||
74 | def getrevs(spec): |
|
102 | def getrevs(spec): | |
75 | """get the list of rev matched by a revset""" |
|
103 | """get the list of rev matched by a revset""" | |
76 | try: |
|
104 | try: | |
@@ -128,7 +156,7 b' for r in revs:' | |||||
128 | for idx, rset in enumerate(revsets): |
|
156 | for idx, rset in enumerate(revsets): | |
129 | data = perf(rset, target=options.repo) |
|
157 | data = perf(rset, target=options.repo) | |
130 | res.append(data) |
|
158 | res.append(data) | |
131 | print "%i)" % idx, data |
|
159 | print "%i)" % idx, formatresult(data) | |
132 | sys.stdout.flush() |
|
160 | sys.stdout.flush() | |
133 | print "----------------------------" |
|
161 | print "----------------------------" | |
134 |
|
162 | |||
@@ -152,5 +180,5 b' for ridx, rset in enumerate(revsets):' | |||||
152 |
|
180 | |||
153 | print "revset #%i: %s" % (ridx, rset) |
|
181 | print "revset #%i: %s" % (ridx, rset) | |
154 | for idx, data in enumerate(results): |
|
182 | for idx, data in enumerate(results): | |
155 | print '%i) %s' % (idx, data[ridx]) |
|
183 | print '%i) %s' % (idx, formatresult(data[ridx])) | |
156 |
|
184 |
General Comments 0
You need to be logged in to leave comments.
Login now