~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/log.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Transport decorator that logs transport operations to .bzr.log."""
18
18
 
44
44
    and may be slow.
45
45
 
46
46
    Not all operations are logged yet.
47
 
 
48
 
    See also TransportTraceDecorator, that records a machine-readable log in 
49
 
    memory for eg testing.
50
47
    """
51
48
 
52
49
    def __init__(self, *args, **kw):
107
104
    def _show_result(self, before, methodname, result):
108
105
        result_len = None
109
106
        if isinstance(result, types.GeneratorType):
110
 
            # We now consume everything from the generator so that we can show
111
 
            # the results and the time it took to get them.  However, to keep
112
 
            # compatibility with callers that may specifically expect a result
113
 
            # (see <https://launchpad.net/bugs/340347>) we also return a new
114
 
            # generator, reset to the starting position.
 
107
            # eagerly pull in all the contents, so that we can measure how
 
108
            # long it takes to get them.  this does make the behaviour a bit
 
109
            # different, but we hope not noticably so
115
110
            result = list(result)
116
 
            return_result = iter(result)
117
 
        else:
118
 
            return_result = result
119
111
        if isinstance(result, (cStringIO.OutputType, StringIO.StringIO)):
120
112
            val = repr(result.getvalue())
121
113
            result_len = len(val)
130
122
        else:
131
123
            shown_result = self._shorten(self._strip_tuple_parens(result))
132
124
        mutter("  --> %s" % shown_result)
133
 
        # The log decorator no longer shows the elapsed time or transfer rate
134
 
        # because they're available in the log prefixes and the transport
135
 
        # activity display respectively.
136
 
        if False:
137
 
            elapsed = time.time() - before
138
 
            if result_len and elapsed > 0:
139
 
                # this is the rate of higher-level data, not the raw network speed
140
 
                mutter("      %9.03fs %8dKB/s" % (elapsed, result_len/elapsed/1024))
141
 
            else:
142
 
                mutter("      %9.03fs" % (elapsed))
143
 
        return return_result
 
125
        # XXX: the time may be wrong when e.g. a generator object is returned from
 
126
        # an http readv, if the object is returned before the bulk data
 
127
        # is read.
 
128
        elapsed = time.time() - before
 
129
        if result_len and elapsed > 0:
 
130
            # this is the rate of higher-level data, not the raw network speed
 
131
            mutter("      %9.03fs %8dkB/s" % (elapsed, result_len/elapsed/1024))
 
132
        else:
 
133
            mutter("      %9.03fs" % (elapsed))
 
134
        return result
144
135
 
145
136
    def _shorten(self, x):
146
137
        if len(x) > 70: