contrib/perf-utils/compare-discovery-case
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 02 Mar 2023 14:44:33 +0100
changeset 50259 a44e489940e0
parent 49463 5acbc550d987
child 51690 493034cc3265
permissions -rwxr-xr-x
branch: pass current transaction when writing branch in rebase
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49018
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     1
#!/usr/bin/env python3
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     2
# compare various algorithm variants for a given case
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     3
#
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     4
#  search-discovery-case REPO LOCAL_CASE REMOTE_CASE
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     5
#
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     6
# The description for the case input uses the same format as the ouput of
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     7
# search-discovery-case
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     9
import json
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    10
import os
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    11
import subprocess
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
import sys
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    13
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    14
this_script = os.path.abspath(sys.argv[0])
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    15
script_name = os.path.basename(this_script)
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    16
this_dir = os.path.dirname(this_script)
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    17
hg_dir = os.path.join(this_dir, '..', '..')
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    18
HG_REPO = os.path.normpath(hg_dir)
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    19
HG_BIN = os.path.join(HG_REPO, 'hg')
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    20
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    21
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    22
SUBSET_PATH = os.path.join(HG_REPO, 'contrib', 'perf-utils', 'subsetmaker.py')
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    23
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    24
CMD_BASE = (
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    25
    HG_BIN,
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    26
    'debugdiscovery',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    27
    '--template',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    28
    'json',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    29
    '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    30
    'extensions.subset=%s' % SUBSET_PATH,
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    31
)
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    32
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    33
# --old
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    34
# --nonheads
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    35
#
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    36
# devel.discovery.exchange-heads=True
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    37
# devel.discovery.grow-sample=True
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    38
# devel.discovery.grow-sample.dynamic=True
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    39
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    40
VARIANTS = {
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    41
    'tree-discovery': ('--old',),
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    42
    'set-discovery-basic': (
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    43
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    44
        'devel.discovery.exchange-heads=no',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    45
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    46
        'devel.discovery.grow-sample=no',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    47
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    48
        'devel.discovery.grow-sample.dynamic=no',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    49
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    50
        'devel.discovery.randomize=yes',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    51
    ),
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    52
    'set-discovery-heads': (
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    53
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    54
        'devel.discovery.exchange-heads=yes',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    55
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    56
        'devel.discovery.grow-sample=no',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    57
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    58
        'devel.discovery.grow-sample.dynamic=no',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    59
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    60
        'devel.discovery.randomize=yes',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    61
    ),
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    62
    'set-discovery-grow-sample': (
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    63
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    64
        'devel.discovery.exchange-heads=yes',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    65
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    66
        'devel.discovery.grow-sample=yes',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    67
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    68
        'devel.discovery.grow-sample.dynamic=no',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    69
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    70
        'devel.discovery.randomize=yes',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    71
    ),
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    72
    'set-discovery-dynamic-sample': (
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    73
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    74
        'devel.discovery.exchange-heads=yes',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    75
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    76
        'devel.discovery.grow-sample=yes',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    77
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    78
        'devel.discovery.grow-sample.dynamic=yes',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    79
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    80
        'devel.discovery.randomize=yes',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    81
    ),
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    82
    'set-discovery-default': (
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    83
        '--config',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    84
        'devel.discovery.randomize=yes',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    85
    ),
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    86
}
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    87
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    88
VARIANTS_KEYS = [
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    89
    'tree-discovery',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    90
    'set-discovery-basic',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    91
    'set-discovery-heads',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    92
    'set-discovery-grow-sample',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    93
    'set-discovery-dynamic-sample',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    94
    'set-discovery-default',
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    95
]
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    96
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    97
assert set(VARIANTS.keys()) == set(VARIANTS_KEYS)
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    98
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    99
49462
ef0b0f94d2e5 compare-disco: move case parsing into its own function
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49461
diff changeset
   100
def parse_case(case):
ef0b0f94d2e5 compare-disco: move case parsing into its own function
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49461
diff changeset
   101
    case_type, case_args = case.split('-', 1)
49463
5acbc550d987 compare-disco: support for `file` nodes specification
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49462
diff changeset
   102
    if case_type == 'file':
5acbc550d987 compare-disco: support for `file` nodes specification
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49462
diff changeset
   103
        case_args = (case_args,)
5acbc550d987 compare-disco: support for `file` nodes specification
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49462
diff changeset
   104
    else:
5acbc550d987 compare-disco: support for `file` nodes specification
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49462
diff changeset
   105
        case_args = tuple(int(x) for x in case_args.split('-'))
5acbc550d987 compare-disco: support for `file` nodes specification
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49462
diff changeset
   106
    case = (case_type,) + case_args
49462
ef0b0f94d2e5 compare-disco: move case parsing into its own function
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49461
diff changeset
   107
    return case
ef0b0f94d2e5 compare-disco: move case parsing into its own function
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49461
diff changeset
   108
ef0b0f94d2e5 compare-disco: move case parsing into its own function
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49461
diff changeset
   109
49018
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   110
def format_case(case):
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   111
    return '-'.join(str(s) for s in case)
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   112
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   113
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   114
def to_revsets(case):
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   115
    t = case[0]
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   116
    if t == 'scratch':
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   117
        return 'not scratch(all(), %d, "%d")' % (case[1], case[2])
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   118
    elif t == 'randomantichain':
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   119
        return '::randomantichain(all(), "%d")' % case[1]
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   120
    elif t == 'rev':
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   121
        return '::%d' % case[1]
