author | Pierre-Yves David <pierre-yves.david@fb.com> |
Tue, 09 Jun 2015 18:53:04 -0700 | |
changeset 25538 | caff256205ea |
parent 25537 | c1e24e1fd45f |
child 25539 | 460922c95643 |
permissions | -rwxr-xr-x |
20848
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
1 |
#!/usr/bin/env python |
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
2 |
|
20746
47fc466825da
contrib: have the revset benchmark test script take a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20745
diff
changeset
|
3 |
# Measure the performance of a list of revsets against multiple revisions |
47fc466825da
contrib: have the revset benchmark test script take a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20745
diff
changeset
|
4 |
# defined by parameter. Checkout one by one and run perfrevset with every |
47fc466825da
contrib: have the revset benchmark test script take a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20745
diff
changeset
|
5 |
# revset in the list to benchmark its performance. |
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
6 |
# |
25535
6d1e456645c9
revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25534
diff
changeset
|
7 |
# You should run this from the root of your mercurial repository. |
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
8 |
# |
25535
6d1e456645c9
revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25534
diff
changeset
|
9 |
# call with --help for details |
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
10 |
|
20848
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
11 |
import sys |
21548
651d7548a744
revsetbenchmark: automatically finds the perf extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21287
diff
changeset
|
12 |
import os |
25530
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
13 |
import re |
20893
b5de9dde181c
revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents:
20855
diff
changeset
|
14 |
from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE |
21287
2d93b74335a2
revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21286
diff
changeset
|
15 |
# cannot use argparse, python 2.7 only |
2d93b74335a2
revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21286
diff
changeset
|
16 |
from optparse import OptionParser |
2d93b74335a2
revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21286
diff
changeset
|
17 |
|
20893
b5de9dde181c
revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents:
20855
diff
changeset
|
18 |
def check_output(*args, **kwargs): |
b5de9dde181c
revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents:
20855
diff
changeset
|
19 |
kwargs.setdefault('stderr', PIPE) |
b5de9dde181c
revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents:
20855
diff
changeset
|
20 |
kwargs.setdefault('stdout', PIPE) |
b5de9dde181c
revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents:
20855
diff
changeset
|
21 |
proc = Popen(*args, **kwargs) |
b5de9dde181c
revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents:
20855
diff
changeset
|
22 |
output, error = proc.communicate() |
b5de9dde181c
revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents:
20855
diff
changeset
|
23 |
if proc.returncode != 0: |
21202
c04e5e937139
revsetbenchmark: fix error raising
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20893
diff
changeset
|
24 |
raise CalledProcessError(proc.returncode, ' '.join(args[0])) |
20893
b5de9dde181c
revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents:
20855
diff
changeset
|
25 |
return output |
20848
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
26 |
|
20850
d0c2535c7aba
revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20849
diff
changeset
|
27 |
def update(rev): |
d0c2535c7aba
revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20849
diff
changeset
|
28 |
"""update the repo to a revision""" |
d0c2535c7aba
revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20849
diff
changeset
|
29 |
try: |
d0c2535c7aba
revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20849
diff
changeset
|
30 |
check_call(['hg', 'update', '--quiet', '--check', str(rev)]) |
d0c2535c7aba
revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20849
diff
changeset
|
31 |
except CalledProcessError, exc: |
d0c2535c7aba
revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20849
diff
changeset
|
32 |
print >> sys.stderr, 'update to revision %s failed, aborting' % rev |
d0c2535c7aba
revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20849
diff
changeset
|
33 |
sys.exit(exc.returncode) |
d0c2535c7aba
revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20849
diff
changeset
|
34 |
|
25528
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
35 |
|
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
36 |
def hg(cmd, repo=None): |
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
37 |
"""run a mercurial command |
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
38 |
|
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
39 |
<cmd> is the list of command + argument, |
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
40 |
<repo> is an optional repository path to run this command in.""" |
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
41 |
fullcmd = ['./hg'] |
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
42 |
if repo is not None: |
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
43 |
fullcmd += ['-R', repo] |
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
44 |
fullcmd += ['--config', |
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
45 |
'extensions.perf=' + os.path.join(contribdir, 'perf.py')] |
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
46 |
fullcmd += cmd |
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
47 |
return check_output(fullcmd, stderr=STDOUT) |
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
48 |
|
21549
ea3d75ebea6d
revsetbenchmark: support for running on other repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21548
diff
changeset
|
49 |
def perf(revset, target=None): |
20851
4130ec938c84
revsetbenchmark: convert performance call to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20850
diff
changeset
|
50 |
"""run benchmark for this very revset""" |
4130ec938c84
revsetbenchmark: convert performance call to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20850
diff
changeset
|
51 |
try: |
25528
a6bcd70cd9c2
revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23139
diff
changeset
|
52 |
output = hg(['perfrevset', revset], repo=target) |
25530
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
53 |
return parseoutput(output) |
20851
4130ec938c84
revsetbenchmark: convert performance call to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20850
diff
changeset
|
54 |
except CalledProcessError, exc: |
25529
3e80691d0dfe
revsetbenchmarks: improve error output in case of failure
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25528
diff
changeset
|
55 |
print >> sys.stderr, 'abort: cannot run revset benchmark: %s' % exc.cmd |
3e80691d0dfe
revsetbenchmarks: improve error output in case of failure
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25528
diff
changeset
|
56 |
if exc.output is None: |
3e80691d0dfe
revsetbenchmarks: improve error output in case of failure
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25528
diff
changeset
|
57 |
print >> sys.stderr, '(no ouput)' |
3e80691d0dfe
revsetbenchmarks: improve error output in case of failure
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25528
diff
changeset
|
58 |
else: |
3e80691d0dfe
revsetbenchmarks: improve error output in case of failure
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25528
diff
changeset
|
59 |
print >> sys.stderr, exc.output |
20851
4130ec938c84
revsetbenchmark: convert performance call to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20850
diff
changeset
|
60 |
sys.exit(exc.returncode) |
4130ec938c84
revsetbenchmark: convert performance call to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20850
diff
changeset
|
61 |
|
25530
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
62 |
outputre = re.compile(r'! wall (\d+.\d+) comb (\d+.\d+) user (\d+.\d+) ' |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
63 |
'sys (\d+.\d+) \(best of (\d+)\)') |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
64 |
|
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
65 |
def parseoutput(output): |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
66 |
"""parse a textual output into a dict |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
67 |
|
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
68 |
We cannot just use json because we want to compare with old |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
69 |
versions of Mercurial that may not support json output. |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
70 |
""" |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
71 |
match = outputre.search(output) |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
72 |
if not match: |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
73 |
print >> sys.stderr, 'abort: invalid output:' |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
74 |
print >> sys.stderr, output |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
75 |
sys.exit(1) |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
76 |
return {'comb': float(match.group(2)), |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
77 |
'count': int(match.group(5)), |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
78 |
'sys': float(match.group(3)), |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
79 |
'user': float(match.group(4)), |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
80 |
'wall': float(match.group(1)), |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
81 |
} |
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
82 |
|
20852
b2353501d6dc
revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20851
diff
changeset
|
83 |
def printrevision(rev): |
b2353501d6dc
revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20851
diff
changeset
|
84 |
"""print data about a revision""" |
25538
caff256205ea
revsetbenchmarks: improve revision printing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25537
diff
changeset
|
85 |
sys.stdout.write("Revision ") |
20852
b2353501d6dc
revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20851
diff
changeset
|
86 |
sys.stdout.flush() |
b2353501d6dc
revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20851
diff
changeset
|
87 |
check_call(['hg', 'log', '--rev', str(rev), '--template', |
25538
caff256205ea
revsetbenchmarks: improve revision printing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25537
diff
changeset
|
88 |
'{rev}:{node|short}: {desc|firstline}\n']) |
20852
b2353501d6dc
revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20851
diff
changeset
|
89 |
|
25532
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
90 |
def idxwidth(nbidx): |
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
91 |
"""return the max width of number used for index |
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
92 |
|
25533
4bdf6f58aee1
revsetbenchmarks: clarify comment based on irc discussion
Augie Fackler <augie@google.com>
parents:
25532
diff
changeset
|
93 |
This is similar to log10(nbidx), but we use custom code here |
4bdf6f58aee1
revsetbenchmarks: clarify comment based on irc discussion
Augie Fackler <augie@google.com>
parents:
25532
diff
changeset
|
94 |
because we start with zero and we'd rather not deal with all the |
4bdf6f58aee1
revsetbenchmarks: clarify comment based on irc discussion
Augie Fackler <augie@google.com>
parents:
25532
diff
changeset
|
95 |
extra rounding business that log10 would imply. |
4bdf6f58aee1
revsetbenchmarks: clarify comment based on irc discussion
Augie Fackler <augie@google.com>
parents:
25532
diff
changeset
|
96 |
""" |
25532
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
97 |
nbidx -= 1 # starts at 0 |
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
98 |
idxwidth = 0 |
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
99 |
while nbidx: |
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
100 |
idxwidth += 1 |
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
101 |
nbidx //= 10 |
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
102 |
if not idxwidth: |
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
103 |
idxwidth = 1 |
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
104 |
return idxwidth |
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
105 |
|
25537
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
106 |
def printresult(idx, data, maxidx, verbose=False): |
25531
371d8afc9144
revsetbenchmarks: factor out result output into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25530
diff
changeset
|
107 |
"""print a line of result to stdout""" |
25532
1311aee85dcf
revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25531
diff
changeset
|
108 |
mask = '%%0%ii) %%s' % idxwidth(maxidx) |
25537
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
109 |
out = ['%10.6f' % data['wall']] |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
110 |
if verbose: |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
111 |
out.append('%10.6f' % data['comb']) |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
112 |
out.append('%10.6f' % data['user']) |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
113 |
out.append('%10.6f' % data['sys']) |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
114 |
out.append('%6d' % data['count']) |
25534
43e5a6819aba
revsetbenchmarks: use a more compact output format with a header
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25533
diff
changeset
|
115 |
print mask % (idx, ' '.join(out)) |
25530
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
116 |
|
25537
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
117 |
def printheader(maxidx, verbose=False): |
25534
43e5a6819aba
revsetbenchmarks: use a more compact output format with a header
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25533
diff
changeset
|
118 |
header = [' ' * (idxwidth(maxidx) + 1), |
25537
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
119 |
' %-8s' % 'time'] |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
120 |
if verbose: |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
121 |
header.append(' %-8s' % 'comb') |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
122 |
header.append(' %-8s' % 'user') |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
123 |
header.append(' %-8s' % 'sys') |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
124 |
header.append('%6s' % 'count') |
25534
43e5a6819aba
revsetbenchmarks: use a more compact output format with a header
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25533
diff
changeset
|
125 |
print ' '.join(header) |
25530
94efef10b63f
revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25529
diff
changeset
|
126 |
|
20853
95293cf67871
revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20852
diff
changeset
|
127 |
def getrevs(spec): |
95293cf67871
revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20852
diff
changeset
|
128 |
"""get the list of rev matched by a revset""" |
95293cf67871
revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20852
diff
changeset
|
129 |
try: |
95293cf67871
revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20852
diff
changeset
|
130 |
out = check_output(['hg', 'log', '--template={rev}\n', '--rev', spec]) |
95293cf67871
revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20852
diff
changeset
|
131 |
except CalledProcessError, exc: |
95293cf67871
revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20852
diff
changeset
|
132 |
print >> sys.stderr, "abort, can't get revision from %s" % spec |
95293cf67871
revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20852
diff
changeset
|
133 |
sys.exit(exc.returncode) |
95293cf67871
revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20852
diff
changeset
|
134 |
return [r for r in out.split() if r] |
95293cf67871
revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20852
diff
changeset
|
135 |
|
95293cf67871
revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20852
diff
changeset
|
136 |
|
21287
2d93b74335a2
revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21286
diff
changeset
|
137 |
parser = OptionParser(usage="usage: %prog [options] <revs>") |
2d93b74335a2
revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21286
diff
changeset
|
138 |
parser.add_option("-f", "--file", |
23139
e53f6b72a0e4
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
22556
diff
changeset
|
139 |
help="read revset from FILE (stdin if omitted)", |
22555
2143d794e960
revsetbenchmark: make it clear that revsets may be read from stdin
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22059
diff
changeset
|
140 |
metavar="FILE") |
21549
ea3d75ebea6d
revsetbenchmark: support for running on other repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21548
diff
changeset
|
141 |
parser.add_option("-R", "--repo", |
ea3d75ebea6d
revsetbenchmark: support for running on other repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21548
diff
changeset
|
142 |
help="run benchmark on REPO", metavar="REPO") |
21287
2d93b74335a2
revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21286
diff
changeset
|
143 |
|
25537
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
144 |
parser.add_option("-v", "--verbose", |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
145 |
action='store_true', |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
146 |
help="display all timing data (not just best total time)") |
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
147 |
|
21287
2d93b74335a2
revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21286
diff
changeset
|
148 |
(options, args) = parser.parse_args() |
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
149 |
|
25535
6d1e456645c9
revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25534
diff
changeset
|
150 |
if not args: |
21287
2d93b74335a2
revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21286
diff
changeset
|
151 |
parser.print_help() |
21286
f0f810096842
revsetbenchmark: add a usage message when no arguments are passed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21202
diff
changeset
|
152 |
sys.exit(255) |
f0f810096842
revsetbenchmark: add a usage message when no arguments are passed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21202
diff
changeset
|
153 |
|
21548
651d7548a744
revsetbenchmark: automatically finds the perf extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21287
diff
changeset
|
154 |
# the directory where both this script and the perf.py extension live. |
651d7548a744
revsetbenchmark: automatically finds the perf extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21287
diff
changeset
|
155 |
contribdir = os.path.dirname(__file__) |
21287
2d93b74335a2
revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21286
diff
changeset
|
156 |
|
20848
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
157 |
revsetsfile = sys.stdin |
21287
2d93b74335a2
revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21286
diff
changeset
|
158 |
if options.file: |
2d93b74335a2
revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21286
diff
changeset
|
159 |
revsetsfile = open(options.file) |
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
160 |
|
22556
480a24ad9f77
revsetbenchmark: allow comments ('#' prefix) in the revset input
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22555
diff
changeset
|
161 |
revsets = [l.strip() for l in revsetsfile if not l.startswith('#')] |
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
162 |
|
20848
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
163 |
print "Revsets to benchmark" |
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
164 |
print "----------------------------" |
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
165 |
|
20848
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
166 |
for idx, rset in enumerate(revsets): |
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
167 |
print "%i) %s" % (idx, rset) |
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
168 |
|
20848
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
169 |
print "----------------------------" |
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
170 |
|
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
171 |
|
25535
6d1e456645c9
revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25534
diff
changeset
|
172 |
revs = [] |
6d1e456645c9
revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25534
diff
changeset
|
173 |
for a in args: |
6d1e456645c9
revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25534
diff
changeset
|
174 |
revs.extend(getrevs(a)) |
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
175 |
|
20855
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
176 |
results = [] |
20848
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
177 |
for r in revs: |
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
178 |
print "----------------------------" |
20852
b2353501d6dc
revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20851
diff
changeset
|
179 |
printrevision(r) |
20848
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
180 |
print "----------------------------" |
20850
d0c2535c7aba
revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20849
diff
changeset
|
181 |
update(r) |
20855
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
182 |
res = [] |
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
183 |
results.append(res) |
25537
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
184 |
printheader(len(revsets), verbose=options.verbose) |
20848
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
185 |
for idx, rset in enumerate(revsets): |
21549
ea3d75ebea6d
revsetbenchmark: support for running on other repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21548
diff
changeset
|
186 |
data = perf(rset, target=options.repo) |
20855
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
187 |
res.append(data) |
25537
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
188 |
printresult(idx, data, len(revsets), verbose=options.verbose) |
20855
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
189 |
sys.stdout.flush() |
20848
11a9393609c8
revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20847
diff
changeset
|
190 |
print "----------------------------" |
20745
5fb7c36d751f
contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff
changeset
|
191 |
|
20855
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
192 |
|
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
193 |
print """ |
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
194 |
|
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
195 |
Result by revset |
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
196 |
================ |
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
197 |
""" |
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
198 |
|
25538
caff256205ea
revsetbenchmarks: improve revision printing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25537
diff
changeset
|
199 |
print 'Revision:' |
20855
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
200 |
for idx, rev in enumerate(revs): |
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
201 |
sys.stdout.write('%i) ' % idx) |
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
202 |
sys.stdout.flush() |
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
203 |
printrevision(rev) |
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
204 |
|
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
205 |
|
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
206 |
|
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
207 |
|
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
208 |
for ridx, rset in enumerate(revsets): |
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
209 |
|
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
210 |
print "revset #%i: %s" % (ridx, rset) |
25537
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
211 |
printheader(len(results), verbose=options.verbose) |
20855
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
212 |
for idx, data in enumerate(results): |
25537
c1e24e1fd45f
revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25536
diff
changeset
|
213 |
printresult(idx, data[ridx], len(results), verbose=options.verbose) |
20855
dfad9bb23ab4
revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20854
diff
changeset
|
214 |