contrib/revsetbenchmarks.py
author Gregory Szorc <gregory.szorc@gmail.com>
Tue, 23 Jun 2015 22:20:08 -0700
changeset 25660 328739ea70c3
parent 25646 57e7a060a06f
child 26034 1d829f802fab
permissions -rwxr-xr-x
global: mass rewrite to use modern exception syntax Python 2.6 introduced the "except type as instance" syntax, replacing the "except type, instance" syntax that came before. Python 3 dropped support for the latter syntax. Since we no longer support Python 2.4 or 2.5, we have no need to continue supporting the "except type, instance". This patch mass rewrites the exception syntax to be Python 2.6+ and Python 3 compatible. This patch was produced by running `2to3 -f except -w -n .`.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
     1
#!/usr/bin/env python
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
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    11
import sys
21548
651d7548a744 revsetbenchmark: automatically finds the perf extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21287
diff changeset
    12
import os
25530
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    13
import re
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
    14
import math
20893
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    15
from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE
21287
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
    16
# cannot use argparse, python 2.7 only
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
    17
from optparse import OptionParser
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
    18
25544
e66f1707ba6c revsetbenchmarks: use combination variants in default set
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25543
diff changeset
    19
DEFAULTVARIANTS = ['plain', 'min', 'max', 'first', 'last',
e66f1707ba6c revsetbenchmarks: use combination variants in default set
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25543
diff changeset
    20
                   'reverse', 'reverse+first', 'reverse+last',
e66f1707ba6c revsetbenchmarks: use combination variants in default set
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25543
diff changeset
    21
                   'sort', 'sort+first', 'sort+last']
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
    22
20893
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    23
def check_output(*args, **kwargs):
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    24
    kwargs.setdefault('stderr', PIPE)
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    25
    kwargs.setdefault('stdout', PIPE)
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    26
    proc = Popen(*args, **kwargs)
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    27
    output, error = proc.communicate()
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    28
    if proc.returncode != 0:
21202
c04e5e937139 revsetbenchmark: fix error raising
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20893
diff changeset
    29
        raise CalledProcessError(proc.returncode, ' '.join(args[0]))
20893
b5de9dde181c revsetbenchmark: remove python 2.7 dependency
Durham Goode <durham@fb.com>
parents: 20855
diff changeset
    30
    return output
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
    31
20850
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    32
def update(rev):
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    33
    """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
    34
    try:
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    35
        check_call(['hg', 'update', '--quiet', '--check', str(rev)])
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25646
diff changeset
    36
    except CalledProcessError as exc:
20850
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    37
        print >> sys.stderr, 'update to revision %s failed, aborting' % rev
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    38
        sys.exit(exc.returncode)
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
    39
25528
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    40
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    41
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
    42
    """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
    43
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    44
    <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
    45
    <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
    46
    fullcmd = ['./hg']
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    47
    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
    48
        fullcmd += ['-R', repo]
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    49
    fullcmd += ['--config',
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    50
                'extensions.perf=' + os.path.join(contribdir, 'perf.py')]
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    51
    fullcmd += cmd
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    52
    return check_output(fullcmd, stderr=STDOUT)
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    53
21549
ea3d75ebea6d revsetbenchmark: support for running on other repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21548
diff changeset
    54
