From 4894419b61a62daf66452ea6c798e6867ea2ef88 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 21 Nov 2018 10:16:06 +0000 Subject: [PATCH] [FIX] cache: ormcache logger The adaptation to Python 3 was done with two mistakes: the iteration on the lru cache does not return keys, and functions are not sortable. closes odoo/odoo#28870 --- odoo/tools/cache.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/odoo/tools/cache.py b/odoo/tools/cache.py index b6b23175773..a576b48c244 100644 --- a/odoo/tools/cache.py +++ b/odoo/tools/cache.py @@ -201,16 +201,22 @@ def log_ormcache_stats(sig=None, frame=None): me = threading.currentThread() me_dbname = getattr(me, 'dbname', 'n/a') - entries = defaultdict(int) - for dbname, reg in Registry.registries.items(): - for key in reg.cache: - entries[(dbname,) + key[:2]] += 1 - for key, count in sorted(entries.items()): - dbname, model_name, method = key + + for dbname, reg in sorted(Registry.registries.items()): + # set logger prefix to dbname me.dbname = dbname - stat = STAT[key] - _logger.info("%6d entries, %6d hit, %6d miss, %6d err, %4.1f%% ratio, for %s.%s", - count, stat.hit, stat.miss, stat.err, stat.ratio, model_name, method.__name__) + entries = defaultdict(int) + # beware: we use .keys() on purpose here (reg.cache is not a real dict) + for key in reg.cache.keys(): + entries[key[:2]] += 1 + # show entries sorted by model name, method name + for key in sorted(entries, key=lambda key: (key[0], key[1].__name__)): + model, method = key + stat = STAT[(dbname, model, method)] + _logger.info( + "%6d entries, %6d hit, %6d miss, %6d err, %4.1f%% ratio, for %s.%s", + entries[key], stat.hit, stat.miss, stat.err, stat.ratio, model, method.__name__, + ) me.dbname = me_dbname