13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Benchmark test suite for bzr."""
19
19
from bzrlib import (
22
from bzrlib import plugin as _mod_plugin
23
23
import bzrlib.branch
24
24
from bzrlib.tests.TestUtil import TestLoader
25
25
from bzrlib.tests.blackbox import ExternalBase
28
28
class Benchmark(ExternalBase):
29
"""A Test class which provides helpers for writing benchmark tests."""
31
30
def make_kernel_like_tree(self, url=None, root='.',
32
31
link_working=False):
33
32
"""Setup a temporary tree roughly like a kernel tree.
35
34
:param url: Creat the kernel like tree as a lightweight checkout
36
of a new branch created at url.
37
:param root: Path where the tree will be created.
35
of a new branch created at url.
38
36
:param link_working: instead of creating a new copy of all files
39
37
just hardlink the working tree. Tests must request this, because
40
38
they must break links if they want to change the files
41
:return: A newly created tree.
43
40
from bzrlib.benchmarks.tree_creator.kernel_like import (
44
41
KernelLikeTreeCreator,
77
74
:param link_working: Instead of copying all of the working tree
78
75
files, just hardlink them to the cached files. Tests can unlink
79
76
files that they will change.
80
:param link_bzr: Hardlink the .bzr directory. For readonly
77
:param link_bzr: Hardlink the .bzr directory. For readonly
81
78
operations this is safe, and shaves off a lot of setup time
83
80
from bzrlib.benchmarks.tree_creator.kernel_like import (
104
101
def make_many_commit_tree(self, directory_name='.',
106
103
"""Create a tree with many commits.
108
No file changes are included. Not hardlinking the working tree,
105
No file changes are included. Not hardlinking the working tree,
109
106
because there are no working tree files.
111
108
from bzrlib.benchmarks.tree_creator.simple_many_commit import (
117
114
def make_heavily_merged_tree(self, directory_name='.',
119
116
"""Create a tree in which almost every commit is a merge.
121
No file changes are included. This produces two trees,
118
No file changes are included. This produces two trees,
122
119
one of which is returned. Except for the first commit, every
123
120
commit in its revision-history is a merge another commit in the other
124
tree. Not hardlinking the working tree, because there are no working
121
tree. Not hardlinking the working tree, because there are no working
127
124
from bzrlib.benchmarks.tree_creator.heavily_merged import (
130
127
creator = HeavilyMergedTreeCreator(self, link_bzr=hardlink)
131
128
return creator.create(root=directory_name)
133
def create_with_commits(self, num_files, num_commits, directory_name='.',
130
def create_with_commits(self, num_files, num_commits, directory_name='.'):
135
131
"""Create a tree with many files and many commits. Every commit changes
136
132
exactly one file.
138
134
:param num_files: number of files to be created
139
135
:param num_commits: number of commits in the newly created tree
141
from bzrlib.benchmarks.tree_creator.many_commit import (
142
ManyCommitTreeCreator,
144
creator = ManyCommitTreeCreator(self, link_bzr=hardlink,
146
num_commits=num_commits)
147
tree = creator.create(root=directory_name)
148
files = ["%s/%s" % (directory_name, fn) for fn in creator.files]
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)])
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)
149
160
return tree, files
151
162
def commit_some_revisions(self, tree, files, num_commits,
156
167
:param tree: The tree in which the changes happen.
157
168
:param files: The list of files where changes should occur.
158
169
:param num_commits: The number of commits
159
:param changes_per_commit: The number of files that are touched in
170
:param changes_per_commit: The number of files that are touched in
162
173
for j in range(num_commits):
163
174
for i in range(changes_per_commit):
176
187
testmod_names = [ \
177
188
'bzrlib.benchmarks.bench_add',
178
189
'bzrlib.benchmarks.bench_bench',
179
'bzrlib.benchmarks.bench_bundle',
180
190
'bzrlib.benchmarks.bench_cache_utf8',
181
191
'bzrlib.benchmarks.bench_checkout',
182
192
'bzrlib.benchmarks.bench_commit',
183
'bzrlib.benchmarks.bench_dirstate',
184
'bzrlib.benchmarks.bench_info',
185
193
'bzrlib.benchmarks.bench_inventory',
186
'bzrlib.benchmarks.bench_knit',
187
194
'bzrlib.benchmarks.bench_log',
188
'bzrlib.benchmarks.bench_pack',
189
195
'bzrlib.benchmarks.bench_osutils',
190
196
'bzrlib.benchmarks.bench_rocks',
191
'bzrlib.benchmarks.bench_startup',
192
197
'bzrlib.benchmarks.bench_status',
193
'bzrlib.benchmarks.bench_tags',
194
198
'bzrlib.benchmarks.bench_transform',
195
199
'bzrlib.benchmarks.bench_workingtree',
196
200
'bzrlib.benchmarks.bench_sftp',
197
201
'bzrlib.benchmarks.bench_xml',
199
suite = TestLoader().loadTestsFromModuleNames(testmod_names)
203
suite = TestLoader().loadTestsFromModuleNames(testmod_names)
201
205
# Load any benchmarks from plugins
202
for name, plugin in _mod_plugin.plugins().items():
203
if getattr(plugin.module, 'bench_suite', None) is not None:
204
suite.addTest(plugin.module.bench_suite())
206
for name, module in plugin.all_plugins().items():
207
if getattr(module, 'bench_suite', None) is not None:
208
suite.addTest(module.bench_suite())