32
35
self.lock.release()
38
class MemoryProfileMiddleware(object):
39
'''Paste middleware for profiling memory with heapy.'''
41
def __init__(self, app, limit=40):
43
self.lock = threading.Lock()
51
obs = sys.getobjects(0)
52
except AttributeError:
54
'Python does not have debug symbols compiled. Memory will '
60
all = sys.getrefcount(o)
62
if type(o) is str and o == '<dummy key>':
63
# avoid dictionary madness
73
ct = [(type2count[t] - self.type2count.get(t, 0),
74
type2all[t] - self.type2all.get(t, 0),
76
for t in type2count.iterkeys()]
81
logger = logging.getLogger('loggerhead-memprofile')
82
logger.debug('*' * 20)
83
logger.debug("Loggerhead Memory Profiling")
85
for delta1, delta2, t in ct:
88
logger.debug("%-55s %8s %8s" % ('', 'insts', 'refs'))
91
logger.debug("%-55s %8d %8d" % (t, delta1, delta2))
97
self.type2count = type2count
98
self.type2all = type2all
100
def __call__(self, environ, start_response):
103
# We don't want to be working with the static images
104
# TODO: There needs to be a better way to do this.
106
return self.app(environ, start_response)