##// END OF EJS Templates
revsetbenchmark: allow comments ('#' prefix) in the revset input
Pierre-Yves David -
r22556:480a24ad default
parent child Browse files
Show More
@@ -1,147 +1,147
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 77 help="read revset from FILE (stdin if omited)",
78 78 metavar="FILE")
79 79 parser.add_option("-R", "--repo",
80 80 help="run benchmark on REPO", metavar="REPO")
81 81
82 82 (options, args) = parser.parse_args()
83 83
84 84 if len(sys.argv) < 2:
85 85 parser.print_help()
86 86 sys.exit(255)
87 87
88 88 # the directory where both this script and the perf.py extension live.
89 89 contribdir = os.path.dirname(__file__)
90 90
91 91 target_rev = args[0]
92 92
93 93 revsetsfile = sys.stdin
94 94 if options.file:
95 95 revsetsfile = open(options.file)
96 96
97 revsets = [l.strip() for l in revsetsfile]
97 revsets = [l.strip() for l in revsetsfile if not l.startswith('#')]
98 98
99 99 print "Revsets to benchmark"
100 100 print "----------------------------"
101 101
102 102 for idx, rset in enumerate(revsets):
103 103 print "%i) %s" % (idx, rset)
104 104
105 105 print "----------------------------"
106 106 print
107 107
108 108
109 109 revs = getrevs(target_rev)
110 110
111 111 results = []
112 112 for r in revs:
113 113 print "----------------------------"
114 114 printrevision(r)
115 115 print "----------------------------"
116 116 update(r)
117 117 res = []
118 118 results.append(res)
119 119 for idx, rset in enumerate(revsets):
120 120 data = perf(rset, target=options.repo)
121 121 res.append(data)
122 122 print "%i)" % idx, data
123 123 sys.stdout.flush()
124 124 print "----------------------------"
125 125
126 126
127 127 print """
128 128
129 129 Result by revset
130 130 ================
131 131 """
132 132
133 133 print 'Revision:', revs
134 134 for idx, rev in enumerate(revs):
135 135 sys.stdout.write('%i) ' % idx)
136 136 sys.stdout.flush()
137 137 printrevision(rev)
138 138
139 139 print
140 140 print
141 141
142 142 for ridx, rset in enumerate(revsets):
143 143
144 144 print "revset #%i: %s" % (ridx, rset)
145 145 for idx, data in enumerate(results):
146 146 print '%i) %s' % (idx, data[ridx])
147 147 print
@@ -1,29 +1,30
1 1 all()
2 2 draft()
3 3 ::tip
4 4 draft() and ::tip
5 5 ::tip and draft()
6 6 0::tip
7 7 roots(0::tip)
8 8 author(lmoscovicz)
9 9 author(mpm)
10 10 author(lmoscovicz) or author(mpm)
11 11 author(mpm) or author(lmoscovicz)
12 12 tip:0
13 13 max(tip:0)
14 14 min(0:tip)
15 15 0::
16 16 min(0::)
17 # those two `roots(...)` inputs are close to what phase movement use.
17 18 roots((tip~100::) - (tip~100::tip))
19 roots((0::) - (0::tip))
18 20 ::p1(p1(tip))::
19 21 public()
20 22 :10000 and public()
21 23 draft()
22 24 :10000 and draft()
23 25 max(::(tip~20) - obsolete())
24 26 roots((0:tip)::)
25 27 (not public() - obsolete())
26 roots((0::) - (0::tip))
27 28 (_intlist('20000\x0020001')) and merge()
28 29 parents(20000)
29 30 (20000::) - (20000)
General Comments 0
You need to be logged in to leave comments. Login now