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