~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: 2007-09-14 00:42:13 UTC
  • mfrom: (2818.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070914004213-xraql0v7q1p63j81
profiling fixes - basename checking and exceptions now caught

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():
118
131
            otherwise the format is given by the filename extension.
119
132
        """
120
133
        if format is None:
121
 
            if filename.startswith('callgrind.out'):
 
134
            basename = bzrlib.osutils.basename(filename)
 
135
            if basename.startswith('callgrind.out'):
122
136
                format = "callgrind"
123
137
            else:
124
 
                ext = os.path.splitext(filename)[1]
 
138
                ext = bzrlib.osutils.splitext(filename)[1]
125
139
                if len(ext) > 1:
126
140
                    format = ext[1:]
127
141
        outfile = open(filename, 'wb')