lsst.dax.apdb g0e03ccb3e3+1224bbe97e
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
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)
 
Timer start (self)
 
Timer stop (self)
 
Timer dump (self)
 
tuple[float, float, float] accumulated (self)
 
dict[str, 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
 
 _tags
 
 _log_level
 
 _startReal
 
 _startUser
 
 _startSys
 
 _sumReal
 
 _sumUser
 
 _sumSys
 

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.

◆ as_dict()

dict[str, float] lsst.dax.apdb.timer.Timer.as_dict ( self,
str prefix = "" )
Return accumulated real, user, and system times 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: