/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

merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
 
18
17
"""Benchmark test suite for bzr."""
19
18
 
20
 
from bzrlib import bzrdir, plugin
 
19
from bzrlib import (
 
20
    plugin,
 
21
    )
21
22
from bzrlib.tests.TestUtil import TestLoader
22
23
from bzrlib.tests.blackbox import ExternalBase
23
24
 
24
25
 
25
26
class Benchmark(ExternalBase):
26
27
 
27
 
    def make_kernel_like_tree(self, url=None):
 
28
    def make_kernel_like_tree(self, url=None, root='.',
 
29
                              link_working=False):
28
30
        """Setup a temporary tree roughly like a kernel tree.
29
31
        
30
32
        :param url: Creat the kernel like tree as a lightweight checkout
31
33
        of a new branch created at url.
32
 
        """
33
 
        # a kernel tree has ~10000 and 500 directory, with most files around 
34
 
        # 3-4 levels deep. 
35
 
        # we simulate this by three levels of dirs named 0-7, givin 512 dirs,
36
 
        # and 20 files each.
37
 
        if url is not None:
38
 
            b = bzrdir.BzrDir.create_branch_convenience(url)
39
 
            d = bzrdir.BzrDir.create('.')
40
 
            bzrlib.branch.BranchReferenceFormat().initialize(d, b)
41
 
            d.create_workingtree()
42
 
        else:
43
 
            self.run_bzr('init')
44
 
        files = []
45
 
        for outer in range(8):
46
 
            files.append("%s/" % outer)
47
 
            for middle in range(8):
48
 
                files.append("%s/%s/" % (outer, middle))
49
 
                for inner in range(8):
50
 
                    prefix = "%s/%s/%s/" % (outer, middle, inner)
51
 
                    files.append(prefix)
52
 
                    files.extend([prefix + str(foo) for foo in range(20)])
53
 
        self.build_tree(files)
54
 
 
55
 
    def make_many_commit_tree(self, directory_name='.'):
 
34
        :param link_working: instead of creating a new copy of all files
 
35
            just hardlink the working tree. Tests must request this, because
 
36
            they must break links if they want to change the files
 
37
        """
 
38
        from bzrlib.benchmarks.tree_creator.kernel_like import (
 
39
            KernelLikeTreeCreator,
 
40
            )
 
41
        creator = KernelLikeTreeCreator(self, link_working=link_working,
 
42
                                        url=url)
 
43
        return creator.create(root=root)
 
44
 
 
45
    def make_kernel_like_added_tree(self, root='.',
 
46
                                    link_working=True,
 
47
                                    hot_cache=True):
 
48
        """Make a kernel like tree, with all files added
 
49
 
 
50
        :param root: Where to create the files
 
51
        :param link_working: Instead of copying all of the working tree
 
52
            files, just hardlink them to the cached files. Tests can unlink
 
53
            files that they will change.
 
54
        :param hot_cache: Run through the newly created tree and make sure
 
55
            the stat-cache is correct. The old way of creating a freshly
 
56
            added tree always had a hot cache.
 
57
        """
 
58
        from bzrlib.benchmarks.tree_creator.kernel_like import (
 
59
            KernelLikeAddedTreeCreator,
 
60
            )
 
61
        creator = KernelLikeAddedTreeCreator(self, link_working=link_working,
 
62
                                             hot_cache=hot_cache)
 
63
        return creator.create(root=root)
 
64
 
 
65
    def make_kernel_like_committed_tree(self, root='.',
 
66
                                    link_working=True,
 
67
                                    link_bzr=False,
 
68
                                    hot_cache=True):
 
69
        """Make a kernel like tree, with all files added and committed
 
70
 
 
71
        :param root: Where to create the files
 
72
        :param link_working: Instead of copying all of the working tree
 
73
            files, just hardlink them to the cached files. Tests can unlink
 
74
            files that they will change.
 
75
        :param link_bzr: Hardlink the .bzr directory. For readonly 
 
76
            operations this is safe, and shaves off a lot of setup time
 
77
        """
 
78
        from bzrlib.benchmarks.tree_creator.kernel_like import (
 
79
            KernelLikeCommittedTreeCreator,
 
80
            )
 
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)
 
86
 
 
87
    def make_kernel_like_inventory(self):
 
88
        """Create an inventory with the properties of a kernel-like tree
 
