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