bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1707.2.2
by Robert Collins
Start on bench_add, an add benchtest. |
1 |
# Copyright (C) 2006 by Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
||
18 |
"""Benchmark test suite for bzr."""
|
|
19 |
||
|
1908.2.12
by John Arbash Meinel
Fix a small bug in _create_heavily_merged_tree when the target dir already exists |
20 |
import errno |
|
1908.2.2
by John Arbash Meinel
Allow caching basic kernel-like trees |
21 |
import os |
22 |
import shutil |
|
23 |
||
24 |
from bzrlib import ( |
|
25 |
add, |
|
26 |
bzrdir, |
|
27 |
osutils, |
|
28 |
plugin, |
|
29 |
workingtree, |
|
30 |
)
|
|
|
1773.4.1
by Martin Pool
Add pyflakes makefile target; fix many warnings |
31 |
from bzrlib.tests.TestUtil import TestLoader |
|
1714.1.4
by Robert Collins
Add new benchmarks for status and commit. |
32 |
from bzrlib.tests.blackbox import ExternalBase |
33 |
||
|
1841.1.1
by John Arbash Meinel
Allow plugins to provide benchmarks just like they do tests |
34 |
|
|
1714.1.4
by Robert Collins
Add new benchmarks for status and commit. |
35 |
class Benchmark(ExternalBase): |
36 |
||
|
1908.2.2
by John Arbash Meinel
Allow caching basic kernel-like trees |
37 |
def make_kernel_like_tree(self, url=None, root='.', |
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
38 |
link_working=False): |
|
1725.2.5
by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop |
39 |
"""Setup a temporary tree roughly like a kernel tree. |
40 |
|
|
41 |
:param url: Creat the kernel like tree as a lightweight checkout
|
|
42 |
of a new branch created at url.
|
|
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
43 |
:param link_working: instead of creating a new copy of all files
|
|
1908.2.2
by John Arbash Meinel
Allow caching basic kernel-like trees |
44 |
just hardlink the working tree. Tests must request this, because
|
45 |
they must break links if they want to change the files
|
|
|
1725.2.5
by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop |
46 |
"""
|
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
47 |
creator = KernelLikeTreeCreator(self, link_working=link_working, |
48 |
url=url) |
|
49 |
return creator.create(root=root) |
|
|
1908.2.5
by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test |
50 |
|
|
1908.2.2
by John Arbash Meinel
Allow caching basic kernel-like trees |
51 |
def make_kernel_like_added_tree(self, root='.', |
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
52 |
link_working=True, |
|
1908.2.9
by John Arbash Meinel
Allow pre-warming the hash-cache |
53 |
hot_cache=True): |
|
1908.2.2
by John Arbash Meinel
Allow caching basic kernel-like trees |
54 |
"""Make a kernel like tree, with all files added |
55 |
||
56 |
:param root: Where to create the files
|
|
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
57 |
:param link_working: Instead of copying all of the working tree
|
|
1908.2.2
by John Arbash Meinel
Allow caching basic kernel-like trees |
58 |
files, just hardlink them to the cached files. Tests can unlink
|
59 |
files that they will change.
|
|
|
1908.2.9
by John Arbash Meinel
Allow pre-warming the hash-cache |
60 |
:param hot_cache: Run through the newly created tree and make sure
|
61 |
the stat-cache is correct. The old way of creating a freshly
|
|
62 |
added tree always had a hot cache.
|
|
|
1908.2.2
by John Arbash Meinel
Allow caching basic kernel-like trees |
63 |
"""
|
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
64 |
creator = KernelLikeAddedTreeCreator(self, link_working=link_working, |
65 |
hot_cache=hot_cache) |
|
66 |
return creator.create(root=root) |
|
|
1908.2.5
by John Arbash Meinel
Updated bench_bench tests to test exactly what we really want to test |
67 |
|
|
1908.2.3
by John Arbash Meinel
Support caching a committed kernel-like tree, and mark hardlinked trees as readonly. |
68 |
def make_kernel_like_committed_tree(self, root='.', |
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
69 |
link_working=True, |
70 |
link_bzr=False, |
|
|
1908.2.9
by John Arbash Meinel
Allow pre-warming the hash-cache |
71 |
hot_cache=True): |
|
1908.2.3
by John Arbash Meinel
Support caching a committed kernel-like tree, and mark hardlinked trees as readonly. |
72 |
"""Make a kernel like tree, with all files added and committed |
73 |
||
74 |
:param root: Where to create the files
|
|
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
75 |
:param link_working: Instead of copying all of the working tree
|
|
1908.2.3
by John Arbash Meinel
Support caching a committed kernel-like tree, and mark hardlinked trees as readonly. |
76 |
files, just hardlink them to the cached files. Tests can unlink
|
77 |
files that they will change.
|
|
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
78 |
:param link_bzr: Hardlink the .bzr directory. For readonly
|
|
1908.2.3
by John Arbash Meinel
Support caching a committed kernel-like tree, and mark hardlinked trees as readonly. |
79 |
operations this is safe, and shaves off a lot of setup time
|
80 |
"""
|
|
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
81 |
creator = KernelLikeCommittedTreeCreator(self, |
82 |
link_working=link_working, |
|
83 |
link_bzr=link_bzr, |
|
84 |
hot_cache=hot_cache) |
|
85 |
return creator.create(root=root) |
|
|
1707.2.2
by Robert Collins
Start on bench_add, an add benchtest. |
86 |
|
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
87 |
def _create_many_commit_tree(self, root, in_cache=False): |
88 |
tree = bzrdir.BzrDir.create_standalone_workingtree(root) |
|
|
1756.1.2
by Aaron Bentley
Show logs using get_revisions |
89 |
tree.lock_write() |
90 |
try: |
|
91 |
for i in xrange(1000): |
|
92 |
tree.commit('no-changes commit %d' % i) |
|
93 |
finally: |
|
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
94 |
tree.unlock() |
95 |
if in_cache: |
|
96 |
self._protect_files(root+'/.bzr') |
|
|
1908.2.6
by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached |
97 |
|
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
98 |
return tree |
|
1908.2.6
by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached |
99 |
|
100 |
def make_many_commit_tree(self, directory_name='.', |
|
101 |
hardlink=False): |
|
102 |
"""Create a tree with many commits. |
|
103 |
|
|
104 |
No file changes are included. Not hardlinking the working tree,
|
|
105 |
because there are no working tree files.
|
|
|
1756.2.19
by Aaron Bentley
Add benchmarks for merged trees |
106 |
"""
|
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
107 |
cache_dir, is_cached = self.get_cache_dir('many_commit_tree') |
108 |
if cache_dir is None: |
|
109 |
return self._create_many_commit_tree(root=directory_name, |
|
110 |
in_cache=False) |
|
111 |
||
112 |
if not is_cached: |
|
113 |
self._create_many_commit_tree(root=cache_dir, in_cache=True) |
|
114 |
||
|
1908.2.9
by John Arbash Meinel
Allow pre-warming the hash-cache |
115 |
return self._clone_tree(cache_dir, directory_name, |
116 |
link_bzr=hardlink, |
|
117 |
hot_cache=True) |
|
|
1908.2.6
by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached |
118 |
|
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
119 |
def _create_heavily_merged_tree(self, root, in_cache=False): |
|
1908.2.12
by John Arbash Meinel
Fix a small bug in _create_heavily_merged_tree when the target dir already exists |
120 |
try: |
121 |
os.mkdir(root) |
|
122 |
except (IOError, OSError), e: |
|
123 |
if e.errno not in (errno.EEXIST,): |
|
124 |
raise
|
|
125 |
||
|
1908.2.6
by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached |
126 |
tree = bzrdir.BzrDir.create_standalone_workingtree( |
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
127 |
root + '/tree1') |
|
1756.2.19
by Aaron Bentley
Add benchmarks for merged trees |
128 |
tree.lock_write() |
129 |
try: |
|
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
130 |
tree2 = tree.bzrdir.sprout(root + '/tree2').open_workingtree() |
|
1756.2.21
by Aaron Bentley
Clean up merge log benchmark |
131 |
tree2.lock_write() |
|
1756.2.19
by Aaron Bentley
Add benchmarks for merged trees |
132 |
try: |
|
1756.2.21
by Aaron Bentley
Clean up merge log benchmark |
133 |
for i in xrange(250): |
134 |
revision_id = tree.commit('no-changes commit %d-a' % i) |
|
135 |
tree2.branch.fetch(tree.branch, revision_id) |
|
136 |
tree2.set_pending_merges([revision_id]) |
|
137 |
revision_id = tree2.commit('no-changes commit %d-b' % i) |
|
138 |
tree.branch.fetch(tree2.branch, revision_id) |
|
139 |
tree.set_pending_merges([revision_id]) |
|
140 |
tree.set_pending_merges([]) |
|
|
1756.2.19
by Aaron Bentley
Add benchmarks for merged trees |
141 |
finally: |
|
1908.2.6
by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached |
142 |
tree2.unlock() |
|
1756.2.21
by Aaron Bentley
Clean up merge log benchmark |
143 |
finally: |
|
1908.2.6
by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached |
144 |
tree.unlock() |
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
145 |
if in_cache: |
146 |
self._protect_files(root+'/tree1/.bzr') |
|
147 |
return tree |
|
|
1908.2.6
by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached |
148 |
|
149 |
def make_heavily_merged_tree(self, directory_name='.', |
|
150 |
hardlink=False): |
|
151 |
"""Create a tree in which almost every commit is a merge. |
|
152 |
|
|
153 |
No file changes are included. This produces two trees,
|
|
154 |
one of which is returned. Except for the first commit, every
|
|
155 |
commit in its revision-history is a merge another commit in the other
|
|
156 |
tree. Not hardlinking the working tree, because there are no working
|
|
157 |
tree files.
|
|
158 |
"""
|
|
|
1908.2.11
by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied |
159 |
cache_dir, is_cached = self.get_cache_dir('heavily_merged_tree') |
160 |
if cache_dir is None: |
|
161 |
# Not caching
|
|
162 |
return self._create_heavily_merged_tree(root=directory_name, |
|
163 |
in_cache=False) |
|
164 |
||
165 |
if not is_cached: |
|
166 |
self._create_heavily_merged_tree(root=cache_dir, in_cache=True) |
|
167 |
||
|
1908.2.6
by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached |
168 |
tree_dir = cache_dir + '/tree1' |
|
1908.2.9
by John Arbash Meinel
Allow pre-warming the hash-cache |
169 |
return self._clone_tree(tree_dir, directory_name, |
170 |
link_bzr=hardlink, |
|
171 |
hot_cache=True) |
|
|
1756.2.19
by Aaron Bentley
Add benchmarks for merged trees |
172 |
|
|
1707.2.2
by Robert Collins
Start on bench_add, an add benchtest. |
173 |
|
|
1908.2.13
by John Arbash Meinel
Factor out all helper functions into a tree creator class |
174 |
class TreeCreator(object): |
175 |
"""Just a basic class which is used to create various test trees""" |
|
176 |
||
177 |
CACHE_ROOT = None |
|
178 |
||
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
179 |
def __init__(self, test, tree_name, |
180 |
link_bzr=False, |
|
181 |
link_working=False, |
|
|
1908.2.13
by John Arbash Meinel
Factor out all helper functions into a tree creator class |
182 |
hot_cache=True): |
183 |
"""Instantiate a new creator object, supply the id of the tree""" |
|
184 |
||
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
185 |
self._cache_root = TreeCreator.CACHE_ROOT |
186 |
self._test = test |
|
|
1908.2.13
by John Arbash Meinel
Factor out all helper functions into a tree creator class |
187 |
self._tree_name = tree_name |
188 |
self._link_bzr = link_bzr |
|
189 |
self._link_working = link_working |
|
190 |
self._hot_cache = hot_cache |
|
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
191 |
if not osutils.hardlinks_good(): |
192 |
self._link_working = self._link_bzr = False |
|
|
1908.2.13
by John Arbash Meinel
Factor out all helper functions into a tree creator class |
193 |
|
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
194 |
def is_caching_enabled(self): |
|
1908.2.13
by John Arbash Meinel
Factor out all helper functions into a tree creator class |
195 |
"""Will we try to cache the tree we create?""" |
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
196 |
return self._cache_root is not None |
|
1908.2.13
by John Arbash Meinel
Factor out all helper functions into a tree creator class |
197 |
|
198 |
def is_cached(self): |
|
199 |
"""Is this tree already cached?""" |
|
200 |
cache_dir = self._get_cache_dir() |
|
201 |
if cache_dir is None: |
|
202 |
return False |
|
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
203 |
return os.path.exists(cache_dir) |
|
1908.2.13
by John Arbash Meinel
Factor out all helper functions into a tree creator class |
204 |
|
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
205 |
def disable_cache(self): |
206 |
"""Do not use the cache""" |
|
207 |
self._cache_root = None |
|
208 |
||
209 |
def ensure_cached(self): |
|
210 |
"""If caching, make sure the cached copy exists""" |
|
211 |
cache_dir = self._get_cache_dir() |
|
212 |
if cache_dir is None: |
|
213 |
return
|
|
214 |
||
215 |
if not self.is_cached(): |
|
216 |
self._create_tree(root=cache_dir, in_cache=True) |
|
217 |
||
|
1908.2.13
by John Arbash Meinel
Factor out all helper functions into a tree creator class |
218 |
def create(self, root): |
219 |
"""Create a new tree at 'root'. |
|
220 |
||
221 |
:return: A WorkingTree object.
|
|
222 |
"""
|
|
223 |
cache_dir = self._get_cache_dir() |
|
224 |
if cache_dir is None: |
|
225 |
# Not caching
|
|
226 |
return self._create_tree(root, in_cache=False) |
|
227 |
||
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
228 |
self.ensure_cached() |
|
1908.2.13
by John Arbash Meinel
Factor out all helper functions into a tree creator class |
229 |
|
230 |
return self._clone_cached_tree(root) |
|
231 |
||
232 |
def _get_cache_dir(self): |
|
233 |
"""Get the directory to use for caching this tree |
|
234 |
||
235 |
:return: The path to use for caching. If None, caching is disabled
|
|
236 |
"""
|
|
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
237 |
if self._cache_root is None: |
|
1908.2.13
by John Arbash Meinel
Factor out all helper functions into a tree creator class |
238 |
return None |
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
239 |
return osutils.pathjoin(self._cache_root, self._tree_name) |
|
1908.2.13
by John Arbash Meinel
Factor out all helper functions into a tree creator class |
240 |
|
241 |
def _create_tree(self, root, in_cache=False): |
|
242 |
"""Create the desired tree in the given location. |
|
243 |
||
244 |
Children should override this function to provide the actual creation
|
|
245 |
of the desired tree. This will be called by 'create()'. If it is
|
|
246 |
building a tree in the cache, before copying it to the real target,
|
|
247 |
it will pass in_cache=True
|
|
248 |
"""
|
|
249 |
raise NotImplemented(self._create_tree) |
|
250 |
||
251 |
def _clone_cached_tree(self, dest): |
|
252 |
"""Copy the contents of the cached dir into the destination |
|
253 |
Optionally hardlink certain pieces of the tree.
|
|
254 |
||
255 |
This is just meant as a helper function for child classes
|
|
256 |
||
257 |
:param dest: The destination to copy things to
|
|
258 |
"""
|
|
259 |
# We use shutil.copyfile so that we don't copy permissions
|
|
260 |
# because most of our source trees are marked readonly to
|
|
261 |
# prevent modifying in the case of hardlinks
|
|
262 |
handlers = {'file':shutil.copyfile} |
|
263 |
if osutils.hardlinks_good(): |
|
264 |
if self._link_working: |
|
265 |
if self._link_bzr: |
|
266 |
handlers = {'file':os.link} |
|
267 |
else: |
|
268 |
# Don't hardlink files inside bzr
|
|
269 |
def file_handler(source, dest): |
|
270 |
if '.bzr/' in source: |
|
271 |
shutil.copyfile(source, dest) |
|
272 |
else: |
|
273 |
os.link(source, dest) |
|
274 |
handlers = {'file':file_handler} |
|
275 |
elif self._link_bzr: |
|
276 |
# Only link files inside .bzr/
|
|
277 |
def file_handler(source, dest): |
|
278 |
if '.bzr/' in source: |
|
279 |
os.link(source, dest) |
|
280 |
else: |
|
281 |
shutil.copyfile(source, dest) |
|
282 |
handlers = {'file':file_handler} |
|
283 |
||
284 |
source = self._get_cache_dir() |
|
285 |
osutils.copy_tree(source, dest, handlers=handlers) |
|
286 |
tree = workingtree.WorkingTree.open(dest) |
|
287 |
if self._hot_cache: |
|
288 |
tree.lock_write() |
|
289 |
try: |
|
290 |
# tree._hashcache.scan() just checks and removes
|
|
291 |
# entries that are out of date
|
|
292 |
# we need to actually store new ones
|
|
293 |
for path, ie in tree.inventory.iter_entries_by_dir(): |
|
294 |
tree.get_file_sha1(ie.file_id, path) |
|
295 |
finally: |
|
296 |
tree.unlock() |
|
297 |
# If we didn't iterate the tree, the hash cache is technically
|
|
298 |
# invalid, and it would be better to remove it, but there is
|
|
299 |
# no public api for that.
|
|
300 |
return tree |
|
301 |
||
302 |
def _protect_files(self, root): |
|
303 |
"""Chmod all files underneath 'root' to prevent writing |
|
304 |
||
305 |
This is a helper function for child classes.
|
|
306 |
||
307 |
:param root: The base directory to modify
|
|
308 |
"""
|
|
309 |
for dirinfo, entries in osutils.walkdirs(root): |
|
310 |
for relpath, name, kind, st, abspath in entries: |
|
311 |
if kind == 'file': |
|
312 |
os.chmod(abspath, 0440) |
|
313 |
||
314 |
||
|
1908.2.14
by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes |
315 |
class KernelLikeTreeCreator(TreeCreator): |
316 |
"""Create a basic tree with ~10k unversioned files""" |
|
317 |
||
318 |
def __init__(self, test, link_working=False, url=None): |
|
319 |
super(KernelLikeTreeCreator, self).__init__(test, |
|
320 |
tree_name='kernel_like_tree', |
|
321 |
link_working=link_working, |
|
322 |
link_bzr=False) |
|
323 |
||
324 |
self._url = url |
|
325 |
||
326 |
def create(self, root): |
|
327 |
"""Create all the kernel files in the given location. |
|
328 |
||
329 |
This is overloaded for compatibility reasons.
|
|
330 |
"""
|
|
331 |
if self._url is not None: |
|
332 |
b = bzrdir.BzrDir.create_branch_convenience(self._url) |
|
333 |
d = bzrdir.BzrDir.create(root) |
|
334 |
bzrlib.branch.BranchReferenceFormat().initialize(d, b) |
|
335 |
tree = d.create_workingtree() |
|
336 |
else: |
|
337 |
tree = bzrdir.BzrDir.create_standalone_workingtree(root) |
|
338 |
||
339 |
if not self._link_working or not self.is_caching_enabled(): |
|
340 |
# Turns out that 'shutil.copytree()' is no faster than
|
|
341 |
# just creating them. Probably the python overhead.
|
|
342 |
# Plain _make_kernel_files takes 3-5s
|
|
343 |
# cp -a takes 3s
|
|
344 |
# using hardlinks takes < 1s.
|
|
345 |
self._create_tree(root=root, in_cache=False) |
|
346 |
return tree |
|
347 |
||
348 |
self.ensure_cached() |
|
349 |
cache_dir = self._get_cache_dir() |
|
350 |
osutils.copy_tree(cache_dir, root, |
|
351 |
handlers={'file':os.link}) |
|
352 |
return tree |
|
353 |
||
354 |
def _create_tree(self, root, in_cache=False): |
|
355 |
# a kernel tree has ~10000 and 500 directory, with most files around
|
|
356 |
# 3-4 levels deep.
|
|
357 |
# we simulate this by three levels of dirs named 0-7, givin 512 dirs,
|
|
358 |
# and 20 files each.
|
|
359 |
files = [] |
|
360 |
for outer in range(8): |
|
361 |
files.append("%s/" % outer) |
|
362 |
for middle in range(8): |
|
363 |
files.append("%s/%s/" % (outer, middle)) |
|
364 |
for inner in range(8): |
|
365 |
prefix = "%s/%s/%s/" % (outer, middle, inner) |
|
366 |
files.append(prefix) |
|
367 |
files.extend([prefix + str(foo) for foo in range(20)]) |
|
368 |
cwd = osutils.getcwd() |
|
369 |
os.chdir(root) |
|
370 |
self._test.build_tree(files) |
|
371 |
os.chdir(cwd) |
|
372 |
if in_cache: |
|
373 |
self._protect_files(root) |
|
374 |
||
375 |
||
376 |
class KernelLikeAddedTreeCreator(TreeCreator): |
|
377 |
||
378 |
def __init__(self, test, link_working=False, hot_cache=True): |
|
379 |
super(KernelLikeAddedTreeCreator, self).__init__(test, |
|
380 |
tree_name='kernel_like_added_tree', |
|
381 |
link_working=link_working, |
|
382 |
link_bzr=False, |
|
383 |
hot_cache=hot_cache) |
|
384 |
||
385 |
def _create_tree(self, root, in_cache=False): |
|
386 |
"""Create a kernel-like tree with the all files added |
|
387 |
||
388 |
:param root: The root directory to create the files
|
|
389 |
:param in_cache: Is this being created in the cache dir?
|
|
390 |
"""
|
|
391 |
kernel_creator = KernelLikeTreeCreator(self._test, |
|
392 |
link_working=in_cache) |
|
393 |
tree = kernel_creator.create(root=root) |
|
394 |
||
395 |
# Add everything to it
|
|
396 |
tree.lock_write() |
|
397 |
try: |
|
398 |
add.smart_add_tree(tree, [root], recurse=True, save=True) |
|
399 |
if in_cache: |
|
400 |
self._protect_files(root+'/.bzr') |
|
401 |
finally: |
|
402 |
tree.unlock() |
|
403 |
return tree |
|
404 |
||
405 |
||
406 |
class KernelLikeCommittedTreeCreator(TreeCreator): |
|
407 |
||
408 |
def __init__(self, test, link_working=False, link_bzr=False, |
|
409 |
hot_cache=True): |
|
410 |
super(KernelLikeCommittedTreeCreator, self).__init__(test, |
|
411 |
tree_name='kernel_like_committed_tree', |
|
412 |
link_working=link_working, |
|
413 |
link_bzr=link_bzr, |
|
414 |
hot_cache=hot_cache) |
|
415 |
||
416 |
def _create_tree(self, root, in_cache=False): |
|
417 |
"""Create a kernel-like tree with the all files added |
|
418 |
||
419 |
:param root: The root directory to create the files
|
|
420 |
:param in_cache: Is this being created in the cache dir?
|
|
421 |
"""
|
|
422 |
kernel_creator = KernelLikeAddedTreeCreator(self._test, |
|
423 |
link_working=in_cache, |
|
424 |
hot_cache=(not in_cache)) |
|
425 |
tree = kernel_creator.create(root=root) |
|
426 |
tree.commit('first post', rev_id='r1') |
|
427 |
||
428 |
if in_cache: |
|
429 |
self._protect_files(root+'/.bzr') |
|
430 |
return tree |
|
431 |
||
432 |
||
433 |
||
|
1707.2.2
by Robert Collins
Start on bench_add, an add benchtest. |
434 |
def test_suite(): |
435 |
"""Build and return a TestSuite which contains benchmark tests only.""" |
|
436 |
testmod_names = [ \ |
|
437 |
'bzrlib.benchmarks.bench_add', |
|
|
1755.2.1
by Robert Collins
Add a benchmark for make_kernel_like_tree. |
438 |
'bzrlib.benchmarks.bench_bench', |
|
1714.1.4
by Robert Collins
Add new benchmarks for status and commit. |
439 |
'bzrlib.benchmarks.bench_checkout', |
|
1714.1.5
by Robert Collins
Add commit benchmark. |
440 |
'bzrlib.benchmarks.bench_commit', |
|
1757.2.10
by Robert Collins
Give all inventory entries __slots__ that are useful with the current codebase. |
441 |
'bzrlib.benchmarks.bench_inventory', |
|
1756.1.7
by Aaron Bentley
Merge bzr.dev |
442 |
'bzrlib.benchmarks.bench_log', |
|
1756.1.2
by Aaron Bentley
Show logs using get_revisions |
443 |
'bzrlib.benchmarks.bench_osutils', |
|
1752.1.2
by Aaron Bentley
Benchmark the rocks command |
444 |
'bzrlib.benchmarks.bench_rocks', |
|
1714.1.4
by Robert Collins
Add new benchmarks for status and commit. |
445 |
'bzrlib.benchmarks.bench_status', |
|
1534.10.33
by Aaron Bentley
Add canonicalize_path benchmark |
446 |
'bzrlib.benchmarks.bench_transform', |
|
1732.1.11
by John Arbash Meinel
Trying multiple things to get WorkingTree.list_files time down |
447 |
'bzrlib.benchmarks.bench_workingtree', |
|
1707.2.2
by Robert Collins
Start on bench_add, an add benchtest. |
448 |
]
|
|
1841.1.1
by John Arbash Meinel
Allow plugins to provide benchmarks just like they do tests |
449 |
suite = TestLoader().loadTestsFromModuleNames(testmod_names) |
450 |
||
451 |
# Load any benchmarks from plugins
|
|
|
1711.2.78
by John Arbash Meinel
Cleanup the imports in bzrlib.benchmark |
452 |
for name, module in plugin.all_plugins().items(): |
453 |
if getattr(module, 'bench_suite', None) is not None: |
|
454 |
suite.addTest(module.bench_suite()) |
|
|
1841.1.1
by John Arbash Meinel
Allow plugins to provide benchmarks just like they do tests |
455 |
|
456 |
return suite |