~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lsprof.py

(vila) Fix bzrlib.tests.test_gpg.TestVerify.test_verify_revoked_signature
 with recent versions of gpg. (Vincent Ladeuil)

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
 
6
8
import cPickle
7
9
import os
8
10
import sys
112
114
 
113
115
 
114
116
class Stats(object):
115
 
    """XXX docstring"""
 
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
    """
116
123
 
117
124
    def __init__(self, data, threads):
118
125
        self.data = data
119
126
        self.threads = threads
120
127
 
121
128
    def sort(self, crit="inlinetime"):
122
 
        """XXX docstring"""
 
129
        """Sort the data by the supplied critera.
 
130
 
 
131
        :param crit: the data attribute used as the sort key."""
123
132
        if crit not in profiler_entry.__dict__:
124
133
            raise ValueError, "Can't sort by %s" % crit
125
134
        self.data.sort(lambda b, a: cmp(getattr(a, crit),
130
139
                                              getattr(b, crit)))
131
140
 
132
141
    def pprint(self, top=None, file=None):
133
 
        """XXX docstring"""
 
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."""
134
148
        if file is None:
135
149
            file = sys.stdout
136
150
        d = self.data
263
277
        code = subentry.code
264
278
        totaltime = int(subentry.totaltime * 1000)
265
279
        #out_file.write('cob=%s\n' % (code.co_filename,))
266
 
        out_file.write('cfn=%s\n' % (label(code, True),))
267
280
        if isinstance(code, str):
268
281
            out_file.write('cfi=~\n')
 
282
            out_file.write('cfn=%s\n' % (label(code, True),))
269
283
            out_file.write('calls=%d 0\n' % (subentry.callcount,))
270
284
        else:
271
285
            out_file.write('cfi=%s\n' % (code.co_filename,))
 
286
            out_file.write('cfn=%s\n' % (label(code, True),))
272
287
            out_file.write('calls=%d %d\n' % (
273
288
                subentry.callcount, code.co_firstlineno))
274
289
        out_file.write('%d %d\n' % (lineno, totaltime))