You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/02/06 16:42:52 UTC
[26/50] git commit: [#4691] Added scm benchmark script for evaluating
LCD solutions
[#4691] Added scm benchmark script for evaluating LCD solutions
Signed-off-by: Cory Johns <jo...@geek.net>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/6cc8e379
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/6cc8e379
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/6cc8e379
Branch: refs/heads/cj/4691
Commit: 6cc8e37999808af7131f98d03a031d1d3172c77b
Parents: 037041c
Author: Cory Johns <jo...@geek.net>
Authored: Thu Jan 10 16:19:59 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Tue Feb 5 20:22:51 2013 +0000
----------------------------------------------------------------------
scripts/benchmark-scm.py | 125 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 125 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6cc8e379/scripts/benchmark-scm.py
----------------------------------------------------------------------
diff --git a/scripts/benchmark-scm.py b/scripts/benchmark-scm.py
new file mode 100755
index 0000000..a5cb9e4
--- /dev/null
+++ b/scripts/benchmark-scm.py
@@ -0,0 +1,125 @@
+#!/bin/env python
+
+import os
+import sys
+import argparse
+from datetime import datetime
+
+import git
+import pysvn
+from mercurial import ui, hg, cmdutil
+
+
+def main(opts):
+ if opts.type == 'git':
+ repo = git.Repo(opts.repo_path, odbt=git.GitCmdObjectDB)
+ cid = opts.cid
+ path = opts.path.strip('/')
+ tree = repo.commit(opts.cid).tree
+ if path:
+ tree = tree[path]
+ names = [n.name for n in tree]
+ impl = impl_git_tree if opts.full_tree else impl_git_node
+ elif opts.type == 'hg':
+ repo = hg.repository(HgUI(), opts.repo_path)
+ cid = None if opts.cid == 'HEAD' else ['%s:0' % opts.cid]
+ path = opts.path.strip('/')
+ filenames = repo['tip' if opts.cid == 'HEAD' else opts.cid].manifest().keys()
+ filenames = [name for name in filenames if name.startswith(('%s/' % path).lstrip('/'))]
+ names = set()
+ for name in filenames:
+ names.add(name.split('/')[0])
+ names = list(names)
+ impl = impl_hg_tree if opts.full_tree else impl_hg_node
+ elif opts.type == 'svn':
+ repo = pysvn.Client()
+ if opts.cid == 'HEAD':
+ cid = pysvn.Revision(pysvn.opt_revision_kind.head)
+ else:
+ cid = pysvn.Revision(pysvn.opt_revision_kind.number, opts.cid)
+ path = opts.path.strip('/')
+ names = []
+ impl = impl_svn_tree if opts.full_tree else impl_svn_node
+
+ sys.stdout.write('Timing %s' % ('full tree' if opts.full_tree else 'node'))
+ sys.stdout.flush()
+ total = 0.0
+ for i in range(opts.count):
+ sys.stdout.write('.')
+ sys.stdout.flush()
+ start = datetime.now()
+ impl(repo, cid, path, names, opts.repo_path)
+ end = datetime.now()
+ total += (end - start).total_seconds()
+ print
+ print 'Total time: %s' % total
+ print 'Average time per run: %s' % (total / opts.count)
+
+
+def impl_git_tree(repo, cid, path, names, *args):
+ data = {}
+ for name in names:
+ #data[name] = repo.git.rev_list(cid, '--', os.path.join(path, name), max_count=1)
+ data[name] = git.Commit.iter_items(repo, cid, os.path.join(path, name), max_count=1).next().hexsha
+ return data
+
+def impl_git_node(repo, cid, path, *args):
+ #return repo.git.rev_list(cid, '--', path, max_count=1)
+ return git.Commit.iter_items(repo, cid, path, max_count=1).next().hexsha
+
+
+def impl_hg_tree(repo, cid, path, names, *args):
+ m = cmdutil.match(repo, pats=[path], default=path)
+ data = {}
+ for name in names:
+ rev_iter = cmdutil.walkchangerevs(repo, m, {'rev': cid}, lambda c,f: None)
+ data[name] = rev_iter.next().hex()
+ return data
+
+def impl_hg_node(repo, cid, path, *args):
+ m = cmdutil.match(repo, pats=[path], default=path)
+ rev_iter = cmdutil.walkchangerevs(repo, m, {'rev': cid}, lambda c,f: None)
+ return rev_iter.next().hex()
+
+def impl_svn_tree(repo, cid, path, names, repo_path, *args):
+ infos = repo.info2(
+ 'file://%s/%s' % (repo_path, path),
+ revision=cid,
+ depth=pysvn.depth.immediates)
+ data = {}
+ for name, info in infos[1:]:
+ data[name] = info.last_changed_rev
+ return data
+
+def impl_svn_node(repo, cid, path, names, repo_path, *args):
+ logs = repo.log(
+ 'file://%s/%s' % (repo_path, path),
+ revision_start=cid,
+ limit=1)
+ return logs[0].revision.number
+
+
+class HgUI(ui.ui):
+ '''Hg UI subclass that suppresses reporting of untrusted hgrc files.'''
+ def __init__(self, *args, **kwargs):
+ super(HgUI, self).__init__(*args, **kwargs)
+ self._reportuntrusted = False
+
+def parse_opts():
+ parser = argparse.ArgumentParser(description='Benchmark getting LCD from repo tool')
+ parser.add_argument('--type', default='git', dest='type',
+ help='Type of repository being tested.')
+ parser.add_argument('--repo-path', dest='repo_path', required=True,
+ help='Path to the repository to test against')
+ parser.add_argument('--commit', default='HEAD', dest='cid',
+ help='Commit ID or revision number to test against')
+ parser.add_argument('--path', default='', dest='path',
+ help='Path within the repository to test against')
+ parser.add_argument('--count', type=int, default=100, dest='count',
+ help='Number of times to execute')
+ parser.add_argument('--full-tree', action='store_true', default=False, dest='full_tree',
+ help='Time full tree listing instead of just the single node')
+ return parser.parse_args()
+
+if __name__ == '__main__':
+ main(parse_opts())