contrib/revsetbenchmarks.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 21 Jan 2022 15:52:48 +0100
changeset 48620 c5f734ef0b15
parent 45830 c102b704edb5
child 48875 6000f5b25c9b
permissions -rwxr-xr-x
test-http-bad-server: move on test from bytes-count to pattern This specific test case is now using the new "close when a pattern is seen" approach compared to the more fragile "that many bytes were sent" approach. Since such change are still a bit noisy, we split each change in there own changesets. Differential Revision: https://phab.mercurial-scm.org/D12051
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45830
c102b704edb5 global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
     1
#!/usr/bin/env python3
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
     2
20746
47fc466825da contrib: have the revset benchmark test script take a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20745
diff changeset
     3
# Measure the performance of a list of revsets against multiple revisions
47fc466825da contrib: have the revset benchmark test script take a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20745
diff changeset
     4
# defined by parameter. Checkout one by one and run perfrevset with every
47fc466825da contrib: have the revset benchmark test script take a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20745
diff changeset
     5
# revset in the list to benchmark its performance.
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
     6
#
25535
6d1e456645c9 revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25534
diff changeset
     7
# You should run this from the root of your mercurial repository.
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
     8
#
25535
6d1e456645c9 revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25534
diff changeset
     9
# call with --help for details
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
    10
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
    11
from __future__ import absolute_import, print_function
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
    12
import math
29210
984c4d23d39c py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara <yuya@tcha.org>
parents: 28564
diff changeset
    13
import optparse  # cannot use argparse, python 2.7 only
21548
651d7548a744 revsetbenchmark: automatically finds the perf extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21287
diff changeset
    14
import os
25530
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    15
import re
29210
984c4d23d39c py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara <yuya@tcha.org>
parents: 28564
diff changeset
    16
import subprocess
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
    17
import sys
21287
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
    18
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    19
DEFAULTVARIANTS = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    20
    'plain',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    21
    'min',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    22
    'max',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    23
    'first',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    24
    'last',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    25
    'reverse',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    26
    'reverse+first',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    27
    'reverse+last',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    28
    'sort',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    29
    'sort+first',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    30
    'sort+last',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    31
]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    32
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
    33
20893
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    34
def check_output(*args, **kwargs):
29210
984c4d23d39c py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara <yuya@tcha.org>
parents: 28564
diff changeset
    35
    kwargs.setdefault('stderr', subprocess.PIPE)
984c4d23d39c py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara <yuya@tcha.org>
parents: 28564
diff changeset
    36
    kwargs.setdefault('stdout', subprocess.PIPE)
984c4d23d39c py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara <yuya@tcha.org>
parents: 28564
diff changeset
    37
    proc = subprocess.Popen(*args, **kwargs)
20893
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    38
    output, error = proc.communicate()
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    39
    if proc.returncode != 0:
29210
984c4d23d39c py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara <yuya@tcha.org>
parents: 28564
diff changeset
    40
        raise subprocess.CalledProcessError(proc.returncode, ' '.join(args[0]))
20893
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    41
    return output
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    42
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    43
20850
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    44
def update(rev):
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    45
    """update the repo to a revision"""
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    46
    try:
29210
984c4d23d39c py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara <yuya@tcha.org>
parents: 28564
diff changeset
    47
        subprocess.check_call(['hg', 'update', '--quiet', '--check', str(rev)])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    48
        check_output(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    49
            ['make', 'local'], stderr=None
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    50
        )  # suppress output except for error/warning
29210
984c4d23d39c py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara <yuya@tcha.org>
parents: 28564
diff changeset
    51
    except subprocess.CalledProcessError as exc:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    52
        print('update to revision %s failed, aborting' % rev, file=sys.stderr)
20850
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    53
        sys.exit(exc.returncode)
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    54
25528
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    55
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    56
def hg(cmd, repo=None):
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    57
    """run a mercurial command
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    58
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    59
    <cmd> is the list of command + argument,
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    60
    <repo> is an optional repository path to run this command in."""
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    61
    fullcmd = ['./hg']
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    62
    if repo is not None:
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    63
        fullcmd += ['-R', repo]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    64
    fullcmd += [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    65
        '--config',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    66
        'extensions.perf=' + os.path.join(contribdir, 'perf.py'),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    67
    ]