def perf(revset, target=None):
20851
4130ec938c84 revsetbenchmark: convert performance call to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20850
diff changeset
    55
    """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
    56
    try:
25528
a6bcd70cd9c2 revsetbenchmarks: extract call to mercurial into a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23139
diff changeset
    57
        output = hg(['perfrevset', revset], repo=target)
25530
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    58
        return parseoutput(output)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25646
diff changeset
    59
    except CalledProcessError as exc:
25529
3e80691d0dfe revsetbenchmarks: improve error output in case of failure
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25528
diff changeset
    60
        print >> sys.stderr, 'abort: cannot run revset benchmark: %s' % exc.cmd
3e80691d0dfe revsetbenchmarks: improve error output in case of failure
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25528
diff changeset
    61
        if exc.output is None:
3e80691d0dfe revsetbenchmarks: improve error output in case of failure
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25528
diff changeset
    62
            print >> sys.stderr, '(no ouput)'
3e80691d0dfe revsetbenchmarks: improve error output in case of failure
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25528
diff changeset
    63
        else:
3e80691d0dfe revsetbenchmarks: improve error output in case of failure
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25528
diff changeset
    64
            print >> sys.stderr, exc.output
25646
57e7a060a06f revsetbenchmark: do not abort on failure to run a revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25642
diff changeset
    65
        return None
20851
4130ec938c84 revsetbenchmark: convert performance call to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20850
diff changeset
    66
25530
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    67
outputre = re.compile(r'! wall (\d+.\d+) comb (\d+.\d+) user (\d+.\d+) '
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    68
                      'sys (\d+.\d+) \(best of (\d+)\)')
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    69
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    70
def parseoutput(output):
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    71
    """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
    72
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    73
    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
    74
    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
    75
    """
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    76
    match = outputre.search(output)
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    77
    if not match:
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    78
        print >> sys.stderr, 'abort: invalid output:'
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    79
        print >> sys.stderr, output
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    80
        sys.exit(1)
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    81
    return {'comb': float(match.group(2)),
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    82
            'count': int(match.group(5)),
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    83
            'sys': float(match.group(3)),
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    84
            'user': float(match.group(4)),
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    85
            'wall': float(match.group(1)),
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    86
            }
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
    87
20852
b2353501d6dc revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20851
diff changeset
    88
def printrevision(rev):
b2353501d6dc revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20851
diff changeset
    89
    """print data about a revision"""
25538
caff256205ea revsetbenchmarks: improve revision printing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25537
diff changeset
    90
    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
    91
    sys.stdout.flush()
b2353501d6dc revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20851
diff changeset
    92
    check_call(['hg', 'log', '--rev', str(rev), '--template',
25546
59cdf631388b revsetbenchmarks: also display tag when printing a revision
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25544
diff changeset
    93
                '{if(tags, " ({tags})")} '
25538
caff256205ea revsetbenchmarks: improve revision printing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25537
diff changeset
    94
                '{rev}:{node|short}: {desc|firstline}\n'])
20852
b2353501d6dc revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20851
diff changeset
    95
25532
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
    96
def idxwidth(nbidx):
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
    97
    """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
    98
25533
4bdf6f58aee1 revsetbenchmarks: clarify comment based on irc discussion
Augie Fackler <augie@google.com>
parents: 25532
diff changeset
    99
    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
   100
    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
   101
    extra rounding business that log10 would imply.
4bdf6f58aee1 revsetbenchmarks: clarify comment based on irc discussion
Augie Fackler <augie@google.com>
parents: 25532
diff changeset
   102
    """
25532
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   103
    nbidx -= 1 # starts at 0
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   104
    idxwidth = 0
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   105
    while nbidx:
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   106
        idxwidth += 1
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   107
        nbidx //= 10
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   108
    if not idxwidth:
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   109
        idxwidth = 1
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   110
    return idxwidth
1311aee85dcf revsetbenchmarks: ensure all indexes have the same width
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25531
diff changeset
   111
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   112
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
   113
    """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
   114
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   115
    Return None if the factor is insignicant (less than <sensitivity>
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   116
    variation)."""
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   117
    factor = 1
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   118
    if main is not None:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   119
        factor = other[field] / main[field]
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   120
    low, high = 1 - sensitivity, 1 + sensitivity
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   121
    if (low < factor < high):
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   122
        return None
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   123
    return factor
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   124
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   125
def formatfactor(factor):
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   126
    """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
   127
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   128
     22%
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   129
    156%
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   130
    x2.4
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   131
     x23
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   132
    x789
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   133
    x1e4
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   134
    x5x7
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   135
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   136
    """
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   137
    if factor is None:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   138
        return '    '
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   139
    elif factor < 2:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   140
        return '%3i%%' % (factor * 100)
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   141
    elif factor < 10:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   142
        return 'x%3.1f' % factor
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   143
    elif factor < 1000:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   144
        return '%4s' % ('x%i' % factor)
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   145
    else:
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   146
        order = int(math.log(factor)) + 1
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   147
        while 1 < math.log(factor):
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   148
            factor //= 0
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   149
        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
   150
25541
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   151
def formattiming(value):
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   152
    """format a value to strictly 8 char, dropping some precision if needed"""
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   153
    if value < 10**7:
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   154
        return ('%.6f' % value)[:8]
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   155
    else:
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   156
        # 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
   157
        return '%i' % value
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   158
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   159
_marker = object()
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   160
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
   161
    """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
   162
    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
   163
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   164
    out = []
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   165
    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
   166
        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
   167
            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
   168
            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
   169
            continue
