~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-15 15:57:56 UTC
  • mfrom: (1911.3.5 add-action-55781)
  • Revision ID: pqm@pqm.ubuntu.com-20060815155756-77559a6254704822
(jam) add '--file-ids-from' to 'bzr add' (bug #55781)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
19
from bzrlib import (
 
20
    plugin,
 
21
    )
 
22
from bzrlib.tests.TestUtil import TestLoader
 
23
from bzrlib.tests.blackbox import ExternalBase
 
24
 
 
25
 
 
26
class Benchmark(ExternalBase):
 
27
 
 
28
    def make_kernel_like_tree(self, url=None, root='.',
 
29
                              link_working=False):
 
30
        """Setup a temporary tree roughly like a kernel tree.
 
31
        
 
32
        :param url: Creat the kernel like tree as a lightweight checkout
 
33
        of a new branch created at url.
 
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_many_commit_tree(self, directory_name='.',
 
88
                              hardlink=False):
 
89
        """Create a tree with many commits.
 
90
        
 
91
        No file changes are included. Not hardlinking the working tree, 
 
92
        because there are no working tree files.
 
93
        """
 
94
        from bzrlib.benchmarks.tree_creator.simple_many_commit import (
 
95
            SimpleManyCommitTreeCreator,
 
96
            )
 
97
        creator = SimpleManyCommitTreeCreator(self, link_bzr=hardlink)
 
98
        return creator.create(root=directory_name)
 
99
 
 
100
    def make_heavily_merged_tree(self, directory_name='.',
 
101
                                 hardlink=False):
 
102
        """Create a tree in which almost every commit is a merge.
 
103
       
 
104
        No file changes are included.  This produces two trees, 
 
105
        one of which is returned.  Except for the first commit, every
 
106
        commit in its revision-history is a merge another commit in the other
 
107
        tree.  Not hardlinking the working tree, because there are no working 
 
108
        tree files.
 
109
        """
 
110
        from bzrlib.benchmarks.tree_creator.heavily_merged import (
 
111
            HeavilyMergedTreeCreator,
 
112
            )
 
113
        creator = HeavilyMergedTreeCreator(self, link_bzr=hardlink)
 
114
        return creator.create(root=directory_name)
 
115
 
 
116
 
 
117
def test_suite():
 
118
    """Build and return a TestSuite which contains benchmark tests only."""
 
119
    testmod_names = [ \
 
120
                   'bzrlib.benchmarks.bench_add',
 
121
                   'bzrlib.benchmarks.bench_bench',
 
122
                   'bzrlib.benchmarks.bench_cache_utf8',
 
123
                   'bzrlib.benchmarks.bench_checkout',
 
124
                   'bzrlib.benchmarks.bench_commit',
 
125
                   'bzrlib.benchmarks.bench_inventory',
 
126
                   'bzrlib.benchmarks.bench_log',
 
127
                   'bzrlib.benchmarks.bench_osutils',
 
128
                   'bzrlib.benchmarks.bench_rocks',
 
129
                   'bzrlib.benchmarks.bench_status',
 
130
                   'bzrlib.benchmarks.bench_transform',
 
131
                   'bzrlib.benchmarks.bench_workingtree',
 
132
                   ]
 
133
    suite = TestLoader().loadTestsFromModuleNames(testmod_names) 
 
134
 
 
135
    # Load any benchmarks from plugins
 
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())
 
139
 
 
140
    return suite