contrib/genosxversion.py
author Georges Racinet <georges.racinet@octobus.net>
Wed, 20 Feb 2019 09:04:54 +0100
changeset 42745 4d20b1fe8a72
parent 38734 25880ddf9a86
child 42815 197e7326b8b8
permissions -rwxr-xr-x
rust-discovery: using from Python code As previously done in other topics, the Rust version is used if it's been built. The version fully in Rust of the partialdiscovery class has the performance advantage over the Python version (actually using the Rust MissingAncestor) if the undecided set is big enough. Otherwise no sampling occurs, and the discovery is reasonably fast anyway. Note: it's hard to predict the size of the initial undecided set, it can depend on the kind of topological changes between the local and remote graphs. The point of the Rust version is to make the bad cases acceptable. More specifically, the performance advantages are: - faster sampling, especially takefullsample() - much faster addmissings() in almost all cases (see commit message in grandparent of the present changeset) - no conversion cost of the undecided set at the interface between Rust and Python == Measurements with big undecided sets For an extreme example, discovery between mozilla-try and mozilla-unified (over one million undecided revisions, same case as in dbd0fcca6dfc), we get roughly a x2.5/x3 better performance: Growing sample size (5% starting with 200): time goes down from 210 to 72 seconds. Constant sample size of 200: time down from 1853 to 659 seconds. With a sample size computed from number of roots and heads of the undecided set (`respectsize` is `False`), here are perfdiscovery results: Before ! wall 9.358729 comb 9.360000 user 9.310000 sys 0.050000 (median of 50) After ! wall 3.793819 comb 3.790000 user 3.750000 sys 0.040000 (median of 50) In that later case, the sample sizes are routinely in the hundreds of thousands of revisions. While still faster, the Rust iteration in addmissings has less of an advantage than with smaller sample sizes, but one sees addcommons becoming faster, probably a consequence of not having to copy big sets back and forth. This example is not a goal in itself, but it showcases several different areas in which the process can become slow, due to different factors, and how this full Rust version can help. == Measurements with small undecided sets In cases the undecided set is small enough than no sampling occurs, the Rust version has a disadvantage at init if `targetheads` is really big (some time is lost in the translation to Rust data structures), and that is compensated by the faster `addmissings()`. On a private repository with over one million commits, we still get a minor improvement, of 6.8%: Before ! wall 0.593585 comb 0.590000 user 0.550000 sys 0.040000 (median of 50) After ! wall 0.553035 comb 0.550000 user 0.520000 sys 0.030000 (median of 50) What's interesting in that case is the first addinfo() at 180ms for Rust and 233ms for Python+C, mostly due to add_missings and the children cache computation being done in less than 0.2ms on the Rust side vs over 40ms on the Python side. The worst case we have on hand is with mozilla-try, prepared with discovery-helper.sh for 10 heads and depth 10, time goes up 2.2% on the median. In this case `targetheads` is really huge with 165842 server heads. Before ! wall 0.823884 comb 0.810000 user 0.790000 sys 0.020000 (median of 50) After ! wall 0.842607 comb 0.840000 user 0.800000 sys 0.040000 (median of 50) If that would be considered a problem, more adjustments can be made, which are prematurate at this stage: cooking special variants of methods of the inner MissingAncestors object, retrieving local heads directly from Rust to avoid the cost of conversion. Effort would probably be better spent at this point improving the surroundings if needed. Here's another data point with a smaller repository, pypy, where performance is almost identical Before ! wall 0.015121 comb 0.030000 user 0.020000 sys 0.010000 (median of 186) After ! wall 0.015009 comb 0.010000 user 0.010000 sys 0.000000 (median of 184) Differential Revision: https://phab.mercurial-scm.org/D6430
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33594
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
#!/usr/bin/env python2
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
from __future__ import absolute_import, print_function
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
import argparse
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
import json
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
import os
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
import subprocess
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
import sys
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
# Always load hg libraries from the hg we can find on $PATH.
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
hglib = json.loads(subprocess.check_output(
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
    ['hg', 'debuginstall', '-Tjson']))[0]['hgmodules']
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
sys.path.insert(0, os.path.dirname(hglib))
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
from mercurial import util
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
ap = argparse.ArgumentParser()
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
ap.add_argument('--paranoid',
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
                action='store_true',
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
                help=("Be paranoid about how version numbers compare and "
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
                      "produce something that's more likely to sort "
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
                      "reasonably."))
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
ap.add_argument('--selftest', action='store_true', help='Run self-tests.')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
ap.add_argument('versionfile', help='Path to a valid mercurial __version__.py')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
def paranoidver(ver):
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
    """Given an hg version produce something that distutils can sort.
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
    Some Mac package management systems use distutils code in order to
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
    figure out upgrades, which makes life difficult. The test case is
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
    a reduced version of code in the Munki tool used by some large
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
    organizations to centrally manage OS X packages, which is what
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
    inspired this kludge.
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    35
    >>> paranoidver('3.4')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    36
    '3.4.0'
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    37
    >>> paranoidver('3.4.2')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
    '3.4.2'
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
    >>> paranoidver('3.0-rc+10')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
    '2.9.9999-rc+10'
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
    >>> paranoidver('4.2+483-5d44d7d4076e')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
    '4.2.0+483-5d44d7d4076e'
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
    >>> paranoidver('4.2.1+598-48d1e1214d8c')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
    '4.2.1+598-48d1e1214d8c'
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    45
    >>> paranoidver('4.3-rc')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    46
    '4.2.9999-rc'
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    47
    >>> paranoidver('4.3')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    48
    '4.3.0'
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    49
    >>> from distutils import version
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    50
    >>> class LossyPaddedVersion(version.LooseVersion):
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    51
    ...     '''Subclass version.LooseVersion to compare things like
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    52
    ...     "10.6" and "10.6.0" as equal'''
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    53
    ...     def __init__(self, s):
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    54
    ...             self.parse(s)
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    55
    ...
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    56
    ...     def _pad(self, version_list, max_length):
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    57
    ...         'Pad a version list by adding extra 0 components to the end'
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    58
    ...         # copy the version_list so we don't modify it
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    59
    ...         cmp_list = list(version_list)
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    60
    ...         while len(cmp_list) < max_length:
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    61
    ...             cmp_list.append(0)
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    62
    ...         return cmp_list
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    63
    ...
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    64
    ...     def __cmp__(self, other):
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    65
    ...         if isinstance(other, str):
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    66
    ...             other = MunkiLooseVersion(other)
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    67
    ...         max_length = max(len(self.version), len(other.version))
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    68
    ...         self_cmp_version = self._pad(self.version, max_length)
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    69
    ...         other_cmp_version = self._pad(other.version, max_length)
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    70
    ...         return cmp(self_cmp_version, other_cmp_version)
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    71
    >>> def testver(older, newer):
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    72
    ...   o = LossyPaddedVersion(paranoidver(older))
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    73
    ...   n = LossyPaddedVersion(paranoidver(newer))
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    74
    ...   return o < n
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    75
    >>> testver('3.4', '3.5')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    76
    True
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    77
    >>> testver('3.4.0', '3.5-rc')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    78
    True
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    79
    >>> testver('3.4-rc', '3.5')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    80
    True
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    81
    >>> testver('3.4-rc+10-deadbeef', '3.5')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    82
    True
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    83
    >>> testver('3.4.2', '3.5-rc')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    84
    True
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    85
    >>> testver('3.4.2', '3.5-rc+10-deadbeef')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    86
    True
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    87
    >>> testver('4.2+483-5d44d7d4076e', '4.2.1+598-48d1e1214d8c')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    88
    True
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    89
    >>> testver('4.3-rc', '4.3')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    90
    True
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    91
    >>> testver('4.3', '4.3-rc')
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    92
    False
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    93
    """
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    94
    major, minor, micro, extra = util.versiontuple(ver, n=4)
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    95
    if micro is None:
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    96
        micro = 0
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    97
    if extra:
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    98
        if extra.startswith('rc'):
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
    99
            if minor == 0:
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   100
                major -= 1
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   101
                minor = 9
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   102
            else:
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   103
                minor -= 1
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   104
            micro = 9999
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   105
            extra = '-' + extra
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   106
        else:
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   107
            extra = '+' + extra
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   108
    else:
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   109
        extra = ''
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   110
    return '%d.%d.%d%s' % (major, minor, micro, extra)
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   111
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   112
def main(argv):
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   113
    opts = ap.parse_args(argv[1:])
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   114
    if opts.selftest:
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   115
        import doctest
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   116
        doctest.testmod()
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   117
        return
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   118
    with open(opts.versionfile) as f:
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   119
        for l in f:
38734
25880ddf9a86 macosx: fixing macOS version generation after db9d1dd01bf0
Rodrigo Damazio <rdamazio@google.com>
parents: 33594
diff changeset
   120
            if l.startswith('version = b'):
33594
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   121
                # version number is entire line minus the quotes
38734
25880ddf9a86 macosx: fixing macOS version generation after db9d1dd01bf0
Rodrigo Damazio <rdamazio@google.com>
parents: 33594
diff changeset
   122
                ver = l[len('version = b') + 1:-2]
33594
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   123
                break
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   124
    if opts.paranoid:
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   125
        print(paranoidver(ver))
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   126
    else:
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   127
        print(ver)
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   128
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   129
if __name__ == '__main__':
283a7da602ae osx: new script for generating OS X package versions
Augie Fackler <augie@google.com>
parents:
diff changeset
   130
    main(sys.argv)