89
 
 
90
        This should be equivalent to a committed kernel like tree, not
 
91
        just a working tree.
 
92
        """
 
93
        from bzrlib.benchmarks.tree_creator.kernel_like import (
 
94
            KernelLikeInventoryCreator,
 
95
            )
 
96
        creator = KernelLikeInventoryCreator(self)
 
97
        return creator.create()
 
98
 
 
99
    def make_many_commit_tree(self, directory_name='.',
 
100
                              hardlink=False):
56
101
        """Create a tree with many commits.
57
102
        
58
 
        No files change are included.
 
103
        No file changes are included. Not hardlinking the working tree, 
 
104
        because there are no working tree files.
59
105
        """
60
 
        tree = bzrdir.BzrDir.create_standalone_workingtree(directory_name)
61
 
        tree.lock_write()
62
 
        tree.branch.lock_write()
63
 
        tree.branch.repository.lock_write()
64
 
        try:
65
 
            for i in xrange(1000):
66
 
                tree.commit('no-changes commit %d' % i)
67
 
        finally:
68
 
            try:
69
 
                try:
70
 
                    tree.branch.repository.unlock()
71
 
                finally:
72
 
                    tree.branch.unlock()
73
 
            finally:
74
 
                tree.unlock()
75
 
        return tree
 
106
        from bzrlib.benchmarks.tree_creator.simple_many_commit import (
 
107
            SimpleManyCommitTreeCreator,
 
108
            )
 
109
        creator = SimpleManyCommitTreeCreator(self, link_bzr=hardlink)
 
110
        return creator.create(root=directory_name)
76
111
 
77
 
    def make_heavily_merged_tree(self, directory_name='.'):
 
112
    def make_heavily_merged_tree(self, directory_name='.',
 
113
                                 hardlink=False):
78
114
        """Create a tree in which almost every commit is a merge.
79
115
       
80
 
        No files change are included.  This produces two trees, 
 
116
        No file changes are included.  This produces two trees, 
81
117
        one of which is returned.  Except for the first commit, every
82
118
        commit in its revision-history is a merge another commit in the other
83
 
        tree.
 
119
        tree.  Not hardlinking the working tree, because there are no working 
 
120
        tree files.
84
121
        """
85
 
        tree = bzrdir.BzrDir.create_standalone_workingtree(directory_name)
86
 
        tree.lock_write()
87
 
        try:
88
 
            tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
89
 
            tree2.lock_write()
90
 
            try:
91
 
                for i in xrange(250):
92
 
                    revision_id = tree.commit('no-changes commit %d-a' % i)
93
 
                    tree2.branch.fetch(tree.branch, revision_id)
94
 
                    tree2.set_pending_merges([revision_id])
95
 
                    revision_id = tree2.commit('no-changes commit %d-b' % i)
96
 
                    tree.branch.fetch(tree2.branch, revision_id)
97
 
                    tree.set_pending_merges([revision_id])
98
 
                tree.set_pending_merges([])
99
 
            finally:
100
 
                tree.unlock()
101
 
        finally:
102
 
            tree2.unlock()
103
 
        return tree
 
122
        from bzrlib.benchmarks.tree_creator.heavily_merged import (
 
123
            HeavilyMergedTreeCreator,
 
124
            )
 
125
        creator = HeavilyMergedTreeCreator(self, link_bzr=hardlink)
 
126
        return creator.create(root=directory_name)
104
127
 
105
128
 
106
129
def test_suite():
109
132
                   'bzrlib.benchmarks.bench_add',
110
133
                   'bzrlib.benchmarks.bench_bench',
111
134
                   'bzrlib.benchmarks.bench_bundle',
 
135
                   'bzrlib.benchmarks.bench_cache_utf8',
112
136
                   'bzrlib.benchmarks.bench_checkout',
113
137
                   'bzrlib.benchmarks.bench_commit',
114
138
                   'bzrlib.benchmarks.bench_info',
119
143
                   'bzrlib.benchmarks.bench_status',
120
144
                   'bzrlib.benchmarks.bench_transform',
121
145
                   'bzrlib.benchmarks.bench_workingtree',
 
146
                   'bzrlib.benchmarks.bench_xml',
122
147
                   ]
123
148
    suite = TestLoader().loadTestsFromModuleNames(testmod_names) 
124
149