From 356321ed2c4766f901532924af7c191e73d6566b Mon Sep 17 00:00:00 2001 From: Greg Laabs Date: Sat, 29 Jul 2017 17:40:04 -0700 Subject: [PATCH] Add DEBUG-level log for db row to native object conversion This is now the bottleneck (by a large margin) for big history queries, so I'm leaving this log feature in to help diagnose users with a slow history page --- homeassistant/components/recorder/util.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/recorder/util.py b/homeassistant/components/recorder/util.py index 63faf2633b1..c6390e5d8e2 100644 --- a/homeassistant/components/recorder/util.py +++ b/homeassistant/components/recorder/util.py @@ -58,10 +58,19 @@ def execute(qry): for tryno in range(0, RETRIES): try: - return [ + timer_start = time.perf_counter() + result = [ row for row in (row.to_native() for row in qry) if row is not None] + + if _LOGGER.isEnabledFor(logging.DEBUG): + elapsed = time.perf_counter() - timer_start + _LOGGER.debug('converting %d rows to native objects took %fs', + len(result), + elapsed) + + return result except SQLAlchemyError as err: _LOGGER.error("Error executing query: %s", err)