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] = (), kwargs: dict[str, Any] | None = None, mem_usage: bool = False, mem_child: bool = False, mem_unit: Unit = Unit('byte'), mem_fmt: str = '.0f', force_mem_usage: bool = False) Iterator[_TimerResult]¶
Time the enclosed block and issue a log message.
- Parameters:
- log
logging.Logger, optional Logger to use to report the timer message. The root logger will be used if none is given. Is also allowed to be a
structlogbound logger.- msg
str, optional Context to include in log message.
- level
int, 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.
- prefix
str, 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.- kwargs
dict, optional Additional keyword parameters passed to the log command. If a Structlog is used then these will be added to the structured data. Otherwise they will be converted to a single string for inclusion in the log message.
- mem_usage
bool, 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_child
bool, optional Flag indication whether to include memory usage of the child processes.
- mem_unit
astropy.units.Unit, optional Unit to use when reporting the memory usage. Defaults to bytes.
- mem_fmt
str, optional Format specifier to use when displaying values related to memory usage. Defaults to ‘.0f’.
- force_mem_usage
bool, optional If
Truememory 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.
- log
- Yields:
- timer_result
_TimerResult Simple data class containing the duration of the block in seconds via the
durationproperty.
- timer_result