/brz/remove-bazaar

To get this branch, use:
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
"""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
    plugin,
22
    )
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):
29
1908.2.2 by John Arbash Meinel
Allow caching basic kernel-like trees
30
    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
31
                              link_working=False):
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
32
        """Setup a temporary tree roughly like a kernel tree.
33
        
34
        :param url: Creat the kernel like tree as a lightweight checkout
35
        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
36
        :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
37
            just hardlink the working tree. Tests must request this, because
38
            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
39
        """
1908.2.16 by John Arbash Meinel
Move all the new TreeCreator classes into separate files.
40
        from bzrlib.benchmarks.tree_creator.kernel_like import (
41
            KernelLikeTreeCreator,
42
            )
1908.2.14 by John Arbash Meinel
Hook the bench_bench.py tests up for the new classes
43
        creator = KernelLikeTreeCreator(self, link_working=link_working,
44
                                        url=url)
45
        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
46
1908.2.18 by John Arbash Meinel
I think it is actually better as simple helper functions on Benchmark
47
    def make_kernel_like_added_tree(self, root='.',
48
                                    link_working=True,
49
                                    hot_cache=True):
50
        """Make a kernel like tree, with all files added
51
52
        :param root: Where to create the files
53
        :param link_working: Instead of copying all of the working tree
54
            files, just hardlink them to the cached files. Tests can unlink
55
            files that they will change.
56
        :param hot_cache: Run through the newly created tree and make sure
57
            the stat-cache is correct. The old way of creating a freshly
58
            added tree always had a hot cache.
59
        """
60
        from bzrlib.benchmarks.tree_creator.kernel_like import (
61
            KernelLikeAddedTreeCreator,
62
            )
63
        creator = KernelLikeAddedTreeCreator(self, link_working=link_working,
64
                                             hot_cache=hot_cache)
65
        return creator.create(root=root)
66
67
    def make_kernel_like_committed_tree(self, root='.',
68
                                    link_working=True,
69
                                    link_bzr=False,
70
                                    hot_cache=True):
71
        """Make a kernel like tree, with all files added and committed
72
73
        :param root: Where to create the files
74
        :param link_working: Instead of copying all of the working tree
75
            files, just hardlink them to the cached files. Tests can unlink
76
            files that they will change.
77
        :param link_bzr: Hardlink the .bzr directory. For readonly 
78
            operations this is safe, and shaves off a lot of setup time
79
        """
80
        from bzrlib.benchmarks.tree_creator.kernel_like import (
81
            KernelLikeCommittedTreeCreator,
82
            )
83
        creator = KernelLikeCommittedTreeCreator(self,
84
                                                 link_working=link_working,
85
                                                 link_bzr=link_bzr,
86
                                                 hot_cache=hot_cache)
87
        return creator.create(root=root)
88
1934.1.16 by John Arbash Meinel
Add a cache for a kernel-like inventory
89
    def make_kernel_like_inventory(self):
90
        """Create an inventory with the properties of a kernel-like tree
91
92
        This should be equivalent to a committed kernel like tree, not
93
        just a working tree.
94
        """
95
        from bzrlib.benchmarks.tree_creator.kernel_like import (
96
            KernelLikeInventoryCreator,
97
            )
98
        creator = KernelLikeInventoryCreator(self)
99
        return creator.create()
100
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
101
    def make_many_commit_tree(self, directory_name='.',
102
                              hardlink=False):
103
        """Create a tree with many commits.
104
        
105
        No file changes are included. Not hardlinking the working tree, 
106
        because there are no working tree files.
1756.2.19 by Aaron Bentley
Add benchmarks for merged trees
107
        """
1908.2.16 by John Arbash Meinel
Move all the new TreeCreator classes into separate files.
108
        from bzrlib.benchmarks.tree_creator.simple_many_commit import (
109
            SimpleManyCommitTreeCreator,
110
            )
1908.2.15 by John Arbash Meinel
Switching many_merge and heavy_merge to new tree creator classes
111
        creator = SimpleManyCommitTreeCreator(self, link_bzr=hardlink)
112
        return creator.create(root=directory_name)
1908.2.6 by John Arbash Meinel
Allow the many_merged and many_commit trees to be cached
113
114
    def make_heavily_merged_tree(self, directory_name='.',
115
                                 hardlink=False):
116
        """Create a tree in which almost every commit is a merge.
117
       
118
        No file changes are included.  This produces two trees, 
119
        one of which is returned.  Except for the first commit, every
120
        commit in its revision-history is a merge another commit in the other
121
        tree.  Not hardlinking the working tree, because there are no working 
122
        tree files.
