summaryrefslogtreecommitdiff
path: root/odoo/sql_db.py
diff options
context:
space:
mode:
authorXavierDo <xdo@odoo.com>2018-09-06 15:33:25 +0200
committerXavierDo <xdo@odoo.com>2018-09-07 10:27:46 +0200
commitc44fe912329e2d4c7541ed810526d4a069f930c4 (patch)
treeafb963429dc3a6e5d05899231421b8d37a155808 /odoo/sql_db.py
parent2f033d718456d8698441620dace4647e96e99931 (diff)
[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 <moc@odoo.com>
Diffstat (limited to 'odoo/sql_db.py')
-rw-r--r--odoo/sql_db.py9
1 files changed, 6 insertions, 3 deletions
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: