Commit 3dde917e authored by Ivan Tyagov's avatar Ivan Tyagov

Add initial implementation of statistics method that will calculate total RAM memory usage

for plugin. This method depens on python module "guppy":http://guppy-pe.sourceforge.net/
When clearing cache initialize default cache scope.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16804 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2ed3e3ab
......@@ -144,3 +144,7 @@ class DistributedRamCache(BaseCache):
## Becasue we've explicitly called this function instead of clearing specific cache
## scope we have no choice but clear whole cache.
self.clearCache()
def getCachePluginTotalMemorySize(self):
""" Calculate total RAM memory size of cache plugin. """
return 0
......@@ -29,11 +29,22 @@
"""
Local RAM based cache plugin.
"""
from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE
from BaseCache import *
import time
def calcPythonObjectMemorySize(h, i):
""" Recursive function that will 'walk' over complex python types and caclulate
their RAM memory usage. """
s = h.iso(i).size
if isinstance(i, dict):
for k, v in i.items():
s += calcPythonObjectMemorySize(h, k) + calcPythonObjectMemorySize(h, v)
elif isinstance(i, list) or isinstance(i, tuple):
for v in i:
s += calcPythonObjectMemorySize(h, v)
return s
class RamCache(BaseCache):
""" RAM based cache plugin."""
......@@ -73,7 +84,6 @@ class RamCache(BaseCache):
now = time.time()
if forceCheck or (now > (self._last_cache_expire_check_at + self.cache_expire_check_interval)):
## time to check for expired cache items
#print "EXPIRE ", self, self.cache_expire_check_interval
self._last_cache_expire_check_at = now
cache = self.getCacheStorage()
for scope in cache.keys():
......@@ -109,10 +119,23 @@ class RamCache(BaseCache):
def clearCache(self):
BaseCache.clearCache(self)
self._cache_dict = {}
self._cache_dict = {DEFAULT_CACHE_SCOPE: {}}
def clearCacheForScope(self, scope):
try:
self.getCacheStorage()[scope] = {}
except KeyError:
pass
def getCachePluginTotalMemorySize(self):
""" Calculate total RAM memory size of cache plugin.
This function depends on guppy python module:
http://guppy-pe.sourceforge.net/
"""
from guppy import hpy
h = hpy()
total_size = 0
for cache_key, cache_value in self._cache_dict[DEFAULT_CACHE_SCOPE].items():
cache_value = cache_value.getValue()
total_size += calcPythonObjectMemorySize(h, cache_value)
return total_size
......@@ -278,3 +278,7 @@ class SQLCache(BaseCache):
dbConn = self.getCacheStorage(force_reconnect=True)
cursor = self._execSQLQuery(sql_query, dbConn)
return cursor
def getCachePluginTotalMemorySize(self):
""" Calculate total RAM memory size of cache plugin. """
return 0
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