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