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