| 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 parse_case(case): |
| 101 |
case_type, case_args = case.split('-', 1) |
| 102 |
if case_type == 'file': |
| 103 |
case_args = (case_args,) |
| 104 |
else: |
| 105 |
case_args = tuple(int(x) for x in case_args.split('-')) |
| 106 |
case = (case_type,) + case_args |
| 107 |
return case |
| 108 |
|
| 109 |
|
| 110 |
def format_case(case): |
| 111 |
return '-'.join(str(s) for s in case) |
| 112 |
|
| 113 |
|
| 114 |
def to_revsets(case): |
| 115 |
t = case[0] |
| 116 |
if t == 'scratch': |
| 117 |
return 'not scratch(all(), %d, "%d")' % (case[1], case[2]) |
| 118 |
elif t == 'randomantichain': |
| 119 |
return '::randomantichain(all(), "%d")' % case[1] |
| 120 |
elif t == 'rev': |
| 121 |
return '::%d' % case[1] |
| 122 |
elif t == 'file': |
| 123 |
return '::nodefromfile("%s")' % case[1] |
| 124 |
else: |
| 125 |
assert False |
| 126 |
|
| 127 |
|
| 128 |
def compare( |
| 129 |
repo, |
| 130 |
local_case, |
| 131 |
remote_case, |
| 132 |
display_header=True, |
| 133 |
display_case=True, |
| 134 |
): |
| 135 |
case = (repo, local_case, remote_case) |
| 136 |
if display_header: |
| 137 |
pieces = ['#'] |
| 138 |
if display_case: |
| 139 |
pieces += [ |
| 140 |
"repo", |
| 141 |
"local-subset", |
| 142 |
"remote-subset", |
| 143 |
] |
| 144 |
|
| 145 |
pieces += [ |
| 146 |
"discovery-variant", |
| 147 |
"roundtrips", |
| 148 |
"queries", |
| 149 |
"revs", |
| 150 |
"local-heads", |
| 151 |
"common-heads", |
| 152 |
"undecided-initial", |
| 153 |
"undecided-common", |
| 154 |
"undecided-missing", |
| 155 |
] |
| 156 |
print(*pieces) |
| 157 |
for variant in VARIANTS_KEYS: |
| 158 |
res = process(case, VARIANTS[variant]) |
| 159 |
revs = res["nb-revs"] |
| 160 |
local_heads = res["nb-head-local"] |
| 161 |
common_heads = res["nb-common-heads"] |
| 162 |
roundtrips = res["total-roundtrips"] |
| 163 |
queries = res["total-queries"] |
| 164 |
pieces = [] |
| 165 |
if display_case: |
| 166 |
pieces += [ |
| 167 |
repo, |
| 168 |
format_case(local_case), |
| 169 |
format_case(remote_case), |
| 170 |
] |
| 171 |
pieces += [ |
| 172 |
variant, |
| 173 |
roundtrips, |
| 174 |
queries, |
| 175 |
revs, |
| 176 |
local_heads, |
| 177 |
common_heads, |
| 178 |
] |
| 179 |
if 'tree-discovery' not in variant: |
| 180 |
undecided_common = res["nb-ini_und-common"] |
| 181 |
undecided_missing = res["nb-ini_und-missing"] |
| 182 |
undecided = undecided_common + undecided_missing |
| 183 |
pieces += [ |
| 184 |
undecided, |
| 185 |
undecided_common, |
| 186 |
undecided_missing, |
| 187 |
] |
| 188 |
print(*pieces) |
| 189 |
return 0 |
| 190 |
|
| 191 |
|
| 192 |
def process(case, variant): |
| 193 |
(repo, left, right) = case |
| 194 |
cmd = list(CMD_BASE) |
| 195 |
cmd.append('-R') |
| 196 |
cmd.append(repo) |
| 197 |
cmd.append('--local-as-revs') |
| 198 |
cmd.append(to_revsets(left)) |
| 199 |
cmd.append('--remote-as-revs') |
| 200 |
cmd.append(to_revsets(right)) |
| 201 |
cmd.extend(variant) |
| 202 |
s = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
| 203 |
out, err = s.communicate() |
| 204 |
return json.loads(out)[0] |
| 205 |
|
| 206 |
|
| 207 |
if __name__ == '__main__': |
| 208 |
argv = sys.argv[:] |
| 209 |
|
| 210 |
kwargs = {} |
| 211 |
# primitive arg parsing |
| 212 |
if '--no-header' in argv: |
| 213 |
kwargs['display_header'] = False |
| 214 |
argv = [a for a in argv if a != '--no-header'] |
| 215 |
if '--no-case' in argv: |
| 216 |
kwargs['display_case'] = False |
| 217 |
argv = [a for a in argv if a != '--no-case'] |
| 218 |
|
| 219 |
if len(argv) != 4: |
| 220 |
usage = f'USAGE: {script_name} REPO LOCAL_CASE REMOTE_CASE' |
| 221 |
print(usage, file=sys.stderr) |
| 222 |
sys.exit(128) |
| 223 |
repo = argv[1] |
| 224 |
local_case = parse_case(argv[2]) |
| 225 |
remote_case = parse_case(argv[3]) |
| 226 |
sys.exit(compare(repo, local_case, remote_case, **kwargs)) |