~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1707.2.2 by Robert Collins
Start on bench_add, an add benchtest.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1707.2.2 by Robert Collins
Start on bench_add, an add benchtest.
16
17
"""Benchmark test suite for bzr."""
18
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
19
from bzrlib import (
1874.1.10 by Carl Friedrich Bolz
Merge bzr.dev.
20
    bzrdir,
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
21
    )
2762.2.3 by Robert Collins
Missed the benchmark suite as something to adjust for the new API.
22
from bzrlib import plugin as _mod_plugin
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
23
import bzrlib.branch
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
24
from bzrlib.tests.TestUtil import TestLoader
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
25
from bzrlib.tests.blackbox import ExternalBase
26
1841.1.1 by John Arbash Meinel
Allow plugins to provide benchmarks just like they do tests
27
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
28
class Benchmark(ExternalBase):
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
29
    """A Test class which provides helpers for writing benchmark tests."""
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
30
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
31
    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
32
                              link_working=False):
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
33
        """Setup a temporary tree roughly like a kernel tree.
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
34
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
35
        :param url: Creat the kernel like tree as a lightweight checkout
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
36
            of a new branch created at url.
37
        :param root: Path where the tree will be created.
1908.2.11 by John Arbash Meinel
Change caching logic. Don't cache at all without --cache-dir being supplied
38
        :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
39
            just hardlink the working tree. Tests must request this, because
40
            they must break links if they want to change the files
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
41
        :return: A newly created tree.
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
42
        """
1908.2.16 by John Arbash Meinel
Move all the new TreeCreator classes into separate files.
43
        from bzrlib.benchmarks.tree_creator.kernel_like import (
44
            KernelLikeTreeCreator,
45
            )
1908.2.14 by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes
46
        creator = KernelLikeTreeCreator(self, link_working=link_working,
47
                                        url=url)
48
        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
49
1908.2.18 by John Arbash Meinel
I think it is actually better as simple helper functions on Benchmark
50
    def make_kernel_like_added_tree(self, root='.',
51
                                    link_working=True,
52
                                    hot_cache=True):
53
        """Make a kernel like tree, with all files added
54
55
        :param root: Where to create the files
56
        :param link_working: Instead of copying all of the working tree
57
            files, just hardlink them to the cached files. Tests can unlink
58
            files that they will change.
59
        :param hot_cache: Run through the newly created tree and make sure
60
            the stat-cache is correct. The old way of creating a freshly
61
            added tree always had a hot cache.
62
        """
63
        from bzrlib.benchmarks.tree_creator.kernel_like import (
64
            KernelLikeAddedTreeCreator,
65
            )
66
        creator = KernelLikeAddedTreeCreator(self, link_working=link_working,
67
                                             hot_cache=hot_cache)
68
        return creator.create(root=root)
69
70
    def make_kernel_like_committed_tree(self, root='.',
71
                                    link_working=True,
72
                                    link_bzr=False,
73
                                    hot_cache=True):
74
        """Make a kernel like tree, with all files added and committed
75
76
        :param root: Where to create the files
77
        :param link_working: Instead of copying all of the working tree
78
            files, just hardlink them to the cached files. Tests can unlink
79
            files that they will change.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
80
        :param link_bzr: Hardlink the .bzr directory. For readonly
1908.2.18 by John Arbash Meinel
I think it is actually better as simple helper functions on Benchmark
81
            operations this is safe, and shaves off a lot of setup time
82
        """
83
        from bzrlib.benchmarks.tree_creator.kernel_like import (
84
            KernelLikeCommittedTreeCreator,
85
            )
86
        creator = KernelLikeCommittedTreeCreator(self,
87
                                                 link_working=link_working,
88
                                                 link_bzr=link_bzr,
89
                                                 hot_cache=hot_cache)
90
        return creator.create(root=root)
91
1934.1.16 by John Arbash Meinel
Add a cache for a kernel-like inventory
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
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
104
    def make_many_commit_tree(self, directory_name='.',
105
                              hardlink=False):
106
        """Create a tree with many commits.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
107
108
        No file changes are included. Not hardlinking the working tree,
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
109
        because there are no working tree files.
1756.2.19 by Aaron Bentley
Add benchmarks for merged trees
110
        """
1908.2.16 by John Arbash Meinel
Move all the new TreeCreator classes into separate files.
111
        from bzrlib.benchmarks.tree_creator.simple_many_commit import (
112
            SimpleManyCommitTreeCreator,
113
            )
1908.2.15 by John Arbash Meinel
Switching many_merge and heavy_merge to new tree creator classes
114
        creator = SimpleManyCommitTreeCreator(self, link_bzr=hardlink)
115
        return creator.create(root=directory_name)
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
116
117
    def make_heavily_merged_tree(self, directory_name='.',
118
                                 hardlink=False):
119
        """Create a tree in which almost every commit is a merge.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
120
121
        No file changes are included.  This produces two trees,
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
122
        one of which is returned.  Except for the first commit, every
123
        commit in its revision-history is a merge another commit in the other
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
124
        tree.  Not hardlinking the working tree, because there are no working
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
125
        tree files.
126
        """