25541
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   170
        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
   171
        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
   172
            factor = None
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   173
            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
   174
                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
   175
            out.append(formatfactor(factor))
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   176
        if verbose:
25541
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   177
            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
   178
            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
   179
            out.append(formattiming(data[var]['sys']))
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   180
            out.append('%6d'    % data[var]['count'])
25534
43e5a6819aba revsetbenchmarks: use a more compact output format with a header
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25533
diff changeset
   181
    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
   182
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   183
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
   184
    header = [' ' * (idxwidth(maxidx) + 1)]
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   185
    for var in variants:
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   186
        if not var:
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   187
            var = 'iter'
25541
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   188
        if 8 < len(var):
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   189
            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
   190
        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
   191
        if relative:
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   192
            header.append('    ')
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   193
        if verbose:
25541
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   194
            header.append('%-8s' % 'comb')
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   195
            header.append('%-8s' % 'user')
80ce5bce281f revsetbenchmarks: display even more compact timing result
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25540
diff changeset
   196
            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
   197
            header.append('%6s' % 'count')
25534
43e5a6819aba revsetbenchmarks: use a more compact output format with a header
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25533
diff changeset
   198
    print ' '.join(header)
25530
94efef10b63f revsetbenchmarks: parse perfrevset output into actual number
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25529
diff changeset
   199
20853
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   200
def getrevs(spec):
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   201
    """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
   202
    try:
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   203
        out = check_output(['hg', 'log', '--template={rev}\n', '--rev', spec])
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25646
diff changeset
   204
    except CalledProcessError as exc:
20853
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   205
        print >> sys.stderr, "abort, can't get revision from %s" % spec
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   206
        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
   207
    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
   208
95293cf67871 revsetbenchmark: get revision to benchmark in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20852
diff changeset
   209
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   210
def applyvariants(revset, variant):
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   211
    if variant == 'plain':
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   212
        return revset
25543
36336cc8cfab revsetbenchmarks: support combining variants with "+"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25542
diff changeset
   213
    for var in variant.split('+'):
36336cc8cfab revsetbenchmarks: support combining variants with "+"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25542
diff changeset
   214
        revset = '%s(%s)' % (var, revset)
36336cc8cfab revsetbenchmarks: support combining variants with "+"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25542
diff changeset
   215
    return revset
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   216
25607
ddb2a648fdbd revsetbenchmarks: add main documention for the script
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25546
diff changeset
   217
helptext="""This script will run multiple variants of provided revsets using
ddb2a648fdbd revsetbenchmarks: add main documention for the script
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25546
diff changeset
   218
different revisions in your mercurial repository. After the benchmark are run
ddb2a648fdbd revsetbenchmarks: add main documention for the script
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25546
diff changeset
   219
summary output is provided. Use itto demonstrate speed improvements or pin
ddb2a648fdbd revsetbenchmarks: add main documention for the script
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25546
diff changeset
   220
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
   221
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
   222
