Anton Shestakov <engored@ya.ru>, Sat, 02 May 2015 02:56:30 +0800
bench: default revsets should be an iterable
bench.py
Permissions: -rwxr-xr-x
from argparse import ArgumentParser from collections import OrderedDict from settings import DBPATH, HG, LOCKFILE, TESTHGREPO, TESTREPO, rel ('blame', 'hg blame README'), ('diff', 'hg diff -r "tip~100:tip" README'), ('diffg', 'hg diff -r "tip~100:tip" --git README'), ('stcp', 'hg status --copies README'), ('logfile', 'hg log README'), ('logfilecp', 'hg log --copies README'), ('log1000', 'hg log -l1000') parser = ArgumentParser(description='Benchmark revisions and put results in the db.') parser.add_argument('revsets', metavar='REVSET', default=('last(all(), 120)',), nargs='*', help='update these revisions') parser.add_argument('--retry', action='store_true', help='try and reduce existing timings') cmd = [HG, 'log', '-R', TESTHGREPO, '-T', '{node}\n'] output = subprocess.check_output(cmd) def test(mark, mintime=1.0, mintries=3, dropcache=True): cmd = [rel(TESTHGREPO, 'hg'), '-R', TESTREPO] cmd += ['blame', rel(TESTREPO, 'README')] cmd += ['status', '--copies', rel(TESTREPO, 'README')] cmd += ['diff', '-r', 'tip~100:tip', rel(TESTREPO, 'README')] cmd += ['diff', '-r', 'tip~100:tip', '--git', rel(TESTREPO, 'README')] cmd += ['log', rel(TESTREPO, 'README')] elif mark == 'logfilecp': cmd += ['log', '--copies', rel(TESTREPO, 'README')] while sum(results) < mintime and len(results) < mintries: shutil.rmtree(rel(TESTREPO, '.hg', 'cache'), ignore_errors=True) subprocess.check_output(cmd) except subprocess.CalledProcessError: results.append(time.time() - start) subprocess.check_output(['make', '--directory', TESTHGREPO, 'clean'], stderr=subprocess.STDOUT) subprocess.check_output([HG, 'update', '-R', TESTHGREPO, '--clean', node], stderr=subprocess.STDOUT) subprocess.check_output(['make', '--directory', TESTHGREPO, 'local'], stderr=subprocess.STDOUT) conn = sqlite3.connect(DBPATH) 'CREATE TABLE IF NOT EXISTS results (' ' node CHAR(40) NOT NULL,' ' mark VARCHAR(40) NOT NULL,' 'CREATE INDEX IF NOT EXISTS idx_results_node ON results (node)') def dbupdate(revsets, retry=False): conn = sqlite3.connect(DBPATH) nodes = getnodes(revsets) for i, node in enumerate(nodes, 1): for cache in (False, True): 'SELECT time FROM results WHERE node = ? AND mark = ? AND cache = ?', (node, mark, cache)).fetchall() oldtime = old[0][0] if old else None if oldtime is not None and not retry: time = test(mark, dropcache=not cache) logging.info('%05d/%05d %s %s %f', i, len(nodes), node, mark, time) 'INSERT INTO results (node, mark, time, cache) VALUES (?, ?, ?, ?)', (node, mark, time, cache)) 'UPDATE results SET time = ? WHERE node = ? AND mark = ? AND cache = ?', (time, node, mark, cache)) flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL return os.fdopen(os.open(LOCKFILE, flags), 'w') if e.errno == errno.EEXIST: logging.error('cannot lock data directory') def main(revsets, retry=False): if __name__ == '__main__': logging.getLogger().setLevel(logging.INFO) args = parser.parse_args() main(args.revsets, args.retry)