25528
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    68
    fullcmd += cmd
29210
984c4d23d39c py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara <yuya@tcha.org>
parents: 28564
diff changeset
    69
    return check_output(fullcmd, stderr=subprocess.STDOUT)
25528
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    70
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    71
27073
b9fc042168a4 revsetbenchmarks: support benchmarking changectx loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26781
diff changeset
    72
def perf(revset, target=None, contexts=False):
20851
4130ec938c84 revsetbenchmark: convert performance call to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20850
diff changeset
    73
    """run benchmark for this very revset"""
4130ec938c84 revsetbenchmark: convert performance call to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20850
diff changeset
    74
    try:
41272
71ef4e923886 revsetbenchmarks: support revset starting with a "-"
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
    75
        args = ['perfrevset']
27073
b9fc042168a4 revsetbenchmarks: support benchmarking changectx loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26781
diff changeset
    76
        if contexts:
b9fc042168a4 revsetbenchmarks: support benchmarking changectx loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26781
diff changeset
    77
            args.append('--contexts')
41272
71ef4e923886 revsetbenchmarks: support revset starting with a "-"
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
    78
        args.append('--')
71ef4e923886 revsetbenchmarks: support revset starting with a "-"
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
    79
        args.append(revset)
27073
b9fc042168a4 revsetbenchmarks: support benchmarking changectx loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26781
diff changeset
    80
        output = hg(args, repo=target)
25530
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    81
        return parseoutput(output)
