<s> import gc <EOL> import pyev <EOL> import logbook <EOL> logger = logbook . Logger ( __name__ ) <EOL> class ObjectWatcher ( object ) : <EOL> def __init__ ( self , loop , classes = [ ] ) : <EOL> """<STR_LIT>""" <EOL> gc . set_debug ( gc . DEBUG_STATS ) <EOL> self . classes = classes <EOL> self . timer = pyev . Timer ( <NUM_LIT> , <NUM_LIT> , loop , self . print_stats ) <EOL> self . timer . start ( ) <EOL> def count ( self , cls ) : <EOL> return len ( [ obj for obj in gc . get_objects ( ) if isinstance ( obj , cls ) ] ) <EOL> def print_stats ( self , watcher , events ) : <EOL> gc . collect ( ) <EOL> logger . debug ( "<STR_LIT>" ) <EOL> for cls in self . classes : <EOL> logger . debug ( "<STR_LIT>" % ( cls . __name__ , self . count ( cls ) ) ) </s>
