LSSTApplications  17.0+50,17.0+84,17.0+9,18.0.0+14,18.0.0+2,18.0.0+30,18.0.0+4,18.0.0+9,18.0.0-2-ge43143a+4,18.1.0-1-g0001055,18.1.0-1-g0896a44+6,18.1.0-1-g1349e88+4,18.1.0-1-g2505f39+3,18.1.0-1-g380d4d4+4,18.1.0-1-g5e4b7ea,18.1.0-1-g85f8cd4+3,18.1.0-1-g9a6769a+2,18.1.0-1-ga1a4c1a+2,18.1.0-1-gc037db8,18.1.0-1-gd55f500+1,18.1.0-1-ge10677a+3,18.1.0-10-g73b8679e+7,18.1.0-11-g311e899+3,18.1.0-12-g0d73a3591,18.1.0-12-gc95f69a+3,18.1.0-2-g000ad9a+3,18.1.0-2-g31c43f9+3,18.1.0-2-g9c63283+4,18.1.0-2-gdf0b915+4,18.1.0-2-gf03bb23,18.1.0-3-g2e29e3d+6,18.1.0-3-g52aa583+2,18.1.0-3-g9cb968e+3,18.1.0-4-gd2e8982+6,18.1.0-5-g510c42a+3,18.1.0-5-gaeab27e+4,18.1.0-6-gdda7f3e+6,18.1.0-7-g89824ecc+4,w.2019.32
LSSTDataManagementBasePackage
Classes | Functions
lsst.pipe.base.cmdLineTask Namespace Reference

Classes

class  ButlerInitializedTaskRunner
 
class  CmdLineTask
 
class  LegacyTaskRunner
 
class  TaskRunner
 

Functions

def profile (filename, log=None)
 

Function Documentation

◆ profile()

def lsst.pipe.base.cmdLineTask.profile (   filename,
  log = None 
)
Context manager for profiling with cProfile.


Parameters
----------
filename : `str`
    Filename to which to write profile (profiling disabled if `None` or empty).
log : `lsst.log.Log`, optional
    Log object for logging the profile operations.

If profiling is enabled, the context manager returns the cProfile.Profile object (otherwise
it returns None), which allows additional control over profiling.  You can obtain this using
the "as" clause, e.g.:

    with profile(filename) as prof:
        runYourCodeHere()

The output cumulative profile can be printed with a command-line like::

    python -c 'import pstats; pstats.Stats("<filename>").sort_stats("cumtime").print_stats(30)'

Definition at line 49 of file cmdLineTask.py.

49 def profile(filename, log=None):
50  """Context manager for profiling with cProfile.
51 
52 
53  Parameters
54  ----------
55  filename : `str`
56  Filename to which to write profile (profiling disabled if `None` or empty).
57  log : `lsst.log.Log`, optional
58  Log object for logging the profile operations.
59 
60  If profiling is enabled, the context manager returns the cProfile.Profile object (otherwise
61  it returns None), which allows additional control over profiling. You can obtain this using
62  the "as" clause, e.g.:
63 
64  with profile(filename) as prof:
65  runYourCodeHere()
66 
67  The output cumulative profile can be printed with a command-line like::
68 
69  python -c 'import pstats; pstats.Stats("<filename>").sort_stats("cumtime").print_stats(30)'
70  """
71  if not filename:
72  # Nothing to do
73  yield
74  return
75  from cProfile import Profile
76  profile = Profile()
77  if log is not None:
78  log.info("Enabling cProfile profiling")
79  profile.enable()
80  yield profile
81  profile.disable()
82  profile.dump_stats(filename)
83  if log is not None:
84  log.info("cProfile stats written to %s" % filename)
85 
86 
def profile(filename, log=None)
Definition: cmdLineTask.py:49