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 the CACHEDIR flag is set, make_parametrized_tree below will cache the tree
31
# it creates in the .bazaar/temp dir.
32
CACHEDIR = os.path.expanduser("~/.bazaar/temp")
35
class BundleBenchmark(Benchmark):
37
The bundle tests should (also) be done at a lower level with
38
direct call to the bzrlib."""
41
def test_create_bundle_known_kernel_like_tree(self):
43
Create a bundle for a kernel sized tree with no ignored, unknowns,
44
or added and one commit."""
45
self.make_kernel_like_tree()
47
self.run_bzr('commit', '-m', 'initial import')
48
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
50
def test_create_bundle_many_commit_tree (self):
52
Create a bundle for a tree with many commits but no changes."""
53
self.make_many_commit_tree()
54
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
56
def test_create_bundle_heavily_merged_tree(self):
58
Create a bundle for a heavily merged tree."""
59
self.make_heavily_merged_tree()
60
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
62
def test_apply_bundle_known_kernel_like_tree(self):
64
Create a bundle for a kernel sized tree with no ignored, unknowns,
65
or added and one commit."""
66
self.make_kernel_like_tree()
68
self.run_bzr('commit', '-m', 'initial import')
69
self.run_bzr('branch', '.', '../branch_a')
70
self.run_bzr('bundle', '--revision', '..-1')
71
f = file('../bundle', 'wb')
73
f.write(self.run_bzr('bundle', '--revision', '..-1')[0])
76
os.chdir('../branch_a')
77
self.time(self.run_bzr, 'merge', '../bundle')
80
class BundleLibraryLevelBenchmark(Benchmark):
82
def make_parametrized_tree(self, num_files, num_revisions,
84
"""Create a tree with given parameters. Always creates 2 levels of
85
directories with the given number of files. Then the given number of
86
revisions are created, changing some lines in one files in each
87
revision. Only num_files_in_bundle files are changed in these
90
:param num_files: number of files in tree
91
:param num_revisions: number of revisions
92
:param num_files_in_bundle: number of files changed in the revisions
95
return self._make_parametrized_tree(num_files, num_revisions,
99
if not os.path.exists(CACHEDIR):
100
os.makedirs(CACHEDIR)
102
cache_name = "make_parametrized_tree_%s_%s_%s" % (
103
num_files, num_revisions, num_files_in_bundle)
104
if not os.path.exists(cache_name):
107
self._make_parametrized_tree(num_files, num_revisions,
110
for subdir in os.listdir(cache_name):
111
shutil.copytree(os.path.join(cache_name, subdir),
112
os.path.join(olddir, subdir))
116
def _make_parametrized_tree(self, num_files, num_revisions,
117
num_files_in_bundle):
122
for outer in range(num_files // 64 + 1):
123
directories.append("%s/" % outer)
124
for middle in range(8):
125
prefix = "%s/%s/" % (outer, middle)
126
directories.append(prefix)
127
for filename in range(min(8, num_files - count)):
129
files.append(prefix + str(filename))
131
self.build_tree(directories + files)
132
for d in directories:
133
self.run_bzr('add', d)
134
self.run_bzr('commit', '-m', 'initial repo layout')
136
affected_files = files[:num_files_in_bundle]
138
for changes_file in range(num_revisions // num_files_in_bundle + 1):
139
for f in affected_files:
141
if count >= num_revisions:
143
content = "\n".join([str(i) for i in range(changes_file)] +
144
[str(changes_file)] * 5) + "\n"
145
self.build_tree_contents([(f, content)])
146
self.run_bzr("commit", '-m', 'some changes')
147
assert count >= num_revisions
150
for treesize, treesize_h in [(5, "small"), (100, "moderate"),
152
for bundlefiles, bundlefiles_h in [(5, "few"), (100, "some"),
154
if bundlefiles > treesize:
156
for num_revisions in [1, 500, 1000]:
158
def test_%s_files_%s_tree_%s_revision(self):
159
self.make_parametrized_tree(%s, %s, %s)
160
branch, _ = Branch.open_containing(".")
161
revision_history = branch.revision_history()
162
bundle_text = StringIO()
163
self.time(write_bundle, branch.repository, revision_history[-1],
166
self.time(read_bundle, bundle_text)""" % (
167
bundlefiles_h, treesize_h, num_revisions,
168
treesize, num_revisions, bundlefiles)