author | Gregory Szorc <gregory.szorc@gmail.com> |
Mon, 21 Feb 2022 10:40:58 -0700 | |
changeset 48902 | 1ba11c8f3430 |
parent 48875 | 6000f5b25c9b |
child 49016 | a2bd6b23881d |
permissions | -rwxr-xr-x |
46771
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python3 |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 |
# Search for interesting discovery instance |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 |
# |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 |
# search-discovery-case REPO [REPO]… |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 |
# |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 |
# This use a subsetmaker extension (next to this script) to generate a steam of |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 |
# random discovery instance. When interesting case are discovered, information |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 |
# about them are print on the stdout. |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 |
import json |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 |
import os |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 |
import queue |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 |
import random |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 |
import signal |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 |
import subprocess |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 |
import sys |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 |
import threading |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 |
this_script = os.path.abspath(sys.argv[0]) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 |
this_dir = os.path.dirname(this_script) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 |
hg_dir = os.path.join(this_dir, '..', '..') |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 |
HG_REPO = os.path.normpath(hg_dir) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 |
HG_BIN = os.path.join(HG_REPO, 'hg') |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
24 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
25 |
JOB = int(os.environ.get('NUMBER_OF_PROCESSORS', 8)) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
27 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 |
SLICING = ('scratch', 'randomantichain', 'rev') |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
30 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
31 |
def nb_revs(repo_path): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
32 |
cmd = [ |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 |
HG_BIN, |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
34 |
'--repository', |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
35 |
repo_path, |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
36 |
'log', |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
37 |
'--template', |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
38 |
'{rev}', |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
39 |
'--rev', |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
40 |
'tip', |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
41 |
] |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
42 |
s = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
43 |
out, err = s.communicate() |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
44 |
return int(out) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
45 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
46 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
47 |
repos = [] |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
48 |
for repo in sys.argv[1:]: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
49 |
size = nb_revs(repo) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
50 |
repos.append((repo, size)) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
51 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
52 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
53 |
def pick_one(repo): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
54 |
pick = random.choice(SLICING) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
55 |
seed = random.randint(0, 100000) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
56 |
if pick == 'scratch': |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
57 |
start = int(repo[1] * 0.3) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
58 |
end = int(repo[1] * 0.7) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
59 |
nb = random.randint(start, end) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
60 |
return ('scratch', nb, seed) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
61 |
elif pick == 'randomantichain': |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
62 |
return ('randomantichain', seed) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
63 |
elif pick == 'rev': |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
64 |
start = int(repo[1] * 0.3) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
65 |
end = int(repo[1]) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
66 |
rev = random.randint(start, end) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
67 |
return ('rev', rev) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
68 |
else: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
69 |
assert False |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
70 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
71 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
72 |
done = threading.Event() |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
73 |
cases = queue.Queue(maxsize=10 * JOB) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
74 |
results = queue.Queue() |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
75 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
76 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
77 |
def worker(): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
78 |
while not done.is_set(): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
79 |
c = cases.get() |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
80 |
if c is None: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
81 |
return |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
82 |
try: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
83 |
res = process(c) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
84 |
results.put((c, res)) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
85 |
except Exception as exc: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
86 |
print('processing-failed: %s %s' % (c, exc), file=sys.stderr) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
87 |
c = (c[0], c[2], c[1]) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
88 |
try: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
89 |
res = process(c) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
90 |
results.put((c, res)) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
91 |
except Exception as exc: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
92 |
print('processing-failed: %s %s' % (c, exc), file=sys.stderr) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
93 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
94 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
95 |
SUBSET_PATH = os.path.join(HG_REPO, 'contrib', 'perf-utils', 'subsetmaker.py') |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
96 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
97 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
98 |
CMD_BASE = ( |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
99 |
HG_BIN, |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
100 |
'debugdiscovery', |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
101 |
'--template', |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
102 |
'json', |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
103 |
'--config', |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
104 |
'extensions.subset=%s' % SUBSET_PATH, |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
105 |
) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
106 |
# '--local-as-revs "$left" --local-as-revs "$right"' |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
107 |
# > /data/discovery-references/results/disco-mozilla-unified-$1-$2.txt |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
108 |
# ) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
109 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
110 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
111 |
def to_revsets(case): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
112 |
t = case[0] |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
113 |
if t == 'scratch': |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
114 |
return 'not scratch(all(), %d, "%d")' % (case[1], case[2]) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
115 |
elif t == 'randomantichain': |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
116 |
return '::randomantichain(all(), "%d")' % case[1] |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
117 |
elif t == 'rev': |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
118 |
return '::%d' % case[1] |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
119 |
else: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
120 |
assert False |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
121 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
122 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
123 |
def process(case): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
124 |
(repo, left, right) = case |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
125 |
cmd = list(CMD_BASE) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
126 |
cmd.append('-R') |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
127 |
cmd.append(repo[0]) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
128 |
cmd.append('--local-as-revs') |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
129 |
cmd.append(to_revsets(left)) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
130 |
cmd.append('--remote-as-revs') |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
131 |
cmd.append(to_revsets(right)) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
132 |
s = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
133 |
out, err = s.communicate() |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
134 |
return json.loads(out)[0] |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
135 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
136 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
137 |
def interesting_boundary(res): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
138 |
"""check if a case is interesting or not |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
139 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
140 |
For now we are mostly interrested in case were we do multiple roundstrip |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
141 |
and where the boundary is somewhere in the middle of the undecided set. |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
142 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
143 |
Ideally, we would make this configurable, but this is not a focus for now |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
144 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
145 |
return None or (round-trip, undecided-common, undecided-missing) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
146 |
""" |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
147 |
roundtrips = res["total-roundtrips"] |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
148 |
if roundtrips <= 1: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
149 |
return None |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
150 |
undecided_common = res["nb-ini_und-common"] |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
151 |
undecided_missing = res["nb-ini_und-missing"] |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
152 |
if undecided_common == 0: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
153 |
return None |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
154 |
if undecided_missing == 0: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
155 |
return None |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
156 |
return (roundtrips, undecided_common, undecided_missing) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
157 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
158 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
159 |
def end(*args, **kwargs): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
160 |
done.set() |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
161 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
162 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
163 |
def format_case(case): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
164 |
return '-'.join(str(s) for s in case) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
165 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
166 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
167 |
signal.signal(signal.SIGINT, end) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
168 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
169 |
for i in range(JOB): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
170 |
threading.Thread(target=worker).start() |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
171 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
172 |
nb_cases = 0 |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
173 |
while not done.is_set(): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
174 |
repo = random.choice(repos) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
175 |
left = pick_one(repo) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
176 |
right = pick_one(repo) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
177 |
cases.put((repo, left, right)) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
178 |
while not results.empty(): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
179 |
# results has a single reader so this is fine |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
180 |
c, res = results.get_nowait() |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
181 |
boundary = interesting_boundary(res) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
182 |
if boundary is not None: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
183 |
print(c[0][0], format_case(c[1]), format_case(c[2]), *boundary) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
184 |
sys.stdout.flush() |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
185 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
186 |
nb_cases += 1 |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
187 |
if not nb_cases % 100: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
188 |
print('[%d cases generated]' % nb_cases, file=sys.stderr) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
189 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
190 |
for i in range(JOB): |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
191 |
try: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
192 |
cases.put_nowait(None) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
193 |
except queue.Full: |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
194 |
pass |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
195 |
|
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
196 |
print('[%d cases generated]' % nb_cases, file=sys.stderr) |
6b26e6432554
perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
197 |
print('[ouput generation is over]' % nb_cases, file=sys.stderr) |