/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/__init__.py

  • Committer: Carl Friedrich Bolz
  • Date: 2006-08-18 15:18:44 UTC
  • mto: (1711.2.131 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1947.
  • Revision ID: cfbolz@gmx.de-20060818151844-4f780772ff8372f1
Rename setup method to make its intent clearer. Some PEP 8 issues.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
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
16
16
 
17
17
"""Benchmark test suite for bzr."""
18
18
 
19
19
from bzrlib import (
20
20
    bzrdir,
 
21
    plugin,
21
22
    )
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
26
26
 
27
27
 
28
28
class Benchmark(ExternalBase):
29
 
    """A Test class which provides helpers for writing benchmark tests."""
30
29
 
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.
34
 
 
 
33
        
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.
42
39
        """
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
82
79
        """
83
80
        from bzrlib.benchmarks.tree_creator.kernel_like import (
89
86
                                                 hot_cache=hot_cache)
90
87
        return creator.create(root=root)
91
88
 
92
 
    def make_kernel_like_inventory(self):
93
 
        """Create an inventory with the properties of a kernel-like tree
94
 
 
95
 
        This should be equivalent to a committed kernel like tree, not
96
 
        just a working tree.
97
 
        """
98
 
        from bzrlib.benchmarks.tree_creator.kernel_like import (
99
 
            KernelLikeInventoryCreator,
100
 
            )
101
 
        creator = KernelLikeInventoryCreator(self)
102
 
        return creator.create()
103
 
 
104
89
    def make_many_commit_tree(self, directory_name='.',
105
90
                              hardlink=False):
106
91
        """Create a tree with many commits.
107
 
 
108
 
        No file changes are included. Not hardlinking the working tree,
 
92
        
 
93
        No file changes are included. Not hardlinking the working tree, 
109
94
        because there are no working tree files.
110
95
        """
111
96
        from bzrlib.benchmarks.tree_creator.simple_many_commit import (
117
102
    def make_heavily_merged_tree(self, directory_name='.',
118
103
                                 hardlink=False):
119
104
        """Create a tree in which almost every commit is a merge.
120
 
 
121
 
        No file changes are included.  This produces two trees,
 
105
       
 
106
        No file changes are included.  This produces two trees, 
122
107
        one of which is returned.  Except for the first commit, every
123
108
        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
 
109
        tree.  Not hardlinking the working tree, because there are no working 
125
110
        tree files.
126
111
        """
127
112
        from bzrlib.benchmarks.tree_creator.heavily_merged import (
130
115
        creator = HeavilyMergedTreeCreator(self, link_bzr=hardlink)
131
116
        return creator.create(root=directory_name)
132
117
 
133
 
    def create_with_commits(self, num_files, num_commits, directory_name='.',
134
 
                            hardlink=False):
 
118
    def create_with_commits(self, num_files, num_commits, directory_name='.'):
135
119
        """Create a tree with many files and many commits. Every commit changes
136
120
        exactly one file.
137
 
 
 
121
        
138
122
        :param num_files: number of files to be created
139
123
        :param num_commits: number of commits in the newly created tree
140
124
        """
141
 
        from bzrlib.benchmarks.tree_creator.many_commit import (
142
 
            ManyCommitTreeCreator,
143
 
            )
144
 
        creator = ManyCommitTreeCreator(self, link_bzr=hardlink,
145
 
                                        num_files=num_files,
146
 
                                        num_commits=num_commits)
147
 
        tree = creator.create(root=directory_name)
148
 
        files = ["%s/%s" % (directory_name, fn) for fn in creator.files]
 
125
        files = ["%s/%s" % (directory_name, i) for i in range(num_files)]
 
126
        for fn in files:
 
127
            f = open(fn, "wb")
 
128
            try:
 
129
                f.write("some content\n")
 
130
            finally:
 
131
                f.close()
 
132
        tree = bzrdir.BzrDir.create_standalone_workingtree(directory_name)
 
133
        tree.add([str(i) for i in range(num_files)])
 
134
        tree.lock_write()
 
135
        try:
 
136
            tree.commit('initial commit')
 
137
            for i in range(num_commits):
 
138
                fn = files[i % len(files)]
 
139
                content = range(i) + [i, i, i, ""]
 
140
                f = open(fn, "wb")
 
141
                try:
 
142
                    f.write("\n".join([str(i) for i in content]))
 
143
                finally:
 
144
                    f.close()
 
145
                tree.commit("changing file %s" % fn)
 
146
        finally:
 
147
            tree.unlock()
149
148
        return tree, files
150
149
 
151
150
    def commit_some_revisions(self, tree, files, num_commits,
156
155
        :param tree: The tree in which the changes happen.
157
156
        :param files: The list of files where changes should occur.
158
157
        :param num_commits: The number of commits
159
 
        :param changes_per_commit: The number of files that are touched in
160
 
            each commit.
 
158
        :param changes_per_commit: The number of files that are touched in 
 
159
        each commit.
161
160
        """
162
161
        for j in range(num_commits):
163
162
            for i in range(changes_per_commit):
176
175
    testmod_names = [ \
177
176
                   'bzrlib.benchmarks.bench_add',
178
177
                   'bzrlib.benchmarks.bench_bench',
179
 
                   'bzrlib.benchmarks.bench_bundle',
180
178
                   'bzrlib.benchmarks.bench_cache_utf8',
181
179
                   'bzrlib.benchmarks.bench_checkout',
182
180
                   'bzrlib.benchmarks.bench_commit',
183
 
                   'bzrlib.benchmarks.bench_dirstate',
184
 
                   'bzrlib.benchmarks.bench_info',
185
181
                   'bzrlib.benchmarks.bench_inventory',
186
 
                   'bzrlib.benchmarks.bench_knit',
187
182
                   'bzrlib.benchmarks.bench_log',
188
 
                   'bzrlib.benchmarks.bench_pack',
189
183
                   'bzrlib.benchmarks.bench_osutils',
190
184
                   'bzrlib.benchmarks.bench_rocks',
191
 
                   'bzrlib.benchmarks.bench_startup',
192
185
                   'bzrlib.benchmarks.bench_status',
193
 
                   'bzrlib.benchmarks.bench_tags',
194
186
                   'bzrlib.benchmarks.bench_transform',
195
187
                   'bzrlib.benchmarks.bench_workingtree',
196
188
                   'bzrlib.benchmarks.bench_sftp',
197
 
                   'bzrlib.benchmarks.bench_xml',
198
189
                   ]
199
 
    suite = TestLoader().loadTestsFromModuleNames(testmod_names)
 
190
    suite = TestLoader().loadTestsFromModuleNames(testmod_names) 
200
191
 
201
192
    # 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())
 
193
    for name, module in plugin.all_plugins().items():
 
194
        if getattr(module, 'bench_suite', None) is not None:
 
195
            suite.addTest(module.bench_suite())
205
196
 
206
197
    return suite