diff options
| author | Raphael Collet <rco@odoo.com> | 2018-11-21 10:16:06 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2018-11-21 10:16:06 +0000 |
| commit | 4894419b61a62daf66452ea6c798e6867ea2ef88 (patch) | |
| tree | 740705f1bb4f4f774e864700b811e9b497b263d4 /odoo/tools/cache.py | |
| parent | baf48ee1f986bb51377cacd081697c88408d924e (diff) | |
[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
Diffstat (limited to 'odoo/tools/cache.py')
| -rw-r--r-- | odoo/tools/cache.py | 24 |
1 files 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 |
