~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-15 02:30:07 UTC
  • mto: This revision was merged to the branch mainline in revision 1923.
  • Revision ID: john@arbash-meinel.com-20060815023007-198de42e2dce63fe
Switching many_merge and heavy_merge to new tree creator classes

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
                                                 hot_cache=hot_cache)
85
85
        return creator.create(root=root)
86
86
 
87
 
    def _create_many_commit_tree(self, root, in_cache=False):
88
 
        tree = bzrdir.BzrDir.create_standalone_workingtree(root)
89
 
        tree.lock_write()
90
 
        try:
91
 
            for i in xrange(1000):
92
 
                tree.commit('no-changes commit %d' % i)
93
 
        finally:
94
 
            tree.unlock()
95
 
        if in_cache:
96
 
            self._protect_files(root+'/.bzr')
97
 
 
98
 
        return tree
99
 
 
100
87
    def make_many_commit_tree(self, directory_name='.',
101
88
                              hardlink=False):
102
89
        """Create a tree with many commits.
104
91
        No file changes are included. Not hardlinking the working tree, 
105
92
        because there are no working tree files.
106
93
        """
107
 
        cache_dir, is_cached = self.get_cache_dir('many_commit_tree')
108
 
        if cache_dir is None:
109
 
            return self._create_many_commit_tree(root=directory_name,
110
 
                                                 in_cache=False)
111
 
 
112
 
        if not is_cached:
113
 
            self._create_many_commit_tree(root=cache_dir, in_cache=True)
114
 
 
115
 
        return self._clone_tree(cache_dir, directory_name,
116
 
                                link_bzr=hardlink,
117
 
                                hot_cache=True)
118
 
 
119
 
    def _create_heavily_merged_tree(self, root, in_cache=False):
120
 
        try:
121
 
            os.mkdir(root)
122
 
        except (IOError, OSError), e:
123
 
            if e.errno not in (errno.EEXIST,):
124
 
                raise
125
 
 
126
 
        tree = bzrdir.BzrDir.create_standalone_workingtree(
127
 
                root + '/tree1')
128
 
        tree.lock_write()
129
 
        try:
130
 
            tree2 = tree.bzrdir.sprout(root + '/tree2').open_workingtree()
131
 
            tree2.lock_write()
132
 
            try:
133
 
                for i in xrange(250):
134
 
                    revision_id = tree.commit('no-changes commit %d-a' % i)
135
 
                    tree2.branch.fetch(tree.branch, revision_id)
136
 
                    tree2.set_pending_merges([revision_id])
137
 
                    revision_id = tree2.commit('no-changes commit %d-b' % i)
138
 
                    tree.branch.fetch(tree2.branch, revision_id)
139
 
                    tree.set_pending_merges([revision_id])
140
 
                tree.set_pending_merges([])
141
 
            finally:
142
 
                tree2.unlock()
143
 
        finally:
144
 
            tree.unlock()
145
 
        if in_cache:
146
 
            self._protect_files(root+'/tree1/.bzr')
147
 
        return tree
 
94
        creator = SimpleManyCommitTreeCreator(self, link_bzr=hardlink)
 
95
        return creator.create(root=directory_name)
148
96
 
149
97
    def make_heavily_merged_tree(self, directory_name='.',
150
98
                                 hardlink=False):
156
104
        tree.  Not hardlinking the working tree, because there are no working 
157
105
        tree files.
