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