time_this

lsst.utils.timer.time_this(log: Logger | LsstLogAdapter | None = None, msg: str | None = None, level: int = 10, prefix: str | None = 'timer', args: Iterable[Any] = (), mem_usage: bool = False, mem_child: bool = False, mem_unit: Quantity = Unit('byte'), mem_fmt: str = '.0f', force_mem_usage: bool = False) Iterator[_TimerResult]

Time the enclosed block and issue a log message.

Parameters:
loglogging.Logger, optional

Logger to use to report the timer message. The root logger will be used if none is given.

msgstr, optional

Context to include in log message.

levelint, optional

Python logging level to use to issue the log message. If the code block raises an exception the log message will include some information about the exception that occurred.

prefixstr, optional

Prefix to use to prepend to the supplied logger to create a new logger to use instead. No prefix is used if the value is set to None. Defaults to “timer”.

argsiterable of any

Additional parameters passed to the log command that should be written to msg.

mem_usagebool, optional

Flag indicating whether to include the memory usage in the report. Defaults, to False. Does nothing if the log message will not be generated.

mem_childbool, optional

Flag indication whether to include memory usage of the child processes.

mem_unitastropy.units.Unit, optional

Unit to use when reporting the memory usage. Defaults to bytes.

mem_fmtstr, optional

Format specifier to use when displaying values related to memory usage. Defaults to ‘.0f’.

force_mem_usagebool, optional

If True memory usage is always calculated even if the log message will not be delivered. Use this if you want the information recorded by the context manager.

Yields:
timer_result_TimerResult

Simple data class containing the duration of the block in seconds via the duration property.