29210
984c4d23d39c py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara <yuya@tcha.org>
parents: 28564
diff changeset
    82
    except subprocess.CalledProcessError as exc:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    83
        print(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    84
            'abort: cannot run revset benchmark: %s' % exc.cmd, file=sys.stderr
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    85
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    86
        if getattr(exc, 'output', None) is None:  # no output before 2.7
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
    87
            print('(no output)', file=sys.stderr)
25529
3e80691d0dfe revsetbenchmarks: improve error output in case of failure
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25528
diff changeset
    88
        else:
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
    89
            print(exc.output, file=sys.stderr)
25646
57e7a060a06f revsetbenchmark: do not abort on failure to run a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25642
diff changeset
    90
        return None
20851
4130ec938c84 revsetbenchmark: convert performance call to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20850
diff changeset
    91
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    92
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    93
outputre = re.compile(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    94
    br'! wall (\d+.\d+) comb (\d+.\d+) user (\d+.\d+) '
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    95
    br'sys (\d+.\d+) \(best of (\d+)\)'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    96
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
    97
25530
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    98
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    99
def parseoutput(output):
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   100
    """parse a textual output into a dict
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   101
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   102
    We cannot just use json because we want to compare with old
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   103
    versions of Mercurial that may not support json output.
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   104
    """
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   105
    match = outputre.search(output)
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   106
    if not match:
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   107
        print('abort: invalid output:', file=sys.stderr)
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   108
        print(output, file=sys.stderr)
25530
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   109
        sys.exit(1)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   110
    return {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   111
        'comb': float(match.group(2)),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   112
        'count': int(match.group(5)),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   113
        'sys': float(match.group(3)),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   114
        'user': float(match.group(4)),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   115
        'wall': float(match.group(1)),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   116
    }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   117
25530
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   118
20852
b2353501d6dc revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20851
diff changeset
   119
def printrevision(rev):
b2353501d6dc revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20851
diff changeset
   120
    """print data about a revision"""
25538
caff256205ea revsetbenchmarks: improve revision printing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25537
diff changeset
   121
    sys.stdout.write("Revision ")
20852
b2353501d6dc revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20851
diff changeset
   122
    sys.stdout.flush()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   123
    subprocess.check_call(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   124
        [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   125
            'hg',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   126
            'log',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   127
            '--rev',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   128
            str(rev),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   129
            '--template',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   130
            '{if(tags, " ({tags})")} ' '{rev}:{node|short}: {desc|firstline}\n',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   131
        ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   132
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   133
20852
b2353501d6dc revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20851
diff changeset
   134
25532
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   135
def idxwidth(nbidx):
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   136
    """return the max width of number used for index
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   137
25533
4bdf6f58aee1 revsetbenchmarks: clarify comment based on irc discussion
Augie Fackler <augie@google.com>
parents: 25532
diff changeset
   138
    This is similar to log10(nbidx), but we use custom code here
4bdf6f58aee1 revsetbenchmarks: clarify comment based on irc discussion
Augie Fackler <augie@google.com>
parents: 25532
diff changeset
   139
    because we start with zero and we'd rather not deal with all the
4bdf6f58aee1 revsetbenchmarks: clarify comment based on irc discussion
Augie Fackler <augie@google.com>
parents: 25532
diff changeset
   140
    extra rounding business that log10 would imply.
4bdf6f58aee1 revsetbenchmarks: clarify comment based on irc discussion
Augie Fackler <augie@google.com>
parents: 25532
diff changeset
   141
    """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   142
    nbidx -= 1  # starts at 0
25532
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   143
    idxwidth = 0
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   144
    while nbidx:
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   145
        idxwidth += 1
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   146
        nbidx //= 10
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   147
    if not idxwidth:
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   148
        idxwidth = 1
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   149
    return idxwidth
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   150
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   151
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   152
def getfactor(main, other, field, sensitivity=0.05):
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   153
    """return the relative factor between values for 'field' in main and other
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   154
26781
1aee2ab0f902 spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents: 26034
diff changeset
   155
    Return None if the factor is insignificant (less than <sensitivity>
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   156
    variation)."""
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   157
    factor = 1
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   158
    if main is not None:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   159
        factor = other[field] / main[field]
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   160
    low, high = 1 - sensitivity, 1 + sensitivity
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   161
    if low < factor < high:
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   162
        return None
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   163
    return factor
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   164
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   165
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   166
def formatfactor(factor):
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   167
    """format a factor into a 4 char string
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   168
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   169
     22%
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   170
    156%
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   171
    x2.4
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   172
     x23
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   173
    x789
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   174
    x1e4
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   175
    x5x7
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   176
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   177
    """
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   178
    if factor is None:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   179
        return '    '
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   180
    elif factor < 2:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   181
        return '%3i%%' % (factor * 100)
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   182
    elif factor < 10:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   183
        return 'x%3.1f' % factor
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   184
    elif factor < 1000:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   185
        return '%4s' % ('x%i' % factor)
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   186
    else:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   187
        order = int(math.log(factor)) + 1
40029
e2697acd9381 cleanup: some Yoda conditions, this patch removes
Martin von Zweigbergk <martinvonz@google.com>
parents: 29210
diff changeset
   188
        while math.log(factor) > 1:
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   189
            factor //= 0
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   190
        return 'x%ix%i' % (factor, order)
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   191
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   192
25541
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   193
def formattiming(value):
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   194
    """format a value to strictly 8 char, dropping some precision if needed"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   195
    if value < 10 ** 7:
25541
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   196
        return ('%.6f' % value)[:8]
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   197
    else:
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   198
        # value is HUGE very unlikely to happen (4+ month run)
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   199
        return '%i' % value
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   200
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   201
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   202
_marker = object()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   203
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   204
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   205
def printresult(variants, idx, data, maxidx, verbose=False, reference=_marker):
25531
371d8afc9144 revsetbenchmarks: factor out result output into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25530
diff changeset
   206
    """print a line of result to stdout"""
25532
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   207
    mask = '%%0%ii) %%s' % idxwidth(maxidx)
25646
57e7a060a06f revsetbenchmark: do not abort on failure to run a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25642
diff changeset
   208
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   209
    out = []
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   210
    for var in variants:
25646
57e7a060a06f revsetbenchmark: do not abort on failure to run a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25642
diff changeset
   211
        if data[var] is None:
57e7a060a06f revsetbenchmark: do not abort on failure to run a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25642
diff changeset
   212
            out.append('error   ')
57e7a060a06f revsetbenchmark: do not abort on failure to run a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25642
diff changeset
   213
            out.append(' ' * 4)
57e7a060a06f revsetbenchmark: do not abort on failure to run a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25642
diff changeset
   214
            continue
25541
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   215
        out.append(formattiming(data[var]['wall']))
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   216
        if reference is not _marker:
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   217
            factor = None
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   218
            if reference is not None:
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   219
                factor = getfactor(reference[var], data[var], 'wall')
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   220
            out.append(formatfactor(factor))
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   221
        if verbose:
25541
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   222
            out.append(formattiming(data[var]['comb']))
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   223
            out.append(formattiming(data[var]['user']))
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   224
            out.append(formattiming(data[var]['sys']))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   225
            out.append('%6d' % data[var]['count'])
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   226
    print(mask % (idx, ' '.join(out)))
25530
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   227
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   228
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   229
def printheader(variants, maxidx, verbose=False, relative=False):
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   230
    header = [' ' * (idxwidth(maxidx) + 1)]
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   231
    for var in variants:
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   232
        if not var:
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   233
            var = 'iter'
40029
e2697acd9381 cleanup: some Yoda conditions, this patch removes
Martin von Zweigbergk <martinvonz@google.com>
parents: 29210
diff changeset
   234
        if len(var) > 8:
25541
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   235
            var = var[:3] + '..' + var[-3:]
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   236
        header.append('%-8s' % var)
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   237
        if relative:
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   238
            header.append('    ')
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   239
        if verbose:
25541
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   240
            header.append('%-8s' % 'comb')
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   241
            header.append('%-8s' % 'user')
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   242
            header.append('%-8s' % 'sys')
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   243
            header.append('%6s' % 'count')
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   244
    print(' '.join(header))
25530
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   245
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   246
20853
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   247
def getrevs(spec):
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   248
    """get the list of rev matched by a revset"""
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   249
    try:
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   250
        out = check_output(['hg', 'log', '--template={rev}\n', '--rev', spec])
29210
984c4d23d39c py3: make contrib/revsetbenchmarks.py not import symbols from stdlib modules
Yuya Nishihara <yuya@tcha.org>
parents: 28564
diff changeset
   251
    except subprocess.CalledProcessError as exc:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   252
        print("abort, can't get revision from %s" % spec, file=sys.stderr)
20853
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   253
        sys.exit(exc.returncode)
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   254
    return [r for r in out.split() if r]
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   255
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   256
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   257
def applyvariants(revset, variant):
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   258
    if variant == 'plain':
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   259
        return revset
25543
36336cc8cfab revsetbenchmarks: support combining variants with "+"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25542
diff changeset
   260
    for var in variant.split('+'):
36336cc8cfab revsetbenchmarks: support combining variants with "+"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25542
diff changeset
   261
        revset = '%s(%s)' % (var, revset)
36336cc8cfab revsetbenchmarks: support combining variants with "+"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25542
diff changeset
   262
    return revset
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   263
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   264
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   265
helptext = """This script will run multiple variants of provided revsets using
25607
ddb2a648fdbd revsetbenchmarks: add main documention for the script
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25546
diff changeset
   266
different revisions in your mercurial repository. After the benchmark are run
26781
1aee2ab0f902 spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents: 26034
diff changeset
   267
summary output is provided. Use it to demonstrate speed improvements or pin
25607
ddb2a648fdbd revsetbenchmarks: add main documention for the script
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25546
diff changeset
   268
point regressions. Revsets to run are specified in a file (or from stdin), one
ddb2a648fdbd revsetbenchmarks: add main documention for the script
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25546
diff changeset
   269
revsets per line. Line starting with '#' will be ignored, allowing insertion of
ddb2a648fdbd revsetbenchmarks: add main documention for the script
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25546
diff changeset
   270
comments."""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   271
parser = optparse.OptionParser(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   272
    usage="usage: %prog [options] <revs>", description=helptext
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   273
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   274
parser.add_option(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   275
    "-f",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   276
    "--file",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   277
    help="read revset from FILE (stdin if omitted)",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   278
    metavar="FILE",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   279
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   280
parser.add_option("-R", "--repo", help="run benchmark on REPO", metavar="REPO")
21287
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
   281
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   282
parser.add_option(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   283
    "-v",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   284
    "--verbose",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   285
    action='store_true',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   286
    help="display all timing data (not just best total time)",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   287
)
25537
c1e24e1fd45f revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25536
diff changeset
   288
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   289
parser.add_option(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   290
    "",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   291
    "--variants",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   292
    default=','.join(DEFAULTVARIANTS),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   293
    help="comma separated list of variant to test "
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   294
    "(eg: plain,min,sorted) (plain = no modification)",
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   295
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   296
parser.add_option(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   297
    '',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   298
    '--contexts',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   299
    action='store_true',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   300
    help='obtain changectx from results instead of integer revs',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   301
)
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   302
21287
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
   303
(options, args) = parser.parse_args()
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   304
25535
6d1e456645c9 revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25534
diff changeset
   305
if not args:
21287
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
   306
    parser.print_help()
21286
f0f810096842 revsetbenchmark: add a usage message when no arguments are passed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21202
diff changeset
   307
    sys.exit(255)
f0f810096842 revsetbenchmark: add a usage message when no arguments are passed
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21202
diff changeset
   308
21548
651d7548a744 revsetbenchmark: automatically finds the perf extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21287
diff changeset
   309
# the directory where both this script and the perf.py extension live.
651d7548a744 revsetbenchmark: automatically finds the perf extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21287
diff changeset
   310
contribdir = os.path.dirname(__file__)
21287
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
   311
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   312
revsetsfile = sys.stdin
21287
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
   313
if options.file:
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
   314
    revsetsfile = open(options.file)
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   315
22556
480a24ad9f77 revsetbenchmark: allow comments ('#' prefix) in the revset input
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22555
diff changeset
   316
revsets = [l.strip() for l in revsetsfile if not l.startswith('#')]
25642
5265932aad83 revsetbenchmarks: ignore empty lines
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25607
diff changeset
   317
revsets = [l for l in revsets if l]
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   318
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   319
print("Revsets to benchmark")
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   320
print("----------------------------")
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   321
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   322
for idx, rset in enumerate(revsets):
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   323
    print("%i) %s" % (idx, rset))
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   324
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   325
print("----------------------------")
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   326
print()
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   327
25535
6d1e456645c9 revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25534
diff changeset
   328
revs = []
6d1e456645c9 revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25534
diff changeset
   329
for a in args:
6d1e456645c9 revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25534
diff changeset
   330
    revs.extend(getrevs(a))
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   331
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   332
variants = options.variants.split(',')
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   333
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   334
results = []
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   335
for r in revs:
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   336
    print("----------------------------")
20852
b2353501d6dc revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20851
diff changeset
   337
    printrevision(r)
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   338
    print("----------------------------")
20850
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
   339
    update(r)
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   340
    res = []
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   341
    results.append(res)
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   342
    printheader(variants, len(revsets), verbose=options.verbose)
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   343
    for idx, rset in enumerate(revsets):
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   344
        varres = {}
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   345
        for var in variants:
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   346
            varrset = applyvariants(rset, var)
27073
b9fc042168a4 revsetbenchmarks: support benchmarking changectx loading
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26781
diff changeset
   347
            data = perf(varrset, target=options.repo, contexts=options.contexts)
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   348
            varres[var] = data
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   349
        res.append(varres)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   350
        printresult(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   351
            variants, idx, varres, len(revsets), verbose=options.verbose
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   352
        )
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   353
        sys.stdout.flush()
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   354
    print("----------------------------")
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   355
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   356
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   357
print(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   358
    """
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   359
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   360
Result by revset
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   361
================
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   362
"""
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   363
)
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   364
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   365
print('Revision:')
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   366
for idx, rev in enumerate(revs):
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   367
    sys.stdout.write('%i) ' % idx)
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   368
    sys.stdout.flush()
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   369
    printrevision(rev)
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   370
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   371
print()
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   372
print()
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   373
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   374
for ridx, rset in enumerate(revsets):
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   375
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   376
    print("revset #%i: %s" % (ridx, rset))
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   377
    printheader(variants, len(results), verbose=options.verbose, relative=True)
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   378
    ref = None
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   379
    for idx, data in enumerate(results):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   380
        printresult(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   381
            variants,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   382
            idx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   383
            data[ridx],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   384
            len(results),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   385
            verbose=options.verbose,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   386
            reference=ref,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41545
diff changeset
   387
        )
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   388
        ref = data[ridx]
28564
6d7da0901a28 contrib: revsetbenchmarks use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28073
diff changeset
   389
    print()