log time delay of domain setup in info level (#7808)

* log time delay of domain setup in info level

 * when setup problems appear, it's difficult to debug which are the components that took a lot to set up. This minimal change goes further than the 'slow setup warning' and measures the setup time interval for each domain.

* use timer as in helpers/entity
This commit is contained in:
Eugenio Panadero 2017-06-02 07:44:44 +02:00 committed by Paulus Schoutsen
parent beb8c05d91
commit 2065426b16

View File

@ -3,6 +3,7 @@ import asyncio
import logging
import logging.handlers
import os
from timeit import default_timer as timer
from types import ModuleType
from typing import Optional, Dict
@ -175,6 +176,7 @@ def _async_setup_component(hass: core.HomeAssistant,
async_comp = hasattr(component, 'async_setup')
start = timer()
_LOGGER.info("Setting up %s", domain)
warn_task = hass.loop.call_later(
SLOW_SETUP_WARNING, _LOGGER.warning,
@ -191,7 +193,9 @@ def _async_setup_component(hass: core.HomeAssistant,
async_notify_setup_error(hass, domain, True)
return False
finally:
end = timer()
warn_task.cancel()
_LOGGER.info("Setup of domain %s took %.1f seconds.", domain, end - start)
if result is False:
log_error("Component failed to initialize.")