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