1
# Copyright (C) 2006 by Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License version 2 as published by
5
# the Free Software Foundation.
7
# This program is distributed in the hope that it will be useful,
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
# GNU General Public License for more details.
12
# You should have received a copy of the GNU General Public License
13
# along with this program; if not, write to the Free Software
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
"""Tests for bzr bundle performance."""
21
from StringIO import StringIO
23
from bzrlib.benchmarks import Benchmark
24
from bzrlib.workingtree import WorkingTree
25
from bzrlib.branch import Branch
26
from bzrlib.bundle.serializer import write_bundle
27
from bzrlib.bundle import read_bundle
28
from bzrlib.revisionspec import RevisionSpec
30
# if set, creation of test trees will be globally cached (even across test runs)
31
CACHEDIR = os.path.expanduser("~/.bazaar/devtemp")
34
def cached_make(maker, *args):
39
if not os.path.exists(CACHEDIR):
42
cache_name = "_".join([maker.__name__] + [str(x) for x in args])
43
if not os.path.exists(cache_name):
50
shutil.rmtree(cache_name)
54
for subdir in os.listdir(cache_name):
55
shutil.copytree(os.path.join(cache_name, subdir),
56
os.path.join(olddir, subdir))
60
class BundleBenchmark(Benchmark):
62
The bundle tests should (also) be done at a lower level with
63
direct call to the bzrlib."""
65
def make_kernel_like_tree_committed(self):
66
cached_make(self.make_kernel_like_tree)
68
self.run_bzr('commit', '-m', 'initial import')
70
def test_create_bundle_known_kernel_like_tree(self):
72
Create a bundle for a kernel sized tree with no ignored, unknowns,
73
or added and one commit."""
74
cached_make(self.make_kernel_like_tree_committed)
75
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
77
def test_create_bundle_many_commit_tree (self):
79
Create a bundle for a tree with many commits but no changes."""
80
cached_make(self.make_many_commit_tree)
81
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
83
def test_create_bundle_heavily_merged_tree(self):
85
Create a bundle for a heavily merged tree."""
86
cached_make(self.make_heavily_merged_tree)
87
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
89
def test_apply_bundle_known_kernel_like_tree(self):
91
Create a bundle for a kernel sized tree with no ignored, unknowns,
92
or added and one commit."""
93
cached_make(self.make_kernel_like_tree_committed)
94
f = file('../bundle', 'wb')
96
f.write(self.run_bzr('bundle', '--revision', '..-1')[0])
99
self.run_bzr("init", "../branch_a")
100
os.chdir('../branch_a')
101
self.time(self.run_bzr, 'merge', '../bundle')
104
class BundleLibraryLevelBenchmark(Benchmark):
106
def make_parametrized_tree(self, num_files, num_revisions,
107
num_files_in_bundle):
108
"""Create a tree with given parameters. Always creates 2 levels of
109
directories with the given number of files. Then the given number of
110
revisions are created, changing some lines in one files in each
111
revision. Only num_files_in_bundle files are changed in these
114
:param num_files: number of files in tree
115
:param num_revisions: number of revisions
116
:param num_files_in_bundle: number of files changed in the revisions
121
for outer in range(num_files // 64 + 1):
122
directories.append("%s/" % outer)
123
for middle in range(8):
124
prefix = "%s/%s/" % (outer, middle)
125
directories.append(prefix)
126
for filename in range(min(8, num_files - count)):
128
files.append(prefix + str(filename))
130
self.build_tree(directories + files)
131
for d in directories:
132
self.run_bzr('add', d)
133
self.run_bzr('commit', '-m', 'initial repo layout')
135
affected_files = files[:num_files_in_bundle]
137
for changes_file in range(num_revisions // num_files_in_bundle + 1):
138
for f in affected_files:
140
if count >= num_revisions:
142
content = "\n".join([str(i) for i in range(changes_file)] +
143
[str(changes_file)] * 5) + "\n"
144
self.build_tree_contents([(f, content)])
145
self.run_bzr("commit", '-m', 'some changes')
146
assert count >= num_revisions
149
for treesize, treesize_h in [(5, "small"), (100, "moderate"),
151
for bundlefiles, bundlefiles_h in [(5, "few"), (100, "some"),
153
if bundlefiles > treesize:
155
for num_revisions in [1, 500, 1000]:
157
def test_%s_files_%s_tree_%s_revision(self):
158
cached_make(self.make_parametrized_tree, %s, %s, %s)
159
branch, _ = Branch.open_containing(".")
160
revision_history = branch.revision_history()
161
bundle_text = StringIO()
162
self.time(write_bundle, branch.repository, revision_history[-1],
165
self.time(read_bundle, bundle_text)""" % (
166
bundlefiles_h, treesize_h, num_revisions,
167
treesize, num_revisions, bundlefiles)