timeMethod#

lsst.utils.timer.timeMethod(_func: _F) _F#
lsst.utils.timer.timeMethod(*, metadata: MutableMapping | None = None, logger: Logger | LsstLogAdapter | None = None, logLevel: int = logging.DEBUG) Callable[[_F], _F]

Measure duration of a method.

Set LSST_UTILS_DISABLE_TIMER in your environment to disable this method.

Parameters#

_funcCallable or None

The method to wrap.

metadatacollections.abc.MutableMapping, optional

Metadata to use as override if the instance object attached to this timer does not support a metadata property.

loggerlogging.Logger or lsst.utils.logging.LsstLogAdapter, optional

Logger to use when the class containing the decorated method does not have a log property.

logLevelint, optional

Log level to use when logging messages. Default is DEBUG.

Notes#

Writes various measures of time and possibly memory usage to the metadata; all items are prefixed with the function name.

Warning

This decorator only works with instance methods of any class with these attributes:

  • metadata: an instance of collections.abc.Mapping. The add method will be used if available, else entries will be added to a list.

  • log: an instance of logging.Logger or subclass.

Examples#

To use:

import lsst.utils as utils
import lsst.pipe.base as pipeBase
class FooTask(pipeBase.Task):
    pass

    @utils.timeMethod
    def run(self, ...): # or any other instance method you want to time
        pass