comments."""
ddb2a648fdbd revsetbenchmarks: add main documention for the script
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25546
diff changeset
   223
parser = OptionParser(usage="usage: %prog [options] <revs>",
ddb2a648fdbd revsetbenchmarks: add main documention for the script
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25546
diff changeset
   224
                      description=helptext)
21287
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
   225
parser.add_option("-f", "--file",
23139
e53f6b72a0e4 spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 22556
diff changeset
   226
                  help="read revset from FILE (stdin if omitted)",
22555
2143d794e960 revsetbenchmark: make it clear that revsets may be read from stdin
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22059
diff changeset
   227
                  metavar="FILE")
21549
ea3d75ebea6d revsetbenchmark: support for running on other repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21548
diff changeset
   228
parser.add_option("-R", "--repo",
ea3d75ebea6d revsetbenchmark: support for running on other repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21548
diff changeset
   229
                  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
   230
25537
c1e24e1fd45f revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25536
diff changeset
   231
parser.add_option("-v", "--verbose",
c1e24e1fd45f revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25536
diff changeset
   232
                  action='store_true',
c1e24e1fd45f revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25536
diff changeset
   233
                  help="display all timing data (not just best total time)")
c1e24e1fd45f revsetbenchmarks: hide most timing under a --verbose flag
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25536
diff changeset
   234
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   235
parser.add_option("", "--variants",
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   236
                  default=','.join(DEFAULTVARIANTS),
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   237
                  help="comma separated list of variant to test "
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   238
                       "(eg: plain,min,sorted) (plain = no modification)")
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   239
21287
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
   240
(options, args) = parser.parse_args()
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   241
25535
6d1e456645c9 revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25534
diff changeset
   242
if not args:
21287
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
   243
    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
   244
    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
   245
21548
651d7548a744 revsetbenchmark: automatically finds the perf extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21287
diff changeset
   246
# 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
   247
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
   248
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   249
revsetsfile = sys.stdin
21287
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
   250
if options.file:
2d93b74335a2 revsetbenchmark: use optparse to retrieve argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21286
diff changeset
   251
    revsetsfile = open(options.file)
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   252
22556
480a24ad9f77 revsetbenchmark: allow comments ('#' prefix) in the revset input
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22555
diff changeset
   253
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
   254
revsets = [l for l in revsets if l]
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   255
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   256
print "Revsets to benchmark"
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   257
print "----------------------------"
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   258
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   259
for idx, rset in enumerate(revsets):
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   260
    print "%i) %s" % (idx, rset)
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   261
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   262
print "----------------------------"
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   263
print
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   264
25535
6d1e456645c9 revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25534
diff changeset
   265
revs = []
6d1e456645c9 revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25534
diff changeset
   266
for a in args:
6d1e456645c9 revsetbenchmarks: fix argument parsing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25534
diff changeset
   267
    revs.extend(getrevs(a))
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   268
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   269
variants = options.variants.split(',')
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   270
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   271
results = []
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   272
for r in revs:
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   273
    print "----------------------------"
20852
b2353501d6dc revsetbenchmark: convert revision display to proper subprocesscall
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20851
diff changeset
   274
    printrevision(r)
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   275
    print "----------------------------"
20850
d0c2535c7aba revsetbenchmark: convert update to proper subprocess call
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20849
diff changeset
   276
    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
   277
    res = []
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   278
    results.append(res)
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   279
    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
   280
    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
   281
        varres = {}
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   282
        for var in variants:
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   283
            varrset = applyvariants(rset, var)
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   284
            data = perf(varrset, target=options.repo)
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   285
            varres[var] = data
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   286
        res.append(varres)
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   287
        printresult(variants, idx, varres, len(revsets),
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   288
                    verbose=options.verbose)
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   289
        sys.stdout.flush()
20848
11a9393609c8 revsetbenchmark: simplify and convert the script to python
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20847
diff changeset
   290
    print "----------------------------"
20745
5fb7c36d751f contrib: added revset performance benchmarking script
Lucas Moscovicz <lmoscovicz@fb.com>
parents:
diff changeset
   291
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   292
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   293
print """
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   294
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   295
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
   296
================
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   297
"""
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   298
25538
caff256205ea revsetbenchmarks: improve revision printing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25537
diff changeset
   299
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
   300
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
   301
    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
   302
    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
   303
    printrevision(rev)
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   304
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   305
print
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   306
print
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   307
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   308
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
   309
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   310
    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
   311
    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
   312
    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
   313
    for idx, data in enumerate(results):
25540
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   314
        printresult(variants, idx, data[ridx], len(results),
f08ad5d17e43 revsetbenchmarks: allow running multiple variants per revset
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25539
diff changeset
   315
                    verbose=options.verbose, reference=ref)
25539
460922c95643 revsetbenchmarks: display relative change when meaningful
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25538
diff changeset
   316
        ref = data[ridx]
20855
dfad9bb23ab4 revsetbenchmark: add a summary at the end of execution
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20854
diff changeset
   317
    print