~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lsprof.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

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