Rev 1: Writing a simple command helper for benchmarking groupcompress in http://bzr.arbash-meinel.com/plugins/test_groupcompress
John Arbash Meinel
john at arbash-meinel.com
Thu Jul 24 04:44:14 BST 2008
At http://bzr.arbash-meinel.com/plugins/test_groupcompress
------------------------------------------------------------
revno: 1
revision-id: john at arbash-meinel.com-20080724034407-899i12guc11vm1lj
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: test_groupcompress
timestamp: Wed 2008-07-23 22:44:07 -0500
message:
Writing a simple command helper for benchmarking groupcompress
-------------- next part --------------
=== added file '__init__.py'
--- a/__init__.py 1970-01-01 00:00:00 +0000
+++ b/__init__.py 2008-07-24 03:44:07 +0000
@@ -0,0 +1,111 @@
+# Copyright (C) 2008 Canonical Limited.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+#
+# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+"""Test utilities for benchmarking groupcompress functionality."""
+
+import time
+
+from bzrlib import (
+ commands,
+ errors,
+ option,
+ osutils,
+ trace,
+ ui,
+ )
+
+
+NUM_STEPS = 5
+
+
+class cmd_bench_gc(commands.Command):
+ """Do a benchmark of a GroupCompress action.
+
+ Recompress the entire history of the given file, and report timings.
+ """
+
+ takes_options = [option.Option('lsp', type=str,
+ help='Profile the compression operation.'),
+ option.Option('reverse',
+ help='Reverse the text ordering'),
+ ]
+ takes_args = ['filename']
+
+ def run(self, filename, lsp=None, reverse=False):
+ from bzrlib import (
+ graph,
+ workingtree,
+ )
+ wt, relpath = workingtree.WorkingTree.open_containing(filename)
+ wt.lock_read()
+ try:
+ file_id = wt.path2id(relpath)
+ basis_tree = wt.basis_tree()
+ basis_tree.lock_read()
+ rev_id = basis_tree.inventory[file_id].revision
+ basis_tree.unlock()
+
+ g = graph.Graph(wt.branch.repository.texts)
+ trace.note('getting ancestry')
+ ancestry = dict(g.iter_ancestry([(file_id, rev_id)]))
+
+ trace.note('getting stream')
+ stream = wt.branch.repository.texts.get_record_stream(ancestry,
+ 'topological', True)
+ texts = []
+ total_count = len(ancestry)
+ trace.note('extracting')
+ pb = ui.ui_factory.nested_progress_bar()
+ try:
+ for idx, record in enumerate(stream):
+ pb.update('extracting', idx, total_count)
+ if record.storage_kind == 'absent':
+ continue
+ texts.append((record.key,
+ osutils.split_lines(record.get_bytes_as('fulltext'))))
+ finally:
+ pb.finished()
+
+ if reverse:
+ texts.reverse()
+ trace.note('compressing')
+ pb = ui.ui_factory.nested_progress_bar()
+ try:
+ self._compress_texts(pb, texts)
+ finally:
+ pb.finished()
+ finally:
+ wt.unlock()
+
+ def _compress_texts(self, pb, texts):
+ from bzrlib.plugins.groupcompress import groupcompress
+ start = time.time()
+ gc = groupcompress.GroupCompressor(True)
+ for idx, (key, lines) in enumerate(texts):
+ pb.update('compressing', idx, len(texts))
+ gc.compress(key, lines, None)
+ end = time.time()
+ trace.note('Compressed %d text with %d bytes to %d bytes (%.2f:1)'
+ ' in %.3fs',
+ len(texts), gc.input_bytes, gc.endpoint, gc.ratio(), end-start)
+
+commands.register_command(cmd_bench_gc)
+
+
+# def load_tests(standard_tests, module, loader):
+# standard_tests.addTests(loader.loadTestsFromModuleNames(
+# ['bzrlib.plugins.groupcompress.tests']))
+# return standard_tests
More information about the bazaar-commits
mailing list