123
        """
1908.2.16 by John Arbash Meinel
Move all the new TreeCreator classes into separate files.
124
        from bzrlib.benchmarks.tree_creator.heavily_merged import (
125
            HeavilyMergedTreeCreator,
126
            )
1908.2.15 by John Arbash Meinel
Switching many_merge and heavy_merge to new tree creator classes
127
        creator = HeavilyMergedTreeCreator(self, link_bzr=hardlink)
128
        return creator.create(root=directory_name)
1756.2.19 by Aaron Bentley
Add benchmarks for merged trees
129
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
130
    def create_with_commits(self, num_files, num_commits, directory_name='.'):
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
131
        """Create a tree with many files and many commits. Every commit changes
132
        exactly one file.
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
133
        
134
        :param num_files: number of files to be created
135
        :param num_commits: number of commits in the newly created tree
136
        """
137
        files = ["%s/%s" % (directory_name, i) for i in range(num_files)]
138
        for fn in files:
139
            f = open(fn, "wb")
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
140
            try:
141
                f.write("some content\n")
142
            finally:
143
                f.close()
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
144
        tree = bzrdir.BzrDir.create_standalone_workingtree(directory_name)
1874.1.13 by Carl Friedrich Bolz
Typos.
145
        tree.add([str(i) for i in range(num_files)])
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
146
        tree.lock_write()
147
        try:
148
            tree.commit('initial commit')
149
            for i in range(num_commits):
150
                fn = files[i % len(files)]
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
151
                content = range(i) + [i, i, i, ""]
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
152
                f = open(fn, "wb")
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
153
                try:
154
                    f.write("\n".join([str(i) for i in content]))
155
                finally:
156
                    f.close()
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
157
                tree.commit("changing file %s" % fn)
158
        finally:
159
            tree.unlock()
160
        return tree, files
161
162
    def commit_some_revisions(self, tree, files, num_commits,
163
                              changes_per_commit):
164
        """Commit a specified number of revisions to some files in a tree,
165
        makeing a specified number of changes per commit.
166
167
        :param tree: The tree in which the changes happen.
168
        :param files: The list of files where changes should occur.
169
        :param num_commits: The number of commits
170
        :param changes_per_commit: The number of files that are touched in 
171
        each commit.
172
        """
173
        for j in range(num_commits):
174
            for i in range(changes_per_commit):
175
                fn = files[(i + j) % changes_per_commit]
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
176
                content = range(i) + [i, i, i, '']
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
177
                f = open(fn, "w")
1874.1.12 by Carl Friedrich Bolz
More fixes according to John's comments.
178
                try:
179
                    f.write("\n".join([str(k) for k in content]))
180
                finally:
181
                    f.close()
1874.1.9 by Carl Friedrich Bolz
Try to fix all the issues outline by john and Robert.
182
            tree.commit("new revision")
183
1707.2.2 by Robert Collins
Start on bench_add, an add benchtest.
184
185
def test_suite():
186
    """Build and return a TestSuite which contains benchmark tests only."""
187
    testmod_names = [ \
188
                   'bzrlib.benchmarks.bench_add',
1755.2.1 by Robert Collins
Add a benchmark for make_kernel_like_tree.
189
                   'bzrlib.benchmarks.bench_bench',
1911.2.3 by John Arbash Meinel
Moving everything into a new location so that we can cache more than just revision ids
190
                   'bzrlib.benchmarks.bench_cache_utf8',
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
191
                   'bzrlib.benchmarks.bench_checkout',
1714.1.5 by Robert Collins
Add commit benchmark.
192
                   'bzrlib.benchmarks.bench_commit',
1757.2.10 by Robert Collins
Give all inventory entries __slots__ that are useful with the current codebase.
193
                   'bzrlib.benchmarks.bench_inventory',
1756.1.7 by Aaron Bentley
Merge bzr.dev
194
                   'bzrlib.benchmarks.bench_log',
1756.1.2 by Aaron Bentley
Show logs using get_revisions
195
                   'bzrlib.benchmarks.bench_osutils',
1752.1.2 by Aaron Bentley
Benchmark the rocks command
196
                   'bzrlib.benchmarks.bench_rocks',
1714.1.4 by Robert Collins
Add new benchmarks for status and commit.
197
                   'bzrlib.benchmarks.bench_status',
1534.10.33 by Aaron Bentley
Add canonicalize_path benchmark
198
                   'bzrlib.benchmarks.bench_transform',
1732.1.11 by John Arbash Meinel
Trying multiple things to get WorkingTree.list_files time down
199
                   '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
200
                   'bzrlib.benchmarks.bench_sftp',
1934.1.1 by John Arbash Meinel
Write a benchmark for the XML serializer
201
                   'bzrlib.benchmarks.bench_xml',
1707.2.2 by Robert Collins
Start on bench_add, an add benchtest.
202
                   ]
1841.1.1 by John Arbash Meinel
Allow plugins to provide benchmarks just like they do tests
203
    suite = TestLoader().loadTestsFromModuleNames(testmod_names) 
204
205
    # Load any benchmarks from plugins
1711.2.78 by John Arbash Meinel
Cleanup the imports in bzrlib.benchmark
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())
1841.1.1 by John Arbash Meinel
Allow plugins to provide benchmarks just like they do tests
209
210
    return suite