14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
17
"""Benchmark test suite for bzr."""
21
from bzrlib.bzrdir import BzrDir
22
from bzrlib.tests import TestLoader
24
from bzrlib.tests.TestUtil import TestLoader
23
25
from bzrlib.tests.blackbox import ExternalBase
25
28
class Benchmark(ExternalBase):
27
def make_kernel_like_tree(self, url=None):
30
def make_kernel_like_tree(self, url=None, root='.',
28
32
"""Setup a temporary tree roughly like a kernel tree.
30
34
:param url: Creat the kernel like tree as a lightweight checkout
31
35
of a new branch created at url.
33
# a kernel tree has ~10000 and 500 directory, with most files around
35
# we simulate this by three levels of dirs named 0-7, givin 512 dirs,
38
b = bzrlib.bzrdir.BzrDir.create_branch_convenience(url)
39
d = bzrlib.bzrdir.BzrDir.create('.')
40
bzrlib.branch.BranchReferenceFormat().initialize(d, b)
41
d.create_workingtree()
45
for outer in range(8):
46
files.append("%s/" % outer)
47
for middle in range(8):
48
files.append("%s/%s/" % (outer, middle))
49
for inner in range(8):
50
prefix = "%s/%s/%s/" % (outer, middle, inner)
52
files.extend([prefix + str(foo) for foo in range(20)])
53
self.build_tree(files)
55
def make_many_commit_tree(self, directory_name='.'):
56
"""Create a tree with an egregious number of commits.
58
No files change are included.
60
tree = BzrDir.create_standalone_workingtree(directory_name)
36
:param link_working: instead of creating a new copy of all files
37
just hardlink the working tree. Tests must request this, because
38
they must break links if they want to change the files
40
from bzrlib.benchmarks.tree_creator.kernel_like import (
41
KernelLikeTreeCreator,
43
creator = KernelLikeTreeCreator(self, link_working=link_working,
45
return creator.create(root=root)
47
def make_kernel_like_added_tree(self, root='.',
50
"""Make a kernel like tree, with all files added
52
:param root: Where to create the files
53
:param link_working: Instead of copying all of the working tree
54
files, just hardlink them to the cached files. Tests can unlink
55
files that they will change.
56
:param hot_cache: Run through the newly created tree and make sure
57
the stat-cache is correct. The old way of creating a freshly
58
added tree always had a hot cache.
60
from bzrlib.benchmarks.tree_creator.kernel_like import (
61
KernelLikeAddedTreeCreator,
63
creator = KernelLikeAddedTreeCreator(self, link_working=link_working,
65
return creator.create(root=root)
67
def make_kernel_like_committed_tree(self, root='.',
71
"""Make a kernel like tree, with all files added and committed
73
:param root: Where to create the files
74
:param link_working: Instead of copying all of the working tree
75
files, just hardlink them to the cached files. Tests can unlink
76
files that they will change.
77
:param link_bzr: Hardlink the .bzr directory. For readonly
78
operations this is safe, and shaves off a lot of setup time
80
from bzrlib.benchmarks.tree_creator.kernel_like import (
81
KernelLikeCommittedTreeCreator,
83
creator = KernelLikeCommittedTreeCreator(self,
84
link_working=link_working,
87
return creator.create(root=root)
89
def make_kernel_like_inventory(self):
90
"""Create an inventory with the properties of a kernel-like tree
92
This should be equivalent to a committed kernel like tree, not
95
from bzrlib.benchmarks.tree_creator.kernel_like import (
96
KernelLikeInventoryCreator,
98
creator = KernelLikeInventoryCreator(self)
99
return creator.create()
101
def make_many_commit_tree(self, directory_name='.',
103
"""Create a tree with many commits.
105
No file changes are included. Not hardlinking the working tree,
106
because there are no working tree files.
108
from bzrlib.benchmarks.tree_creator.simple_many_commit import (
109
SimpleManyCommitTreeCreator,
111
creator = SimpleManyCommitTreeCreator(self, link_bzr=hardlink)
112
return creator.create(root=directory_name)
114
def make_heavily_merged_tree(self, directory_name='.',
116
"""Create a tree in which almost every commit is a merge.
118
No file changes are included. This produces two trees,
119
one of which is returned. Except for the first commit, every
120
commit in its revision-history is a merge another commit in the other
121
tree. Not hardlinking the working tree, because there are no working
124
from bzrlib.benchmarks.tree_creator.heavily_merged import (
125
HeavilyMergedTreeCreator,
127
creator = HeavilyMergedTreeCreator(self, link_bzr=hardlink)
128
return creator.create(root=directory_name)
130
def create_with_commits(self, num_files, num_commits, directory_name='.'):
131
"""Create a tree with many files and many commits. Every commit changes
134
:param num_files: number of files to be created
135
:param num_commits: number of commits in the newly created tree
137
files = ["%s/%s" % (directory_name, i) for i in range(num_files)]
141
f.write("some content\n")
144
tree = bzrdir.BzrDir.create_standalone_workingtree(directory_name)
145
tree.add([str(i) for i in range(num_files)])
62
tree.branch.lock_write()
63
tree.branch.repository.lock_write()
65
for i in xrange(1000):
66
tree.commit('no-changes commit %d' % i)
148
tree.commit('initial commit')
149
for i in range(num_commits):
150
fn = files[i % len(files)]
151
content = range(i) + [i, i, i, ""]
154
f.write("\n".join([str(i) for i in content]))
157
tree.commit("changing file %s" % fn)
162
def commit_some_revisions(self, tree, files, num_commits,
164
"""Commit a specified number of revisions to some files in a tree,
165
makeing a specified number of changes per commit.
167
:param tree: The tree in which the changes happen.
168
:param files: The list of files where changes should occur.
169
:param num_commits: The number of commits
170
:param changes_per_commit: The number of files that are touched in
173
for j in range(num_commits):
174
for i in range(changes_per_commit):
175
fn = files[(i + j) % changes_per_commit]
176
content = range(i) + [i, i, i, '']
70
tree.branch.repository.unlock()
179
f.write("\n".join([str(k) for k in content]))
182
tree.commit("new revision")