From c44fe912329e2d4c7541ed810526d4a069f930c4 Mon Sep 17 00:00:00 2001 From: XavierDo Date: Thu, 6 Sep 2018 15:33:25 +0200 Subject: [IMP] http,server: add query count and request times in logs When there is a performance issue, it's sometimes difficult to discover which request increased the query count or its duration. With this commit, the query count, the query time and "python and io" time are displayed in the logs at the end of each werkzeug request line. Co-authored-by: Christophe Monniez --- odoo/sql_db.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'odoo/sql_db.py') diff --git a/odoo/sql_db.py b/odoo/sql_db.py index ae1db0d6436..afa396148f0 100644 --- a/odoo/sql_db.py +++ b/odoo/sql_db.py @@ -217,10 +217,9 @@ class Cursor(object): raise ValueError("SQL query parameters should be a tuple, list or dict; got %r" % (params,)) if self.sql_log: - now = time.time() encoding = psycopg2.extensions.encodings[self.connection.encoding] _logger.debug("query: %s", self._obj.mogrify(query, params).decode(encoding, 'replace')) - + now = time.time() try: params = params or None res = self._obj.execute(query, params) @@ -231,10 +230,14 @@ class Cursor(object): # simple query count is always computed self.sql_log_count += 1 + delay = (time.time() - now) + if hasattr(threading.current_thread(), 'query_count'): + threading.current_thread().query_count += 1 + threading.current_thread().query_time += delay # advanced stats only if sql_log is enabled if self.sql_log: - delay = (time.time() - now) * 1E6 + delay *= 1E6 res_from = re_from.match(query.lower()) if res_from: -- cgit v1.2.3