1908.2.16 by John Arbash Meinel
Move all the new TreeCreator classes into separate files.
127
        from bzrlib.benchmarks.tree_creator.heavily_merged import (
128
            HeavilyMergedTreeCreator,
129
            )
1908.2.15 by John Arbash Meinel
Switching many_merge and heavy_merge to new tree creator classes
130
        creator = HeavilyMergedTreeCreator(self, link_bzr=hardlink)
131
        return creator.create(root=directory_name)
1756.2.19 by Aaron Bentley
Add benchmarks for merged trees
132
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
133
    def create_with_commits(self, num_files, num_commits, directory_name='.',
134
                            hardlink=False):
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
135
        """Create a tree with many files and many commits. Every commit changes
136
        exactly one file.
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
137
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
138
        :param num_files: number of files to be created
139
        :param num_commits: number of commits in the newly created tree
140
        """
1908.3.14 by Carl Friedrich Bolz
Refactor the bundle benchmarks to use the existing helper functions.
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]
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
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
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
159
        :param changes_per_commit: The number of files that are touched in
160
            each commit.
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
161
        """
162
        for j in range(num_commits):
163
            for i in range(changes_per_commit):
164
                fn = files[(i + j) % changes_per_commit]
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
165
                content = range(i) + [i, i, i, '']
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
166
                f = open(fn, "w")
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
167
                try:
168
                    f.write("\n".join([str(k) for k in content]))
169
                finally:
170
                    f.close()
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
171
            tree.commit("new revision")
172
1707.2.2 by Robert Collins
Start on bench_add, an add benchtest.
173
174
def test_suite():
175
    """Build and return a TestSuite which contains benchmark tests only."""
176
    testmod_names = [ \
177
                   'bzrlib.benchmarks.bench_add',
1755.2.1 by Robert Collins
Add a benchmark for make_kernel_like_tree.
178
                   'bzrlib.benchmarks.bench_bench',
1868.1.5 by Jan Balster
benchmarks for "bzr bundle --revision ..-1"
179
                   'bzrlib.benchmarks.bench_bundle',
1911.2.3 by John Arbash Meinel
Moving everything into a new location so that we can cache more than just revision ids
180
                   'bzrlib.benchmarks.bench_cache_utf8',
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
181
                   'bzrlib.benchmarks.bench_checkout',
1714.1.5 by Robert Collins
Add commit benchmark.
182
                   'bzrlib.benchmarks.bench_commit',
2474.1.2 by John Arbash Meinel
Add benchmark tests for a couple DirState functions.
183
                   'bzrlib.benchmarks.bench_dirstate',
1868.1.3 by Jan Balster
benchmarks for "bzr info" in a kernel like tree
184
                   'bzrlib.benchmarks.bench_info',
1757.2.10 by Robert Collins
Give all inventory entries __slots__ that are useful with the current codebase.
185
                   'bzrlib.benchmarks.bench_inventory',
2484.1.2 by John Arbash Meinel
Add benchmarks for loading a knit index with a lot of records.
186
                   'bzrlib.benchmarks.bench_knit',
1756.1.7 by Aaron Bentley
Merge bzr.dev
187
                   'bzrlib.benchmarks.bench_log',
2776.2.1 by Robert Collins
25 percent time reduction in pack write logic.
188
                   'bzrlib.benchmarks.bench_pack',
1756.1.2 by Aaron Bentley
Show logs using get_revisions
189
                   'bzrlib.benchmarks.bench_osutils',
1752.1.2 by Aaron Bentley
Benchmark the rocks command
190
                   'bzrlib.benchmarks.bench_rocks',
2063.1.1 by John Arbash Meinel
spin off startup benchmarks to their own branch
191
                   'bzrlib.benchmarks.bench_startup',
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
192
                   'bzrlib.benchmarks.bench_status',
2694.5.2 by Alexander Belchenko
benchmark for tags serialization/deserialization
193
                   'bzrlib.benchmarks.bench_tags',
1534.10.33 by Aaron Bentley
Add canonicalize_path benchmark
194
                   'bzrlib.benchmarks.bench_transform',
1732.1.11 by John Arbash Meinel
Trying multiple things to get WorkingTree.list_files time down
195
                   'bzrlib.benchmarks.bench_workingtree',
1874.1.4 by Carl Friedrich Bolz
Add some benchmark for pushing and pulling via sftp, also with the slow socket
196
                   'bzrlib.benchmarks.bench_sftp',
1934.1.1 by John Arbash Meinel
Write a benchmark for the XML serializer
197
                   'bzrlib.benchmarks.bench_xml',
1707.2.2 by Robert Collins
Start on bench_add, an add benchtest.
198
                   ]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
199
    suite = TestLoader().loadTestsFromModuleNames(testmod_names)
1841.1.1 by John Arbash Meinel
Allow plugins to provide benchmarks just like they do tests
200
201
    # Load any benchmarks from plugins
2762.2.3 by Robert Collins
Missed the benchmark suite as something to adjust for the new API.
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())
1841.1.1 by John Arbash Meinel
Allow plugins to provide benchmarks just like they do tests
205
206
    return suite