~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: 2009-03-06 06:48:25 UTC
  • mfrom: (4070.8.6 debug-config)
  • Revision ID: pqm@pqm.ubuntu.com-20090306064825-kbpwggw21dygeix6
(mbp) debug_flags configuration option

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
def profile(f, *args, **kwds):
30
30
    """Run a function profile.
31
31
 
32
 
    Exceptions are not caught: If you need stats even when exceptions are to be
33
 
    raised, passing in a closure that will catch the exceptions and transform
34
 
    them appropriately for your driver function.
35
 
 
36
32
    :return: The functions return value and a stats object.
37
33
    """
38
34
    global _g_threadmap
39
35
    p = Profiler()
40
36
    p.enable(subcalls=True)
41
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.
42
42
    try:
43
 
        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
44
49
    finally:
45
50
        p.disable()
46
51
        for pp in _g_threadmap.values():