/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/lsprof.py

  • Committer: Martin Pool
  • Date: 2007-09-14 06:31:28 UTC
  • mfrom: (2822 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2823.
  • Revision ID: mbp@sourcefrog.net-20070914063128-0p7mh6zfb4pzdg9p
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
import threading
11
11
from _lsprof import Profiler, profiler_entry
12
12
 
 
13
 
 
14
import bzrlib.osutils
 
15
 
 
16
 
13
17
__all__ = ['profile', 'Stats']
14
18
 
15
19
_g_threadmap = {}
31
35
    p = Profiler()
32
36
    p.enable(subcalls=True)
33
37
    threading.setprofile(_thread_profile)
 
38
    # Note: The except clause is needed below so that profiling data still
 
39
    # gets dumped even when exceptions are encountered. The except clause code
 
40
    # is taken straight from run_bzr_catch_errrors() in commands.py and ought
 
41
    # to be kept in sync with it.
34
42
    try:
35
 
        ret = f(*args, **kwds)
 
43
        try:
 
44
            ret = f(*args, **kwds)
 
45
        except (KeyboardInterrupt, Exception), e:
 
46
            import bzrlib.trace
 
47
            bzrlib.trace.report_exception(sys.exc_info(), sys.stderr)
 
48
            ret = 3
36
49
    finally:
37
50
        p.disable()
38
51
        for pp in _g_threadmap.values():
113
126
        :param format: 'txt' for a text representation;
114
127
            'callgrind' for calltree format;
115
128
            otherwise a pickled Python object. A format of None indicates
116
 
            that the format to use is to be found from the extension of
117
 
            filename.
 
129
            that the format to use is to be found from the filename. If
 
130
            the name starts with callgrind.out, callgrind format is used
 
131
            otherwise the format is given by the filename extension.
118
132
        """
119
133
        if format is None:
120
 
            ext = os.path.splitext(filename)[1]
121
 
            if len(ext) > 1:
122
 
                format = ext[1:]
 
134
            basename = bzrlib.osutils.basename(filename)
 
135
            if basename.startswith('callgrind.out'):
 
136
                format = "callgrind"
 
137
            else:
 
138
                ext = bzrlib.osutils.splitext(filename)[1]
 
139
                if len(ext) > 1:
 
140
                    format = ext[1:]
123
141
        outfile = open(filename, 'wb')
124
142
        try:
125
143
            if format == "callgrind":