~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-07 21:12:32 UTC
  • mto: (1908.4.6 commit-perf)
  • mto: This revision was merged to the branch mainline in revision 1923.
  • Revision ID: john@arbash-meinel.com-20060807211232-96637b7104feace3
Add the ability to specify a benchmark cache directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
class Benchmark(ExternalBase):
35
35
 
36
 
    _cached_kernel_like_tree = None
37
 
    _cached_kernel_like_added_tree = None
38
 
    _cached_kernel_like_committed_tree = None
 
36
    CACHE_ROOT = None
 
37
 
 
38
    def get_cache_dir(self, extra):
 
39
        """Get the directory to use for caching the given object."""
 
40
 
 
41
        if Benchmark.CACHE_ROOT is None:
 
42
            Benchmark.CACHE_ROOT = osutils.pathjoin(self.TEST_ROOT, 'CACHE')
 
43
        if not os.path.isdir(Benchmark.CACHE_ROOT):
 
44
            os.mkdir(Benchmark.CACHE_ROOT)
 
45
        cache_dir = osutils.pathjoin(self.CACHE_ROOT, extra)
 
46
        return cache_dir, os.path.exists(cache_dir)
39
47
 
40
48
    def make_kernel_like_tree(self, url=None, root='.',
41
49
                              hardlink_working=False):
93
101
            self._make_kernel_files(root=root)
94
102
            return
95
103
 
96
 
        if Benchmark._cached_kernel_like_tree is None:
97
 
            cache_dir = osutils.pathjoin(self.TEST_ROOT,
98
 
                                         'cached_kernel_like_tree')
 
104
        cache_dir, is_cached = self.get_cache_dir('kernel_like_tree')
 
105
        if not is_cached:
99
106
            os.mkdir(cache_dir)
100
107
            self._make_kernel_files(root=cache_dir)
101
108
            self._protect_files(cache_dir)
102
 
            Benchmark._cached_kernel_like_tree = cache_dir
103
109
 
104
110
        # Hardlinking the target directory is *much* faster (7s => <1s).
105
 
        osutils.copy_tree(Benchmark._cached_kernel_like_tree, root,
 
111
        osutils.copy_tree(cache_dir, root,
106
112
                          handlers={'file':os.link})
107
113
 
108
114
    def _clone_tree(self, source, dest, link_bzr=False, link_working=True):
162
168
        # There isn't much underneath .bzr, so we don't support hardlinking
163
169
        # it. Testing showed there wasn't much gain, and there is potentially
164
170
        # a problem if someone modifies something underneath us.
165
 
        if Benchmark._cached_kernel_like_added_tree is None:
166
 
            cache_dir = osutils.pathjoin(self.TEST_ROOT,
167
 
                                         'cached_kernel_like_added_tree')
 
171
        cache_dir, is_cached = self.get_cache_dir('kernel_like_added_tree')
 
172
        if not is_cached:
168
173
            # Get a basic tree with working files
169
174
            tree = self.make_kernel_like_tree(root=cache_dir,
170
175
                                              hardlink_working=True)
172
177
            add.smart_add_tree(tree, [cache_dir], recurse=True, save=True)
173
178
 
174
179
            self._protect_files(cache_dir+'/.bzr')
175
 
            Benchmark._cached_kernel_like_added_tree = cache_dir
176
180
 
177
 
        self._clone_tree(Benchmark._cached_kernel_like_added_tree, root,
 
181
        self._clone_tree(cache_dir, root,
178
182
                         link_working=hardlink_working)
179
183
        return workingtree.WorkingTree.open(root)
180
184
 
190
194
        :param hardlink_bzr: Hardlink the .bzr directory. For readonly 
191
195
            operations this is safe, and shaves off a lot of setup time
192
196
        """
193
 
        if Benchmark._cached_kernel_like_committed_tree is None:
194
 
            cache_dir = osutils.pathjoin(self.TEST_ROOT,
195
 
                                         'cached_kernel_like_committed_tree')
 
197
        cache_dir, is_cached = self.get_cache_dir('kernel_like_committed_tree')
 
198
        if not is_cached:
196
199
            # Get a basic tree with working files
197
200
            tree = self.make_kernel_like_added_tree(root=cache_dir,
198
201
                                                    hardlink_working=True)
199
202
            tree.commit('first post', rev_id='r1')
200
203
 
201
204
            self._protect_files(cache_dir+'/.bzr')
202
 
            Benchmark._cached_kernel_like_committed_tree = cache_dir
203
205
 
204
206
        # Now we have a cached tree, just copy it
205
 
        self._clone_tree(Benchmark._cached_kernel_like_committed_tree, root,
 
207
        self._clone_tree(cache_dir, root,
206
208
                         link_bzr=hardlink_bzr,
207
209
                         link_working=hardlink_working)
208
210
        return workingtree.WorkingTree.open(root)