158
106
        """
159
 
        cache_dir, is_cached = self.get_cache_dir('heavily_merged_tree')
160
 
        if cache_dir is None:
161
 
            # Not caching
162
 
            return self._create_heavily_merged_tree(root=directory_name,
163
 
                                                    in_cache=False)
164
 
 
165
 
        if not is_cached:
166
 
            self._create_heavily_merged_tree(root=cache_dir, in_cache=True)
167
 
 
168
 
        tree_dir = cache_dir + '/tree1'
169
 
        return self._clone_tree(tree_dir, directory_name,
170
 
                                link_bzr=hardlink,
171
 
                                hot_cache=True)
 
107
        creator = HeavilyMergedTreeCreator(self, link_bzr=hardlink)
 
108
        return creator.create(root=directory_name)
172
109
 
173
110
 
174
111
class TreeCreator(object):
404
341
 
405
342
 
406
343
class KernelLikeCommittedTreeCreator(TreeCreator):
 
344
    """Create a tree with ~10K files, and a single commit adding all of them"""
407
345
 
408
346
    def __init__(self, test, link_working=False, link_bzr=False,
409
347
                 hot_cache=True):
414
352
            hot_cache=hot_cache)
415
353
 
416
354
    def _create_tree(self, root, in_cache=False):
417
 
        """Create a kernel-like tree with the all files added
 
355
        """Create a kernel-like tree with all files committed
418
356
 
419
357
        :param root: The root directory to create the files
420
358
        :param in_cache: Is this being created in the cache dir?
430
368
        return tree
431
369
 
432
370
 
 
371
class SimpleManyCommitTreeCreator(TreeCreator):
 
372
    """Create an empty tree with lots of commits"""
 
373
 
 
374
    def __init__(self, test, link_bzr=False):
 
375
        super(SimpleManyCommitTreeCreator, self).__init__(test,
 
376
            tree_name='many_commit_tree',
 
377
            link_bzr=link_bzr,
 
378
            link_working=False,
 
379
            hot_cache=True)
 
380
 
 
381
    def _create_tree(self, root, in_cache=False):
 
382
        tree = bzrdir.BzrDir.create_standalone_workingtree(root)
 
383
        tree.lock_write()
 
384
        try:
 
385
            for i in xrange(1000):
 
386
                tree.commit('no-changes commit %d' % i)
 
387
        finally:
 
388
            tree.unlock()
 
389
        if in_cache:
 
390
            self._protect_files(root+'/.bzr')
 
391
 
 
392
        return tree
 
393
 
 
394
 
 
395
class HeavilyMergedTreeCreator(TreeCreator):
 
396
    """Create a tree in which almost every commit is a merge.
 
397
   
 
398
    No file changes are included.  This produces two trees, 
 
399
    one of which is returned.  Except for the first commit, every
 
400
    commit in its revision-history is a merge of another commit in the other
 
401
    tree.  
 
402
    Not hardlinking the working tree, because there are no working tree files.
 
403
    """
 
404
 
 
405
    def __init__(self, test, link_bzr=True):
 
406
        super(HeavilyMergedTreeCreator, self).__init__(test,
 
407
            tree_name='heavily_merged_tree',
 
408
            link_bzr=link_bzr,
 
409
            link_working=False,
 
410
            hot_cache=True)
 
411
 
 
412
    def _create_tree(self, root, in_cache=False):
 
413
        try:
 
414
            os.mkdir(root)
 
415
        except (IOError, OSError), e:
 
416
            if e.errno not in (errno.EEXIST,):
 
417
                raise
 
418
 
 
419
        tree = bzrdir.BzrDir.create_standalone_workingtree(root)
 
420
        tree.lock_write()
 
421
        try:
 
422
            tree2 = tree.bzrdir.sprout(root + '/tree2').open_workingtree()
 
423
            tree2.lock_write()
 
424
            try:
 
425
                for i in xrange(250):
 
426
                    revision_id = tree.commit('no-changes commit %d-a' % i)
 
427
                    tree2.branch.fetch(tree.branch, revision_id)
 
428
                    tree2.set_pending_merges([revision_id])
 
429
                    revision_id = tree2.commit('no-changes commit %d-b' % i)
 
430
                    tree.branch.fetch(tree2.branch, revision_id)
 
431
                    tree.set_pending_merges([revision_id])
 
432
                tree.set_pending_merges([])
 
433
            finally:
 
434
                tree2.unlock()
 
435
        finally:
 
436
            tree.unlock()
 
437
        if in_cache:
 
438
            self._protect_files(root+'/.bzr')
 
439
        return tree
 
440
 
433
441
 
434
442
def test_suite():
435
443
    """Build and return a TestSuite which contains benchmark tests only."""