Show More
@@ -0,0 +1,183 b'' | |||||
|
1 | #!/usr/bin/env python3 | |||
|
2 | # compare various algorithm variants for a given case | |||
|
3 | # | |||
|
4 | # search-discovery-case REPO LOCAL_CASE REMOTE_CASE | |||
|
5 | # | |||
|
6 | # The description for the case input uses the same format as the ouput of | |||
|
7 | # search-discovery-case | |||
|
8 | ||||
|
9 | import json | |||
|
10 | import os | |||
|
11 | import subprocess | |||
|
12 | import sys | |||
|
13 | ||||
|
14 | this_script = os.path.abspath(sys.argv[0]) | |||
|
15 | script_name = os.path.basename(this_script) | |||
|
16 | this_dir = os.path.dirname(this_script) | |||
|
17 | hg_dir = os.path.join(this_dir, '..', '..') | |||
|
18 | HG_REPO = os.path.normpath(hg_dir) | |||
|
19 | HG_BIN = os.path.join(HG_REPO, 'hg') | |||
|
20 | ||||
|
21 | ||||
|
22 | SUBSET_PATH = os.path.join(HG_REPO, 'contrib', 'perf-utils', 'subsetmaker.py') | |||
|
23 | ||||
|
24 | CMD_BASE = ( | |||
|
25 | HG_BIN, | |||
|
26 | 'debugdiscovery', | |||
|
27 | '--template', | |||
|
28 | 'json', | |||
|
29 | '--config', | |||
|
30 | 'extensions.subset=%s' % SUBSET_PATH, | |||
|
31 | ) | |||
|
32 | ||||
|
33 | # --old | |||
|
34 | # --nonheads | |||
|
35 | # | |||
|
36 | # devel.discovery.exchange-heads=True | |||
|
37 | # devel.discovery.grow-sample=True | |||
|
38 | # devel.discovery.grow-sample.dynamic=True | |||
|
39 | ||||
|
40 | VARIANTS = { | |||
|
41 | 'tree-discovery': ('--old',), | |||
|
42 | 'set-discovery-basic': ( | |||
|
43 | '--config', | |||
|
44 | 'devel.discovery.exchange-heads=no', | |||
|
45 | '--config', | |||
|
46 | 'devel.discovery.grow-sample=no', | |||
|
47 | '--config', | |||
|
48 | 'devel.discovery.grow-sample.dynamic=no', | |||
|
49 | '--config', | |||
|
50 | 'devel.discovery.randomize=yes', | |||
|
51 | ), | |||
|
52 | 'set-discovery-heads': ( | |||
|
53 | '--config', | |||
|
54 | 'devel.discovery.exchange-heads=yes', | |||
|
55 | '--config', | |||
|
56 | 'devel.discovery.grow-sample=no', | |||
|
57 | '--config', | |||
|
58 | 'devel.discovery.grow-sample.dynamic=no', | |||
|
59 | '--config', | |||
|
60 | 'devel.discovery.randomize=yes', | |||
|
61 | ), | |||
|
62 | 'set-discovery-grow-sample': ( | |||
|
63 | '--config', | |||
|
64 | 'devel.discovery.exchange-heads=yes', | |||
|
65 | '--config', | |||
|
66 | 'devel.discovery.grow-sample=yes', | |||
|
67 | '--config', | |||
|
68 | 'devel.discovery.grow-sample.dynamic=no', | |||
|
69 | '--config', | |||
|
70 | 'devel.discovery.randomize=yes', | |||
|
71 | ), | |||
|
72 | 'set-discovery-dynamic-sample': ( | |||
|
73 | '--config', | |||
|
74 | 'devel.discovery.exchange-heads=yes', | |||
|
75 | '--config', | |||
|
76 | 'devel.discovery.grow-sample=yes', | |||
|
77 | '--config', | |||
|
78 | 'devel.discovery.grow-sample.dynamic=yes', | |||
|
79 | '--config', | |||
|
80 | 'devel.discovery.randomize=yes', | |||
|
81 | ), | |||
|
82 | 'set-discovery-default': ( | |||
|
83 | '--config', | |||
|
84 | 'devel.discovery.randomize=yes', | |||
|
85 | ), | |||
|
86 | } | |||
|
87 | ||||
|
88 | VARIANTS_KEYS = [ | |||
|
89 | 'tree-discovery', | |||
|
90 | 'set-discovery-basic', | |||
|
91 | 'set-discovery-heads', | |||
|
92 | 'set-discovery-grow-sample', | |||
|
93 | 'set-discovery-dynamic-sample', | |||
|
94 | 'set-discovery-default', | |||
|
95 | ] | |||
|
96 | ||||
|
97 | assert set(VARIANTS.keys()) == set(VARIANTS_KEYS) | |||
|
98 | ||||
|
99 | ||||
|
100 | def format_case(case): | |||
|
101 | return '-'.join(str(s) for s in case) | |||
|
102 | ||||
|
103 | ||||
|
104 | def to_revsets(case): | |||
|
105 | t = case[0] | |||
|
106 | if t == 'scratch': | |||
|
107 | return 'not scratch(all(), %d, "%d")' % (case[1], case[2]) | |||
|
108 | elif t == 'randomantichain': | |||
|
109 | return '::randomantichain(all(), "%d")' % case[1] | |||
|
110 | elif t == 'rev': | |||
|
111 | return '::%d' % case[1] | |||
|
112 | else: | |||
|
113 | assert False | |||
|
114 | ||||
|
115 | ||||
|
116 | def compare(repo, local_case, remote_case): | |||
|
117 | case = (repo, local_case, remote_case) | |||
|
118 | for variant in VARIANTS_KEYS: | |||
|
119 | res = process(case, VARIANTS[variant]) | |||
|
120 | revs = res["nb-revs"] | |||
|
121 | local_heads = res["nb-head-local"] | |||
|
122 | common_heads = res["nb-common-heads"] | |||
|
123 | roundtrips = res["total-roundtrips"] | |||
|
124 | queries = res["total-queries"] | |||
|
125 | if 'tree-discovery' in variant: | |||
|
126 | print( | |||
|
127 | repo, | |||
|
128 | format_case(local_case), | |||
|
129 | format_case(remote_case), | |||
|
130 | variant, | |||
|
131 | roundtrips, | |||
|
132 | queries, | |||
|
133 | revs, | |||
|
134 | local_heads, | |||
|
135 | common_heads, | |||
|
136 | ) | |||
|
137 | else: | |||
|
138 | undecided_common = res["nb-ini_und-common"] | |||
|
139 | undecided_missing = res["nb-ini_und-missing"] | |||
|
140 | undecided = undecided_common + undecided_missing | |||
|
141 | print( | |||
|
142 | repo, | |||
|
143 | format_case(local_case), | |||
|
144 | format_case(remote_case), | |||
|
145 | variant, | |||
|
146 | roundtrips, | |||
|
147 | queries, | |||
|
148 | revs, | |||
|
149 | local_heads, | |||
|
150 | common_heads, | |||
|
151 | undecided, | |||
|
152 | undecided_common, | |||
|
153 | undecided_missing, | |||
|
154 | ) | |||
|
155 | return 0 | |||
|
156 | ||||
|
157 | ||||
|
158 | def process(case, variant): | |||
|
159 | (repo, left, right) = case | |||
|
160 | cmd = list(CMD_BASE) | |||
|
161 | cmd.append('-R') | |||
|
162 | cmd.append(repo) | |||
|
163 | cmd.append('--local-as-revs') | |||
|
164 | cmd.append(to_revsets(left)) | |||
|
165 | cmd.append('--remote-as-revs') | |||
|
166 | cmd.append(to_revsets(right)) | |||
|
167 | cmd.extend(variant) | |||
|
168 | s = subprocess.Popen(cmd, stdout=subprocess.PIPE) | |||
|
169 | out, err = s.communicate() | |||
|
170 | return json.loads(out)[0] | |||
|
171 | ||||
|
172 | ||||
|
173 | if __name__ == '__main__': | |||
|
174 | if len(sys.argv) != 4: | |||
|
175 | usage = f'USAGE: {script_name} REPO LOCAL_CASE REMOTE_CASE' | |||
|
176 | print(usage, file=sys.stderr) | |||
|
177 | sys.exit(128) | |||
|
178 | repo = sys.argv[1] | |||
|
179 | local_case = sys.argv[2].split('-') | |||
|
180 | local_case = (local_case[0],) + tuple(int(x) for x in local_case[1:]) | |||
|
181 | remote_case = sys.argv[3].split('-') | |||
|
182 | remote_case = (remote_case[0],) + tuple(int(x) for x in remote_case[1:]) | |||
|
183 | sys.exit(compare(repo, local_case, remote_case)) |
General Comments 0
You need to be logged in to leave comments.
Login now