49463
5acbc550d987 compare-disco: support for `file` nodes specification
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49462
diff changeset
   122
    elif t == 'file':
5acbc550d987 compare-disco: support for `file` nodes specification
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49462
diff changeset
   123
        return '::nodefromfile("%s")' % case[1]
49018
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   124
    else:
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   125
        assert False
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   126
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   127
49460
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   128
def compare(
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   129
    repo,
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   130
    local_case,
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   131
    remote_case,
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   132
    display_header=True,
49461
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   133
    display_case=True,
49460
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   134
):
49018
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   135
    case = (repo, local_case, remote_case)
49460
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   136
    if display_header:
49461
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   137
        pieces = ['#']
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   138
        if display_case:
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   139
            pieces += [
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   140
                "repo",
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   141
                "local-subset",
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   142
                "remote-subset",
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   143
            ]
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   144
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   145
        pieces += [
49460
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   146
            "discovery-variant",
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   147
            "roundtrips",
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   148
            "queries",
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   149
            "revs",
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   150
            "local-heads",
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   151
            "common-heads",
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   152
            "undecided-initial",
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   153
            "undecided-common",
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   154
            "undecided-missing",
49461
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   155
        ]
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   156
        print(*pieces)
49018
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   157
    for variant in VARIANTS_KEYS:
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   158
        res = process(case, VARIANTS[variant])
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   159
        revs = res["nb-revs"]
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   160
        local_heads = res["nb-head-local"]
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   161
        common_heads = res["nb-common-heads"]
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   162
        roundtrips = res["total-roundtrips"]
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   163
        queries = res["total-queries"]
49461
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   164
        pieces = []
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   165
        if display_case:
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   166
            pieces += [
49018
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   167
                repo,
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   168
                format_case(local_case),
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   169
                format_case(remote_case),
49461
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   170
            ]
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   171
        pieces += [
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   172
            variant,
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   173
            roundtrips,
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   174
            queries,
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   175
            revs,
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   176
            local_heads,
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   177
            common_heads,
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   178
        ]
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   179
        if 'tree-discovery' not in variant:
49018
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   180
            undecided_common = res["nb-ini_und-common"]
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   181
            undecided_missing = res["nb-ini_und-missing"]
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   182
            undecided = undecided_common + undecided_missing
49461
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   183
            pieces += [
49018
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   184
                undecided,
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   185
                undecided_common,
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   186
                undecided_missing,
49461
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   187
            ]
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   188
        print(*pieces)
49018
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   189
    return 0
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   190
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   191
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   192
def process(case, variant):
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   193
    (repo, left, right) = case
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   194
    cmd = list(CMD_BASE)
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   195
    cmd.append('-R')
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   196
    cmd.append(repo)
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   197
    cmd.append('--local-as-revs')
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   198
    cmd.append(to_revsets(left))
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   199
    cmd.append('--remote-as-revs')
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   200
    cmd.append(to_revsets(right))
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   201
    cmd.extend(variant)
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   202
    s = subprocess.Popen(cmd, stdout=subprocess.PIPE)
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   203
    out, err = s.communicate()
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   204
    return json.loads(out)[0]
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   205
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   206
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   207
if __name__ == '__main__':
49459
df1d4e442c08 compare-disco: prepare for primitive argument parsing
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49018
diff changeset
   208
df1d4e442c08 compare-disco: prepare for primitive argument parsing
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49018
diff changeset
   209
    argv = sys.argv[:]
df1d4e442c08 compare-disco: prepare for primitive argument parsing
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49018
diff changeset
   210
df1d4e442c08 compare-disco: prepare for primitive argument parsing
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49018
diff changeset
   211
    kwargs = {}
49460
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   212
    # primitive arg parsing
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   213
    if '--no-header' in argv:
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   214
        kwargs['display_header'] = False
3c026138f234 compare-disco: display a header by default
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49459
diff changeset
   215
        argv = [a for a in argv if a != '--no-header']
49461
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   216
    if '--no-case' in argv:
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   217
        kwargs['display_case'] = False
ebbaf6a77807 compare-disco: add an option to skip the case
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49460
diff changeset
   218
        argv = [a for a in argv if a != '--no-case']
49459
df1d4e442c08 compare-disco: prepare for primitive argument parsing
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49018
diff changeset
   219
df1d4e442c08 compare-disco: prepare for primitive argument parsing
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49018
diff changeset
   220
    if len(argv) != 4:
49018
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   221
        usage = f'USAGE: {script_name} REPO LOCAL_CASE REMOTE_CASE'
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   222
        print(usage, file=sys.stderr)
a78c45a22ce4 perf-util: add a `compare-discovery-case` script
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   223
        sys.exit(128)
49459
df1d4e442c08 compare-disco: prepare for primitive argument parsing
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49018
diff changeset
   224
    repo = argv[1]
49462
ef0b0f94d2e5 compare-disco: move case parsing into its own function
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49461
diff changeset
   225
    local_case = parse_case(argv[2])
ef0b0f94d2e5 compare-disco: move case parsing into its own function
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49461
diff changeset
   226
    remote_case = parse_case(argv[3])
49459
df1d4e442c08 compare-disco: prepare for primitive argument parsing
Pierre-Yves DAVID <pierre-yves.david@octobus.net>
parents: 49018
diff changeset
   227
    sys.exit(compare(repo, local_case, remote_case, **kwargs))