--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Sat May 02 01:47:27 2015 +0800
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bench.py Sat May 02 01:47:27 2015 +0800
+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'),
+ ('log1', 'hg log -l1'),
+ ('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')]
+ elif mark == 'logfile':
+ cmd += ['log', rel(TESTREPO, 'README')]
+ elif mark == 'logfilecp':
+ cmd += ['log', '--copies', rel(TESTREPO, 'README')]
+ elif mark == 'log1000':
+ cmd += ['log', '-l1000']
+ 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,'
+ ' time FLOAT 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):
+ dbupdate(revsets, retry)
+if __name__ == '__main__':
+ logging.getLogger().setLevel(logging.INFO)
+ args = parser.parse_args()
+ main(args.revsets, args.retry)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/deploy.sh Sat May 02 01:47:27 2015 +0800
+HGURL='http://selenic.com/hg'
+TESTURL='http://selenic.com/hg'
+hg clone "$HGURL" ./data/testhg
+hg archive -R ./data/testhg ./data/newesthg
+make --directory ./data/newesthg local
+hg clone "$TESTURL" -r 3.3.3 ./data/testrepo
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/settings.py Sat May 02 01:47:27 2015 +0800
+os.environ['HGPLAIN'] = '1'
+rel = lambda *x: os.path.abspath(os.path.join(os.path.dirname(__file__), *x))
+DBPATH = rel('data', 'db.sqlite')
+HG = rel('data', 'newesthg', 'hg')
+LOCKFILE = rel('data', 'bench.lock')
+TESTHGREPO = rel('data', 'testhg')
+TESTREPO = rel('data', 'testrepo')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/update.sh Sat May 02 01:47:27 2015 +0800
+nodes=`./data/newesthg/hg incoming -R ./data/testhg --quiet -T '{node}\n'`
+./data/newesthg/hg pull -R ./data/testhg