lsst.dax.apdb g9290983e33+d2d81de7f7
 
Loading...
Searching...
No Matches
lsst.dax.apdb.timer.Timer Class Reference

Public Member Functions

 __init__ (self, str name, *MonAgent|logging.Logger args, _TagsType|None tags=None, int log_level=logging.INFO)
 
None add_values (self, **int|float values)
 
Timer start (self)
 
Timer stop (self)
 
Timer dump (self)
 
tuple[float, float, float] accumulated (self)
 
dict[str, int|float] as_dict (self, str prefix="")
 
str __str__ (self)
 
Timer __enter__ (self)
 
Any __exit__ (self, type|None exc_type, Any exc_val, Any exc_tb)
 

Protected Attributes

 _name = name
 
list _mon_agents = []
 
list _loggers = []
 
 _tags = tags
 
 _log_level = log_level
 
float _startReal = -1.0
 
float _startUser = -1.0
 
float _startSys = -1.0
 
float _sumReal = 0.0
 
float _sumUser = 0.0
 
float _sumSys = 0.0
 
dict _extra_values = {}
 

Detailed Description

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

Parameters
----------
name : `str`
    Timer name, will be use for reporting to both monitoring and logging.
    Typically the name should look like an identifier for ease of use with
    downstream monitoring software.
*args : `MonAgent` or `logging.Logger`
    Positional arguments can include a combination of `MonAgent` and
    `logging.Logger` instances. They will be used to report accumulated
    times on exit from context or by calling `dump` method directly.
tags : `~collections.abc.Mapping` [`str`, `str` or `int`], optional
    Keyword argument, additional tags added to monitoring report and
    logging output.
log_level : `int`, optional
    Keyword argument, level used for logging output, default is
    `logging.INFO`.

Notes
-----
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", logger):
        engine.execute('SELECT ...')

Member Function Documentation

◆ __enter__()

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

◆ __exit__()

Any lsst.dax.apdb.timer.Timer.__exit__ ( self,
type | None exc_type,
Any exc_val,
Any exc_tb )
Exit context, stop and dump timer

◆ accumulated()

tuple[float, float, float] lsst.dax.apdb.timer.Timer.accumulated ( self)
Return accumulated real, user, and system times in seconds.

◆ add_values()

None lsst.dax.apdb.timer.Timer.add_values ( self,
**int | float values )
Add values to dump together with timing information.

Parameters
----------
**values : int | float
    Key/values to add to timer information.

◆ as_dict()

dict[str, int | float] lsst.dax.apdb.timer.Timer.as_dict ( self,
str prefix = "" )
Return timers and extra values as dictionary.

◆ dump()

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

◆ start()

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

◆ stop()

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

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