[Erp5-report] r16804 - /erp5/trunk/products/ERP5Type/CachePlugins/
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Oct 3 17:20:30 CEST 2007
Author: ivan
Date: Wed Oct 3 17:20:30 2007
New Revision: 16804
URL: http://svn.erp5.org?rev=16804&view=rev
Log:
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.
Modified:
erp5/trunk/products/ERP5Type/CachePlugins/DistributedRamCache.py
erp5/trunk/products/ERP5Type/CachePlugins/RamCache.py
erp5/trunk/products/ERP5Type/CachePlugins/SQLCache.py
Modified: erp5/trunk/products/ERP5Type/CachePlugins/DistributedRamCache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/CachePlugins/DistributedRamCache.py?rev=16804&r1=16803&r2=16804&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/CachePlugins/DistributedRamCache.py (original)
+++ erp5/trunk/products/ERP5Type/CachePlugins/DistributedRamCache.py Wed Oct 3 17:20:30 2007
@@ -144,3 +144,7 @@
## 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
Modified: erp5/trunk/products/ERP5Type/CachePlugins/RamCache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/CachePlugins/RamCache.py?rev=16804&r1=16803&r2=16804&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/CachePlugins/RamCache.py (original)
+++ erp5/trunk/products/ERP5Type/CachePlugins/RamCache.py Wed Oct 3 17:20:30 2007
@@ -29,10 +29,21 @@
"""
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 @@
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 @@
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
Modified: erp5/trunk/products/ERP5Type/CachePlugins/SQLCache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/CachePlugins/SQLCache.py?rev=16804&r1=16803&r2=16804&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/CachePlugins/SQLCache.py (original)
+++ erp5/trunk/products/ERP5Type/CachePlugins/SQLCache.py Wed Oct 3 17:20:30 2007
@@ -278,3 +278,7 @@
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
More information about the Erp5-report
mailing list