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

12 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2022-07-09 06:14 -0700

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 typing import Any, Callable 

28 

29import lsst.utils.timer 

30from deprecated.sphinx import deprecated 

31 

32 

33@deprecated( 

34 reason="logInfo has been replaced by lsst.utils.timer.logInfo. Will be removed after v25.", 

35 version="v24", 

36 category=FutureWarning, 

37) 

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

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

40 

41 Parameters 

42 ---------- 

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

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

45 

46 - ``metadata`` an instance of `~lsst.pipe.base.TaskMetadata` (or other 

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

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

49 

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

51 or this function will do nothing. 

52 prefix : `str` 

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

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

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

56 logLevel : `int`, optional 

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

58 metadata : `lsst.pipe.base.TaskMetadata`, optional 

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

60 logger : `logging.Logger` 

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

62 

63 Notes 

64 ----- 

65 Logged items include: 

66 

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

68 timestamps). 

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

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

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

72 

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

74 processes are excluded. 

75 """ 

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

77 

78 

79@deprecated( 

80 reason="timeMethod has been replaced by lsst.utils.timer.timeMethod. Will be removed after v25.", 

81 version="v24", 

82 category=FutureWarning, 

83) 

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

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

86 

87 Notes 

88 ----- 

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

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

91 """ 

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