~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-17 07:52:09 UTC
  • mfrom: (1910.3.4 trivial)
  • Revision ID: pqm@pqm.ubuntu.com-20060817075209-e85a1f9e05ff8b87
(andrew) Trivial fixes to NotImplemented errors.

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
17
17
"""Benchmark test suite for bzr."""
18
18
 
19
19
from bzrlib import (
20
 
    bzrdir,
 
20
    plugin,
21
21
    )
22
 
from bzrlib import plugin as _mod_plugin
23
 
import bzrlib.branch
24
22
from bzrlib.tests.TestUtil import TestLoader
25
23
from bzrlib.tests.blackbox import ExternalBase
26
24
 
27
25
 
28
26
class Benchmark(ExternalBase):
29
 
    """A Test class which provides helpers for writing benchmark tests."""
30
27
 
31
28
    def make_kernel_like_tree(self, url=None, root='.',
32
29
                              link_working=False):
33
30
        """Setup a temporary tree roughly like a kernel tree.
34
 
 
 
31
        
35
32
        :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.
 
33
        of a new branch created at url.
38
34
        :param link_working: instead of creating a new copy of all files
39
35
            just hardlink the working tree. Tests must request this, because
40
36
            they must break links if they want to change the files
41
 
        :return: A newly created tree.
42
37
        """
43
38
        from bzrlib.benchmarks.tree_creator.kernel_like import (
44
39
            KernelLikeTreeCreator,
89
84
                                                 hot_cache=hot_cache)
90
85
        return creator.create(root=root)
91
86
 
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
87
    def make_many_commit_tree(self, directory_name='.',
105
88
                              hardlink=False):
106
89
        """Create a tree with many commits.
130
113
        creator = HeavilyMergedTreeCreator(self, link_bzr=hardlink)
131
114
        return creator.create(root=directory_name)
132
115
 
133
 
    def create_with_commits(self, num_files, num_commits, directory_name='.',
134
 
                            hardlink=False):
135
 
        """Create a tree with many files and many commits. Every commit changes
136
 
        exactly one file.
137
 
 
138
 
        :param num_files: number of files to be created
139
 
        :param num_commits: number of commits in the newly created tree
140
 
        """
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]
149
 
        return tree, files
150
 
 
151
 
    def commit_some_revisions(self, tree, files, num_commits,
152
 
                              changes_per_commit):
153
 
        """Commit a specified number of revisions to some files in a tree,
154
 
        makeing a specified number of changes per commit.
155
 
 
156
 
        :param tree: The tree in which the changes happen.
157
 
        :param files: The list of files where changes should occur.
158
 
        :param num_commits: The number of commits
159
 
        :param changes_per_commit: The number of files that are touched in
160
 
            each commit.
161
 
        """
162
 
        for j in range(num_commits):
163
 
            for i in range(changes_per_commit):
164
 
                fn = files[(i + j) % changes_per_commit]
165
 
                content = range(i) + [i, i, i, '']
166
 
                f = open(fn, "w")
167
 
                try:
168
 
                    f.write("\n".join([str(k) for k in content]))
169
 
                finally:
170
 
                    f.close()
171
 
            tree.commit("new revision")
172
 
 
173
116
 
174
117
def test_suite():
175
118
    """Build and return a TestSuite which contains benchmark tests only."""
176
119
    testmod_names = [ \
177
120
                   'bzrlib.benchmarks.bench_add',
178
121
                   'bzrlib.benchmarks.bench_bench',
179
 
                   'bzrlib.benchmarks.bench_bundle',
180
122
                   'bzrlib.benchmarks.bench_cache_utf8',
181
123
                   'bzrlib.benchmarks.bench_checkout',
182
124
                   'bzrlib.benchmarks.bench_commit',
183
 
                   'bzrlib.benchmarks.bench_dirstate',
184
 
                   'bzrlib.benchmarks.bench_info',
185
125
                   'bzrlib.benchmarks.bench_inventory',
186
 
                   'bzrlib.benchmarks.bench_knit',
187
126
                   'bzrlib.benchmarks.bench_log',
188
 
                   'bzrlib.benchmarks.bench_pack',
189
127
                   'bzrlib.benchmarks.bench_osutils',
190
128
                   'bzrlib.benchmarks.bench_rocks',
191
 
                   'bzrlib.benchmarks.bench_startup',
192
129
                   'bzrlib.benchmarks.bench_status',
193
130
                   'bzrlib.benchmarks.bench_transform',
194
131
                   'bzrlib.benchmarks.bench_workingtree',
195
 
                   'bzrlib.benchmarks.bench_sftp',
196
 
                   'bzrlib.benchmarks.bench_xml',
197
132
                   ]
198
133
    suite = TestLoader().loadTestsFromModuleNames(testmod_names) 
199
134
 
200
135
    # Load any benchmarks from plugins
201
 
    for name, plugin in _mod_plugin.plugins().items():
202
 
        if getattr(plugin.module, 'bench_suite', None) is not None:
203
 
            suite.addTest(plugin.module.bench_suite())
 
136
    for name, module in plugin.all_plugins().items():
 
137
        if getattr(module, 'bench_suite', None) is not None:
 
138
            suite.addTest(module.bench_suite())
204
139
 
205
140
    return suite