~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1756.1.3 by Aaron Bentley
Add log benchmark
2
#
3
# This program is free software; you can redistribute it and/or modify
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
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.
1756.1.3 by Aaron Bentley
Add log benchmark
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
"""Tests for tree transform performance"""
18
19
import os
20
import sys
21
22
from bzrlib.benchmarks import Benchmark
23
from bzrlib.log import log_formatter, show_log
24
from bzrlib.osutils import pathjoin
1756.2.10 by Aaron Bentley
Use cStringIO to reduce benchmark noise
25
from cStringIO import StringIO
1756.1.3 by Aaron Bentley
Add log benchmark
26
from bzrlib.transform import TreeTransform
27
from bzrlib.workingtree import WorkingTree
28
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
29
1756.2.9 by Aaron Bentley
Benchmark the time to display a screenful of log
30
class LinesDone(Exception):
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
31
    """Raised when `LineConsumer` reaches the required number of lines."""
1756.2.9 by Aaron Bentley
Benchmark the time to display a screenful of log
32
    pass
33
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
34
1756.2.9 by Aaron Bentley
Benchmark the time to display a screenful of log
35
class LineConsumer(object):
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
36
    """Count lines that are produced.
37
38
    When the required number of lines have been reached, raise `LinesDone`.
39
    """
1756.2.9 by Aaron Bentley
Benchmark the time to display a screenful of log
40
41
    def __init__(self, required_lines):
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
42
        """Create a new consumer.
43
44
        :param required_lines: How many lines must be produced.
45
        :type required_lines: integer
46
        """
1756.2.9 by Aaron Bentley
Benchmark the time to display a screenful of log
47
        self.required_lines = required_lines
48
49
    def write(self, text):
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
50
        """Write some text to the black hole.
51
52
        But count how many lines have been written.
53
54
        :param text: A string that would be written.
55
        :raise LinesDone: when the required number of lines has been reached.
56
        :return: None
57
        """
1756.2.9 by Aaron Bentley
Benchmark the time to display a screenful of log
58
        self.required_lines -= text.count('\n')
59
        if self.required_lines < 0:
60
            raise LinesDone()
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
61
1756.2.9 by Aaron Bentley
Benchmark the time to display a screenful of log
62
1756.1.3 by Aaron Bentley
Add log benchmark
63
class LogBenchmark(Benchmark):
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
64
    """Benchmarks for ``'bzr log'`` performance."""
1756.1.3 by Aaron Bentley
Add log benchmark
65
66
    def test_log(self):
2399.1.7 by John Arbash Meinel
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.
67
        """Run log in a many-commit tree."""
1908.2.7 by John Arbash Meinel
Update the benchmarks to actually use the cached trees
68
        tree = self.make_many_commit_tree(hardlink=True)
1756.1.3 by Aaron Bentley
Add log benchmark
69
        lf = log_formatter('long', to_file=StringIO())
70
        self.time(show_log, tree.branch, lf, direction='reverse')
1756.2.9 by Aaron Bentley
Benchmark the time to display a screenful of log
71
1756.2.19 by Aaron Bentley
Add benchmarks for merged trees
72
    def test_merge_log(self):
73
        """Run log in a tree with many merges"""
1908.2.7 by John Arbash Meinel
Update the benchmarks to actually use the cached trees
74
        tree = self.make_heavily_merged_tree(hardlink=True)
1756.2.19 by Aaron Bentley
Add benchmarks for merged trees
75
        lf = log_formatter('short', to_file=StringIO())
76
        self.time(show_log, tree.branch, lf, direction='reverse')
77
1756.2.9 by Aaron Bentley
Benchmark the time to display a screenful of log
78
    def test_log_screenful(self):
1756.2.15 by Aaron Bentley
Fix up benchmark comments
79
        """Simulate log --long|less"""
1756.2.11 by Aaron Bentley
Add screenful benchmark for the line log formatter
80
        self.screenful_tester('long')
81
82
    def test_log_screenful_line(self):
1756.2.15 by Aaron Bentley
Fix up benchmark comments
83
        """Simulate log --line|less"""
1756.2.11 by Aaron Bentley
Add screenful benchmark for the line log formatter
84
        self.screenful_tester('line')
85
1756.2.12 by Aaron Bentley
Add screenful benchmark for the short log formatter
86
    def test_log_screenful_short(self):
1756.2.15 by Aaron Bentley
Fix up benchmark comments
87
        """Simulate log --short|less"""
1756.2.12 by Aaron Bentley
Add screenful benchmark for the short log formatter
88
        self.screenful_tester('short')
89
1756.2.11 by Aaron Bentley
Add screenful benchmark for the line log formatter
90
    def screenful_tester(self, formatter):
1756.2.15 by Aaron Bentley
Fix up benchmark comments
91
        """Run show_log, but stop after 25 lines are generated"""
1908.2.7 by John Arbash Meinel
Update the benchmarks to actually use the cached trees
92
        tree = self.make_many_commit_tree(hardlink=True)
1756.2.9 by Aaron Bentley
Benchmark the time to display a screenful of log
93
        def log_screenful():
1756.2.11 by Aaron Bentley
Add screenful benchmark for the line log formatter
94
            lf = log_formatter(formatter, to_file=LineConsumer(25))
1756.2.9 by Aaron Bentley
Benchmark the time to display a screenful of log
95
            try:
96
                show_log(tree.branch, lf, direction='reverse')
97
            except LinesDone:
98
                pass
99
            else:
100
                raise Exception, "LinesDone not raised"
101
        self.time(log_screenful)
1756.2.14 by Aaron Bentley
Add benchmarks for the log commands
102
103
    def test_cmd_log(self):
1756.2.15 by Aaron Bentley
Fix up benchmark comments
104
        """Test execution of the log command.""" 
1908.2.7 by John Arbash Meinel
Update the benchmarks to actually use the cached trees
105
        tree = self.make_many_commit_tree(hardlink=True)
1756.2.14 by Aaron Bentley
Add benchmarks for the log commands
106
        self.time(self.run_bzr, 'log', '-r', '-4..')
107
108
    def test_cmd_log_subprocess(self):
1756.2.15 by Aaron Bentley
Fix up benchmark comments
109
        """Text startup and execution of the log command.""" 
1908.2.7 by John Arbash Meinel
Update the benchmarks to actually use the cached trees
110
        tree = self.make_many_commit_tree(hardlink=True)
1756.2.14 by Aaron Bentley
Add benchmarks for the log commands
111
        self.time(self.run_bzr_subprocess, 'log', '-r', '-4..')
1756.3.1 by Aaron Bentley
Add log --verbose benchmark
112
113
    def test_log_verbose(self):
114
        """'verbose' log -- shows file changes"""
1908.2.7 by John Arbash Meinel
Update the benchmarks to actually use the cached trees
115
        tree = self.make_many_commit_tree(hardlink=True)
1756.3.1 by Aaron Bentley
Add log --verbose benchmark
116
        lf = log_formatter('long', to_file=StringIO())
117
        self.time(show_log, tree.branch, lf, direction='reverse', verbose=True)