LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | List of all members
lsst.dax.apdb.timer.Timer Class Reference

Public Member Functions

def __init__ (self, str name="", bool doPrint=True)
 
Timer start (self)
 
Timer stop (self)
 
Timer dump (self)
 
str __str__ (self)
 
Timer __enter__ (self)
 
Any __exit__ (self, Optional[Type] exc_type, Any exc_val, Any exc_tb)
 

Detailed Description

Instance of this class can be used to track consumed time.

This class is also a context manager and can be used in
a `with` statement. By default it prints consumed CPU time
and real time spent in a context.

Example:

    with Timer('SelectTimer'):
        engine.execute('SELECT ...')

Definition at line 39 of file timer.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.dax.apdb.timer.Timer.__init__ (   self,
str   name = "",
bool   doPrint = True 
)
Parameters
----------
name : `str`
    Timer name, will be printed together with statistics.
doPrint : `bool`
    If True then print statistics on exist from context.

Definition at line 53 of file timer.py.

53  def __init__(self, name: str = "", doPrint: bool = True):
54  """
55  Parameters
56  ----------
57  name : `str`
58  Timer name, will be printed together with statistics.
59  doPrint : `bool`
60  If True then print statistics on exist from context.
61  """
62  self._name = name
63  self._print = doPrint
64 
65  self._startReal = -1.
66  self._startUser = -1.
67  self._startSys = -1.
68  self._sumReal = 0.
69  self._sumUser = 0.
70  self._sumSys = 0.
71 

Member Function Documentation

◆ __enter__()

Timer lsst.dax.apdb.timer.Timer.__enter__ (   self)
Enter context, start timer

Definition at line 117 of file timer.py.

117  def __enter__(self) -> Timer:
118  """
119  Enter context, start timer
120  """
121  self.start()
122  return self
123 

◆ __exit__()

Any lsst.dax.apdb.timer.Timer.__exit__ (   self,
Optional[Type]  exc_type,
Any  exc_val,
Any  exc_tb 
)
Exit context, stop and dump timer

Definition at line 124 of file timer.py.

124  def __exit__(self, exc_type: Optional[Type], exc_val: Any, exc_tb: Any) -> Any:
125  """
126  Exit context, stop and dump timer
127  """
128  if exc_type is None:
129  self.stop()
130  if self._print:
131  self.dump()
132  return False

◆ __str__()

str lsst.dax.apdb.timer.Timer.__str__ (   self)

Definition at line 103 of file timer.py.

103  def __str__(self) -> str:
104  real = self._sumReal
105  user = self._sumUser
106  sys = self._sumSys
107  if self._startReal > 0:
108  real += time.time() - self._startReal
109  ru = resource.getrusage(resource.RUSAGE_SELF)
110  user += ru.ru_utime - self._startUser
111  sys += ru.ru_stime - self._startSys
112  info = "real=%.3f user=%.3f sys=%.3f" % (real, user, sys)
113  if self._name:
114  info = self._name + ": " + info
115  return info
116 

◆ dump()

Timer lsst.dax.apdb.timer.Timer.dump (   self)
Dump timer statistics

Definition at line 96 of file timer.py.

96  def dump(self) -> Timer:
97  """
98  Dump timer statistics
99  """
100  _LOG.info("%s", self)
101  return self
102 

◆ start()

Timer lsst.dax.apdb.timer.Timer.start (   self)
Start timer.

Definition at line 72 of file timer.py.

72  def start(self) -> Timer:
73  """
74  Start timer.
75  """
76  self._startReal = time.time()
77  ru = resource.getrusage(resource.RUSAGE_SELF)
78  self._startUser = ru.ru_utime
79  self._startSys = ru.ru_stime
80  return self
81 

◆ stop()

Timer lsst.dax.apdb.timer.Timer.stop (   self)
Stop timer.

Definition at line 82 of file timer.py.

82  def stop(self) -> Timer:
83  """
84  Stop timer.
85  """
86  if self._startReal > 0:
87  self._sumReal += time.time() - self._startReal
88  ru = resource.getrusage(resource.RUSAGE_SELF)
89  self._sumUser += ru.ru_utime - self._startUser
90  self._sumSys += ru.ru_stime - self._startSys
91  self._startReal = -1.
92  self._startUser = -1.
93  self._startSys = -1.
94  return self
95 

The documentation for this class was generated from the following file: