<s> from astrolabe . interval import Interval <EOL> from metrology . instruments . histogram import HistogramExponentiallyDecaying <EOL> from metrology . instruments . meter import Meter <EOL> class Timer ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , histogram = HistogramExponentiallyDecaying ) : <EOL> self . meter = Meter ( ) <EOL> self . histogram = histogram ( ) <EOL> def clear ( self ) : <EOL> self . meter . clear ( ) <EOL> self . histogram . clear ( ) <EOL> def update ( self , duration ) : <EOL> """<STR_LIT>""" <EOL> if duration >= <NUM_LIT:0> : <EOL> self . meter . mark ( ) <EOL> self . histogram . update ( duration ) <EOL> @ property <EOL> def snapshot ( self ) : <EOL> return self . histogram . snapshot <EOL> def __enter__ ( self ) : <EOL> self . interval = Interval . now ( ) <EOL> return self <EOL> def __exit__ ( self , type , value , callback ) : <EOL> duration = self . interval . stop ( ) <EOL> self . update ( duration ) <EOL> @ property <EOL> def count ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . histogram . count <EOL> @ property <EOL> def one_minute_rate ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . meter . one_minute_rate <EOL> @ property <EOL> def five_minute_rate ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . meter . five_minute_rate <EOL> @ property <EOL> def fifteen_minute_rate ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . meter . fifteen_minute_rate <EOL> @ property <EOL> def mean_rate ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . meter . mean_rate <EOL> @ property <EOL> def min ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . histogram . min <EOL> @ property <EOL> def max ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . histogram . max <EOL> @ property <EOL> def mean ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . histogram . mean <EOL> @ property <EOL> def stddev ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . histogram . stddev <EOL> def stop ( self ) : <EOL> self . meter . stop ( ) <EOL> class UtilizationTimer ( Timer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , histogram = HistogramExponentiallyDecaying ) : <EOL> super ( UtilizationTimer , self ) . __init__ ( histogram ) <EOL> self . duration_meter = Meter ( ) <EOL> def clear ( self ) : <EOL> super ( UtilizationTimer , self ) . clear ( ) <EOL> self . duration_meter . clear ( ) <EOL> def update ( self , duration ) : <EOL> super ( UtilizationTimer , self ) . update ( duration ) <EOL> if duration >= <NUM_LIT:0> : <EOL> self . duration_meter . mark ( duration ) <EOL> @ property <EOL> def one_minute_utilization ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . duration_meter . one_minute_rate <EOL> @ property <EOL> def five_minute_utilization ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . duration_meter . five_minute_rate <EOL> @ property <EOL> def fifteen_minute_utilization ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . duration_meter . fifteen_minute_rate <EOL> @ property <EOL> def mean_utilization ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . duration_meter . mean_rate <EOL> def stop ( self ) : <EOL> super ( UtilizationTimer , self ) . stop ( ) <EOL> self . duration_meter . stop ( ) </s>
