Coverage for python/lsst/pipe/base/timer.py: 83%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

12 statements  

1# 

2# LSST Data Management System 

3# Copyright 2008, 2009, 2010, 2011 LSST Corporation. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22"""Utilities for measuring execution time. 

23""" 

24__all__ = ["logInfo", "timeMethod"] 

25 

26import logging 

27from deprecated.sphinx import deprecated 

28from typing import Any, Callable 

29import lsst.utils.timer 

30 

31 

32@deprecated(reason="logInfo has been replaced by lsst.utils.timer.logInfo." 

33 " Will be removed after v25.", 

34 version="v24", category=FutureWarning) 

35def logInfo(obj, prefix, logLevel=logging.DEBUG, metadata=None, logger=None): 

36 """Log timer information to ``obj.metadata`` and ``obj.log``. 

37 

38 Parameters 

39 ---------- 

40 obj : `lsst.pipe.base.Task`-type or `None` 

41 A `~lsst.pipe.base.Task` or any other object with these two attributes: 

42 

43 - ``metadata`` an instance of `lsst.daf.base.PropertyList`` (or other 

44 object with ``add(name, value)`` method). 

45 - ``log`` an instance of `logging.Logger` or subclass. 

46 

47 If `None`, at least one of ``metadata`` or ``logger`` should be passed 

48 or this function will do nothing. 

49 prefix : `str` 

50 Name prefix, the resulting entries are ``CpuTime``, etc.. For example 

51 timeMethod uses ``prefix = Start`` when the method begins and 

52 ``prefix = End`` when the method ends. 

53 logLevel : `int`, optional 

54 Log level (an `logging` level constant, such as `logging.DEBUG`). 

55 metadata : `lsst.daf.base.PropertyList`, optional 

56 Metadata object to write entries to, overriding ``obj.metadata``. 

57 logger : `logging.Logger` 

58 Log object to write entries to, overriding ``obj.log``. 

59 

60 Notes 

61 ----- 

62 Logged items include: 

63 

64 - ``Utc``: UTC date in ISO format (only in metadata since log entries have 

65 timestamps). 

66 - ``CpuTime``: System + User CPU time (seconds). This should only be used 

67 in differential measurements; the time reference point is undefined. 

68 - ``MaxRss``: maximum resident set size. 

69 

70 All logged resource information is only for the current process; child 

71 processes are excluded. 

72 """ 

73 return lsst.utils.timer.logInfo(obj, prefix, logLevel=logLevel, metadata=metadata, logger=logger) 

74 

75 

76@deprecated(reason="timeMethod has been replaced by lsst.utils.timer.timeMethod." 

77 " Will be removed after v25.", 

78 version="v24", category=FutureWarning) 

79def timeMethod(*args: Any, **kwargs: Any) -> Callable: 

80 """Decorator to measure duration of a method. 

81 

82 Notes 

83 ----- 

84 This is a just a forwarding method for `lsst.utils.timer.timeMethod`. For 

85 documentation look at `lsst.utils.timer.timeMethod`. 

86 """ 

87 return lsst.utils.timer.timeMethod(*args, **kwargs)