16
16
"""Tests for bzr bundle performance."""
21
from StringIO import StringIO
18
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
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))
21
60
class BundleBenchmark(Benchmark):
23
62
The bundle tests should (also) be done at a lower level with
24
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')
26
70
def test_create_bundle_known_kernel_like_tree(self):
28
72
Create a bundle for a kernel sized tree with no ignored, unknowns,
29
73
or added and one commit."""
30
self.make_kernel_like_tree()
32
self.run_bzr('commit', '-m', 'initial import')
74
cached_make(self.make_kernel_like_tree_committed)
33
75
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
35
77
def test_create_bundle_many_commit_tree (self):
37
79
Create a bundle for a tree with many commits but no changes."""
38
self.make_many_commit_tree()
80
cached_make(self.make_many_commit_tree)
39
81
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
41
83
def test_create_bundle_heavily_merged_tree(self):
43
85
Create a bundle for a heavily merged tree."""
44
self.make_heavily_merged_tree()
86
cached_make(self.make_heavily_merged_tree)
45
87
self.time(self.run_bzr, 'bundle', '--revision', '..-1')
47
89
def test_apply_bundle_known_kernel_like_tree(self):
49
91
Create a bundle for a kernel sized tree with no ignored, unknowns,
50
92
or added and one commit."""
51
self.make_kernel_like_tree()
53
self.run_bzr('commit', '-m', 'initial import')
54
self.run_bzr('branch', '.', '../branch_a')
55
self.run_bzr('bundle', '--revision', '..-1')
93
cached_make(self.make_kernel_like_tree_committed)
56
94
f = file('../bundle', 'wb')
58
96
f.write(self.run_bzr('bundle', '--revision', '..-1')[0])
99
self.run_bzr("init", "../branch_a")
61
100
os.chdir('../branch_a')
62
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)