contrib/perf-utils/search-discovery-case
author Pierre-Yves DAVID <pierre-yves.david@octobus.net>
Sun, 05 Jun 2022 07:16:29 +0200
changeset 49463 5acbc550d987
parent 49271 87a3f43b9dc2
permissions -rwxr-xr-x
compare-disco: support for `file` nodes specification This leverage the `nodefromfile` feature in core. This make it possible for callers to no longer pay the subset computation cost (and to make sure the subset is the right one, even when the base repository is different)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
49271
87a3f43b9dc2 search-discovery-case: update documentation of a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49016
diff changeset
   145
    return None or (
87a3f43b9dc2 search-discovery-case: update documentation of a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49016
diff changeset
   146
        round-trip,
87a3f43b9dc2 search-discovery-case: update documentation of a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49016
diff changeset
   147
        undecided-common,
87a3f43b9dc2 search-discovery-case: update documentation of a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49016
diff changeset
   148
        undecided-missing,
87a3f43b9dc2 search-discovery-case: update documentation of a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49016
diff changeset
   149
        total-revs,
87a3f43b9dc2 search-discovery-case: update documentation of a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49016
diff changeset
   150
        common-revs,
87a3f43b9dc2 search-discovery-case: update documentation of a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49016
diff changeset
   151
        missing-revs,
87a3f43b9dc2 search-discovery-case: update documentation of a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49016
diff changeset
   152
    )
46771
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   153
    """
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   154
    roundtrips = res["total-roundtrips"]
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   155
    if roundtrips <= 1:
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   156
        return None
49016
a2bd6b23881d search-discovery-case: display more information about the interresting case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
   157
    total_revs = res["nb-revs"]
a2bd6b23881d search-discovery-case: display more information about the interresting case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
   158
    common_revs = res["nb-revs-common"]
a2bd6b23881d search-discovery-case: display more information about the interresting case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
   159
    missing_revs = res["nb-revs-missing"]
46771
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   160
    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
   161
    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
   162
    if undecided_common == 0:
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   163
        return None
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   164
    if undecided_missing == 0:
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   165
        return None
49016
a2bd6b23881d search-discovery-case: display more information about the interresting case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
   166
    return (
a2bd6b23881d search-discovery-case: display more information about the interresting case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
   167
        roundtrips,
a2bd6b23881d search-discovery-case: display more information about the interresting case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
   168
        undecided_common,
a2bd6b23881d search-discovery-case: display more information about the interresting case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
   169
        undecided_missing,
a2bd6b23881d search-discovery-case: display more information about the interresting case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
   170
        total_revs,
a2bd6b23881d search-discovery-case: display more information about the interresting case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
   171
        common_revs,
a2bd6b23881d search-discovery-case: display more information about the interresting case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
   172
        missing_revs,
a2bd6b23881d search-discovery-case: display more information about the interresting case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48875
diff changeset
   173
    )
46771
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   174
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   175
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   176
def end(*args, **kwargs):
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   177
    done.set()
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   178
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   179
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   180
def format_case(case):
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   181
    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
   182
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   183
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   184
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
   185
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   186
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
   187
    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
   188
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   189
nb_cases = 0
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   190
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
   191
    repo = random.choice(repos)
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   192
    left = pick_one(repo)
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   193
    right = pick_one(repo)
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   194
    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
   195
    while not results.empty():
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   196
        # 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
   197
        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
   198
        boundary = interesting_boundary(res)
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   199
        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
   200
            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
   201
            sys.stdout.flush()
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   202
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   203
    nb_cases += 1
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   204
    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
   205
        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
   206
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   207
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
   208
    try:
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   209
        cases.put_nowait(None)
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   210
    except queue.Full:
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   211
        pass
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   212
6b26e6432554 perf-helpers: add a search-discovery-case script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   213
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
   214
print('[ouput generation is over]' % nb_cases, file=sys.stderr)