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 

50 prefix 

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

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

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

54 logLevel : optional 

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

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

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

58 logger : `logging.Logger` 

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

60 

61 Notes 

62 ----- 

63 Logged items include: 

64 

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

66 timestamps). 

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

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

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

70 

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

72 processes are excluded. 

73 """ 

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

75 

76 

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

78 " Will be removed after v25.", 

79 version="v24", category=FutureWarning) 

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

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

82 

83 Notes 

84 ----- 

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

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

87 """ 

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