Show More
@@ -15,6 +15,7 | |||
|
15 | 15 | |
|
16 | 16 | import sys |
|
17 | 17 | import os |
|
18 | import re | |
|
18 | 19 | from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE |
|
19 | 20 | # cannot use argparse, python 2.7 only |
|
20 | 21 | from optparse import OptionParser |
@@ -54,8 +55,7 def perf(revset, target=None): | |||
|
54 | 55 | """run benchmark for this very revset""" |
|
55 | 56 | try: |
|
56 | 57 | output = hg(['perfrevset', revset], repo=target) |
|
57 | output = output.lstrip('!') # remove useless ! in this context | |
|
58 | return output.strip() | |
|
58 | return parseoutput(output) | |
|
59 | 59 | except CalledProcessError, exc: |
|
60 | 60 | print >> sys.stderr, 'abort: cannot run revset benchmark: %s' % exc.cmd |
|
61 | 61 | if exc.output is None: |
@@ -64,6 +64,27 def perf(revset, target=None): | |||
|
64 | 64 | print >> sys.stderr, exc.output |
|
65 | 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 | 88 | def printrevision(rev): |
|
68 | 89 | """print data about a revision""" |
|
69 | 90 | sys.stdout.write("Revision: ") |
@@ -71,6 +92,13 def printrevision(rev): | |||
|
71 | 92 | check_call(['hg', 'log', '--rev', str(rev), '--template', |
|
72 | 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 | 102 | def getrevs(spec): |
|
75 | 103 | """get the list of rev matched by a revset""" |
|
76 | 104 | try: |
@@ -128,7 +156,7 for r in revs: | |||
|
128 | 156 | for idx, rset in enumerate(revsets): |
|
129 | 157 | data = perf(rset, target=options.repo) |
|
130 | 158 | res.append(data) |
|
131 | print "%i)" % idx, data | |
|
159 | print "%i)" % idx, formatresult(data) | |
|
132 | 160 | sys.stdout.flush() |
|
133 | 161 | print "----------------------------" |
|
134 | 162 | |
@@ -152,5 +180,5 for ridx, rset in enumerate(revsets): | |||
|
152 | 180 | |
|
153 | 181 | print "revset #%i: %s" % (ridx, rset) |
|
154 | 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