<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> class StatsCounter ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _stat_counters = { } <EOL> def count ( self , namespace = None , ** kwargs ) : <EOL> namespace = namespace or "<STR_LIT:None>" <EOL> if namespace not in self . _stat_counters : <EOL> self . _stat_counters [ namespace ] = { } <EOL> stats = self . _stat_counters [ namespace ] <EOL> for key , value in kwargs . iteritems ( ) : <EOL> if key not in stats : <EOL> stats [ key ] = value <EOL> else : <EOL> stats [ key ] += value <EOL> def print_stats ( self , stats = None ) : <EOL> stats = stats or self . _stat_counters <EOL> import pprint <EOL> pprint . pprint ( stats ) <EOL> def get_stats ( self ) : <EOL> import copy <EOL> return copy . deepcopy ( self . _stat_counters ) <EOL> def diff_stats ( self , stat_new , stat_old ) : <EOL> diff_stat = { } <EOL> for ckey , cval in stat_new . iteritems ( ) : <EOL> if ckey in stat_old : <EOL> cstat = { } <EOL> diff_stat [ ckey ] = cstat <EOL> oval = stat_old [ ckey ] <EOL> for vkey , vval in cval . iteritems ( ) : <EOL> if vkey in oval : <EOL> cstat [ vkey ] = cval [ vkey ] - oval [ vkey ] <EOL> else : <EOL> cstat [ vkey ] = cval [ vkey ] <EOL> else : <EOL> diff_stat [ ckey ] = cval . copy ( ) <EOL> return diff_stat </s>
