~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cmd_test_script.py

  • Committer: John Arbash Meinel
  • Date: 2010-08-05 16:27:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5374.
  • Revision ID: john@arbash-meinel.com-20100805162735-172opvx34sr5gpbl
Find a case where we are wasting a bit of memory.

Specifically the 'build_details' tuple contains a lot of wasted references,
and we hold on to one of these for each record we are fetching.
And for something like 'bzr pack', that is all keys.

For just loading all text build details on my bzr+ repository, With:
locations = b.repository.texts._index.get_build_details(b.repository.texts.keys())
This drops the memory consumption from:
WorkingSize   77604KiB
 to
WorkingSize   64640KiB

Or around 10.6MB. I worked it out to a savings of about 80 bytes/record
on data that can have hundreds of thousands of records (in 32-bit).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
"""Front-end command for shell-like test scripts.
18
 
 
19
 
See doc/developers/testing.txt for more explanations.
20
 
This module should be importable even if testtools aren't available.
21
 
"""
22
 
 
23
 
import os
24
 
 
25
 
from bzrlib import (
26
 
    commands,
27
 
    option,
28
 
    )
29
 
 
30
 
 
31
 
class cmd_test_script(commands.Command):
32
 
    """Run a shell-like test from a file."""
33
 
 
34
 
    hidden = True
35
 
    takes_args = ['infile']
36
 
    takes_options = [
37
 
        option.Option('null-output',
38
 
                       help='Null command outputs match any output.'),
39
 
        ]
40
 
 
41
 
    @commands.display_command
42
 
    def run(self, infile, null_output=False):
43
 
        # local imports to defer testtools dependency
44
 
        from bzrlib import tests
45
 
        from bzrlib.tests.script import TestCaseWithTransportAndScript
46
 
 
47
 
        f = open(infile)
48
 
        try:
49
 
            script = f.read()
50
 
        finally:
51
 
            f.close()
52
 
 
53
 
        class Test(TestCaseWithTransportAndScript):
54
 
 
55
 
            script = None # Set before running
56
 
 
57
 
            def test_it(self):
58
 
                self.run_script(script,
59
 
                                null_output_matches_anything=null_output)
60
 
 
61
 
        runner = tests.TextTestRunner(stream=self.outf)
62
 
        test = Test('test_it')
63
 
        test.path = os.path.realpath(infile)
64
 
        res = runner.run(test)
65
 
        return len(res.errors) + len(res.failures)