Rev 1: Simple plugin to time the 'save_pack_names' time. in http://bzr.arbash-meinel.com/plugins/lock_test
John Arbash Meinel
john at arbash-meinel.com
Tue Jun 15 21:01:40 BST 2010
At http://bzr.arbash-meinel.com/plugins/lock_test
------------------------------------------------------------
revno: 1
revision-id: john at arbash-meinel.com-20100615200134-axeyrh0o6dnm0asg
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: lock_test
timestamp: Tue 2010-06-15 15:01:34 -0500
message:
Simple plugin to time the 'save_pack_names' time.
-------------- next part --------------
=== added file '__init__.py'
--- a/__init__.py 1970-01-01 00:00:00 +0000
+++ b/__init__.py 2010-06-15 20:01:34 +0000
@@ -0,0 +1,71 @@
+# Copyright (C) 2010 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Test the update-pack-repo overhead.
+"""
+
+from bzrlib import commands, option, ui
+
+
+version_info = (0, 1, 0, 'dev', 0)
+__version__ = '.'.join(map(str, version_info))
+
+
+class cmd_lock_test(commands.Command):
+ """Start running lock tests on the given URL
+ """
+
+ aliases = []
+ takes_options = [option.Option('count', type=int,
+ help='How many inserts do we do'),
+ ]
+ takes_args = ['location?']
+
+ def run(self, location='.', count=10):
+ from bzrlib.plugins.lock_test import lock_test
+ repo = lock_test.open_or_create_remote(location)
+ repo.lock_write()
+ try:
+ times = []
+ save_times = []
+ pb = ui.ui_factory.nested_progress_bar()
+ for i in xrange(count):
+ pb.update('Inserting', i, count)
+ t, st = lock_test.add_random_content(repo)
+ times.append(t)
+ save_times.extend(st)
+ pb.finished()
+ s = sum(times)
+ avg = s / float(len(times))
+ m = max(times)
+ self.outf.write('commit: %d %.3fs avg, %.3fs max\n'
+ % (len(times), avg, m))
+ s = sum(save_times)
+ avg = s / float(len(save_times))
+ m = max(save_times)
+ self.outf.write('save: %d %.3fs avg, %.3fs max\n'
+ % (len(save_times), avg, m))
+ finally:
+ repo.unlock()
+
+commands.register_command(cmd_lock_test)
+
+def load_tests(standard_tests, module, loader):
+ return standard_tests
+ # standard_tests.addTests(loader.loadTestsFromModuleNames(
+ # [__name__ + '.tests']))
+ # return standard_tests
+
=== added file 'lock_test.py'
--- a/lock_test.py 1970-01-01 00:00:00 +0000
+++ b/lock_test.py 2010-06-15 20:01:34 +0000
@@ -0,0 +1,66 @@
+
+import time
+import hashlib
+
+from bzrlib import (
+ branch,
+ bzrdir,
+ errors,
+ inventory,
+ repository,
+ transport,
+ versionedfile,
+ )
+
+
+def open_or_create_remote(url):
+ t = transport.get_transport(url)
+ try:
+ bdir = bzrdir.BzrDir.open_from_transport(t)
+ except errors.NotBranchError:
+ pass
+ else:
+ repo = bdir.open_repository()
+ return repo
+ t.ensure_base()
+ fmt = bzrdir.format_registry.make_bzrdir('default')
+ newdir = fmt.initialize_on_transport(t)
+ repo = newdir.create_repository(shared=True)
+ repo.set_make_working_trees(False)
+ return repo
+
+
+def add_random_content(repo):
+ now = time.asctime() + ' %.6fs' % (time.time(),)
+ sha1 = hashlib.sha1(now).hexdigest()
+ rev_id = 'rev-' + sha1
+ content = versionedfile.FulltextContentFactory((rev_id,), [], sha1, now)
+ repo.lock_write()
+ repo.start_write_group()
+ # TODO: This is a different RPC than using repo.insert_stream(), we should
+ # probably be testing at that level instead...
+ root_ie = inventory.InventoryDirectory('TREE_ROOT', '', None)
+ root_ie.revision = rev_id
+ root_content = versionedfile.FulltextContentFactory(
+ ('TREE_ROOT', rev_id), [], None, '')
+ repo.add_inventory_by_delta('null:', [(None, '', 'TREE_ROOT', root_ie)],
+ rev_id, [])
+ repo.texts.insert_record_stream([root_content])
+ repo.revisions.insert_record_stream([content])
+ save_times = []
+ orig = repo._pack_collection._save_pack_names
+ def _do_save(*args, **kwargs):
+ t1 = time.time()
+ try:
+ return orig(*args, **kwargs)
+ finally:
+ t2 = time.time()
+ save_times.append(t2 - t1)
+ try:
+ repo._pack_collection._save_pack_names = _do_save
+ t = time.time()
+ repo.commit_write_group()
+ tdelta = time.time() - t
+ finally:
+ repo._pack_collection._save_pack_names = orig
+ return tdelta, save_times
More information about the bazaar-commits
mailing list