profile#
- lsst.utils.timer.profile(filename: str | None, log: LsstLoggers | None = None) Iterator[cProfile.Profile | None]#
Profile the enclosed code block and save the result to a file.
Parameters#
- filename
strorNone Filename to which to write profile (profiling disabled if
Noneor empty string).- log
logging.Loggerorlsst.utils.logging.LsstLogAdapter, optional Log object for logging the profile operations.
Yields#
- prof
cProfile.ProfileorNone If profiling is enabled, the context manager returns the
cProfile.Profileobject (otherwise it returnsNone), which allows additional control over profiling.
Examples#
You can obtain the
cProfile.Profileobject 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)'
- filename