Commit 9e543d76 authored by Julien Muchembled's avatar Julien Muchembled

client: dump cache stats on SIGRTMIN+2

parent 06a64d80
...@@ -139,6 +139,10 @@ class Application(ThreadedApplication): ...@@ -139,6 +139,10 @@ class Application(ThreadedApplication):
self._getMasterConnection() self._getMasterConnection()
return self.__getattribute__(attr) return self.__getattribute__(attr)
def log(self):
super(Application, self).log()
logging.info("%r", self._cache)
@property @property
def txn_contexts(self): def txn_contexts(self):
# do not iter lazily to avoid race condition # do not iter lazily to avoid race condition
......
...@@ -80,6 +80,16 @@ class ClientCache(object): ...@@ -80,6 +80,16 @@ class ClientCache(object):
self._size = 0 self._size = 0
self._history_size = 0 self._history_size = 0
def __repr__(self):
return ("<%s history_size=%s oid_count=%s size=%s time=%s"
" queue_length=%r (life_time=%s max_history_size=%s"
" max_size=%s)>") % (
self.__class__.__name__, self._history_size,
len(self._oid_dict), self._size, self._time,
[sum(1 for x in self._iterQueue(x))
for x in xrange(len(self._queue_list))],
self._life_time, self._max_history_size, self._max_size)
def _iterQueue(self, level): def _iterQueue(self, level):
"""for debugging purpose""" """for debugging purpose"""
if level < len(self._queue_list): if level < len(self._queue_list):
...@@ -255,6 +265,7 @@ class ClientCache(object): ...@@ -255,6 +265,7 @@ class ClientCache(object):
def test(self): def test(self):
cache = ClientCache() cache = ClientCache()
repr(cache)
self.assertEqual(cache.load(1, 10), None) self.assertEqual(cache.load(1, 10), None)
self.assertEqual(cache.load(1, None), None) self.assertEqual(cache.load(1, None), None)
cache.invalidate(1, 10) cache.invalidate(1, 10)
...@@ -277,6 +288,7 @@ def test(self): ...@@ -277,6 +288,7 @@ def test(self):
cache.store(1, '20', 20, 21) cache.store(1, '20', 20, 21)
self.assertEqual([5, 10, 15, 20], [x.tid for x in cache._oid_dict[1]]) self.assertEqual([5, 10, 15, 20], [x.tid for x in cache._oid_dict[1]])
self.assertRaises(AssertionError, cache.store, 1, '20', 20, None) self.assertRaises(AssertionError, cache.store, 1, '20', 20, None)
repr(cache)
if __name__ == '__main__': if __name__ == '__main__':
import unittest import unittest
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment