~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lsprof.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# I made one modification to profile so that it returns a pair
4
4
# instead of just the Stats object
5
5
 
6
 
from __future__ import absolute_import
7
 
 
8
6
import cPickle
9
7
import os
10
8
import sys
114
112
 
115
113
 
116
114
class Stats(object):
117
 
    """Wrapper around the collected data.
118
 
 
119
 
    A Stats instance is created when the profiler finishes. Normal
120
 
    usage is to use save() to write out the data to a file, or pprint()
121
 
    to write human-readable information to the command line.
122
 
    """
 
115
    """XXX docstring"""
123
116
 
124
117
    def __init__(self, data, threads):
125
118
        self.data = data
126
119
        self.threads = threads
127
120
 
128
121
    def sort(self, crit="inlinetime"):
129
 
        """Sort the data by the supplied critera.
130
 
 
131
 
        :param crit: the data attribute used as the sort key."""
 
122
        """XXX docstring"""
132
123
        if crit not in profiler_entry.__dict__:
133
124
            raise ValueError, "Can't sort by %s" % crit
134
125
        self.data.sort(lambda b, a: cmp(getattr(a, crit),
139
130
                                              getattr(b, crit)))
140
131
 
141
132
    def pprint(self, top=None, file=None):
142
 
        """Pretty-print the data as plain text for human consumption.
143
 
 
144
 
        :param top: only output the top n entries.
145
 
            The default value of None means output all data.
146
 
        :param file: the output file; if None, output will
147
 
            default to stdout."""
 
133
        """XXX docstring"""
148
134
        if file is None:
149
135
            file = sys.stdout
150
136
        d = self.data
277
263
        code = subentry.code
278
264
        totaltime = int(subentry.totaltime * 1000)
279
265
        #out_file.write('cob=%s\n' % (code.co_filename,))
 
266
        out_file.write('cfn=%s\n' % (label(code, True),))
280
267
        if isinstance(code, str):
281
268
            out_file.write('cfi=~\n')
282
 
            out_file.write('cfn=%s\n' % (label(code, True),))
283
269
            out_file.write('calls=%d 0\n' % (subentry.callcount,))
284
270
        else:
285
271
            out_file.write('cfi=%s\n' % (code.co_filename,))
286
 
            out_file.write('cfn=%s\n' % (label(code, True),))
287
272
            out_file.write('calls=%d %d\n' % (
288
273
                subentry.callcount, code.co_firstlineno))
289
274
        out_file.write('%d %d\n' % (lineno, totaltime))