Home | Trees | Indices | Help |
---|
|
1 # -*- coding: utf-8 -*- 2 # Elisa - Home multimedia server 3 # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 4 # All rights reserved. 5 # 6 # This file is available under one of two license agreements. 7 # 8 # This file is licensed under the GPL version 3. 9 # See "LICENSE.GPL" in the root of this distribution including a special 10 # exception to use Elisa with Fluendo's plugins. 11 # 12 # The GPL part of Elisa is also available under a commercial licensing 13 # agreement from Fluendo. 14 # See "LICENSE.Elisa" in the root directory of this distribution package 15 # for details on that license. 16 17 18 __maintainer__ = 'Lionel Martin <lionel@fluendo.com>' 19 20 import gc 21237426 """ 27 return a dict: 28 key: classname of the instance 29 value: (refcount, instances) 30 """ 31 d = {} 32 gc.collect() 33 all_objects = gc.get_objects() 34 35 def class_filter_function(obj): 36 return isinstance(obj, class_filter)37 38 if class_filter != None: 39 all_objects = filter(class_filter_function, all_objects) 40 41 for obj in all_objects: 42 try: 43 if hasattr(obj, '__class__'): 44 class_name = obj.__class__ 45 else: 46 class_name = str(obj)[0:50] 47 if d.has_key(class_name): 48 refcount = d[class_name][0] + 1 49 instances = d[class_name][1] 50 instances.append(obj) 51 d[class_name] = (refcount, instances) 52 else: 53 refcount = 1 54 instances = [obj] 55 d[class_name] = (refcount, instances) 56 except Exception, e: 57 print e 58 pass 59 60 # apply snapshot and cut the dict 61 for key in d.keys(): 62 refcount = d[key][0] 63 if refcount > min_count: 64 if snapshot != None and snapshot.has_key(key): 65 new_refcount = refcount - snapshot[key][0] 66 if new_refcount == 0: 67 del d[key] 68 else: 69 d[key] = (new_refcount, d[key][1]) 70 else: 71 del d[key] 72 73 return d
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0beta1 on Wed Jan 16 19:10:33 2008 | http://epydoc.sourceforge.net |