Refactor integration startup time to show wall clock time (#113707)

* Refactor setup time tracking to exclude time waiting on other operations

We now exclude the import time and th time waiting on
base platforms to setup from the setup times

* tweak

* tweak

* tweak

* tweak

* adjust

* fixes

* fixes

* preen

* preen

* tweak

* tweak

* adjust

* tweak

* reduce

* do not count integrtion platforms against their parent integration

* handle legacy tts platforms

* stt as well

* one more wait

* use the same pattern in all the legacy

* fix tts and stt legacy

* fix

* fix

* reduce

* preen

* entity comp does not wait for platforms

* scene blocks as well

* fix test

* test fixes

* coverage

* coverage

* coverage

* fix test

* Update tests/test_setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update tests/test_setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* strip

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* remove complexity

* Apply suggestions from code review

* no longer works that way

* fixes

* fixes

* fixes

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
J. Nick Koston 2024-03-18 15:45:34 -10:00 committed by GitHub
parent 9be5f3531f
commit c615b52840
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 598 additions and 176 deletions

View file

@ -57,7 +57,14 @@ from .helpers.frame import report
from .helpers.json import json_bytes, json_fragment
from .helpers.typing import UNDEFINED, ConfigType, DiscoveryInfoType, UndefinedType
from .loader import async_suggest_report_issue
from .setup import DATA_SETUP_DONE, async_process_deps_reqs, async_setup_component
from .setup import (
DATA_SETUP_DONE,
SetupPhases,
async_pause_setup,
async_process_deps_reqs,
async_setup_component,
async_start_setup,
)
from .util import uuid as uuid_util
from .util.async_ import create_eager_task
from .util.decorator import Registry
@ -529,10 +536,17 @@ class ConfigEntry:
self._async_set_state(hass, ConfigEntryState.MIGRATION_ERROR, None)
return
setup_phase = SetupPhases.CONFIG_ENTRY_SETUP
else:
setup_phase = SetupPhases.CONFIG_ENTRY_PLATFORM_SETUP
error_reason = None
try:
result = await component.async_setup_entry(hass, self)
with async_start_setup(
hass, integration=self.domain, group=self.entry_id, phase=setup_phase
):
result = await component.async_setup_entry(hass, self)
if not isinstance(result, bool):
_LOGGER.error( # type: ignore[unreachable]
@ -1838,7 +1852,9 @@ class ConfigEntries:
) -> None:
"""Forward the setup of an entry to platforms."""
integration = await loader.async_get_integration(self.hass, entry.domain)
await integration.async_get_platforms(platforms)
if not integration.platforms_are_loaded(platforms):
with async_pause_setup(self.hass, SetupPhases.WAIT_IMPORT_PLATFORMS):
await integration.async_get_platforms(platforms)
await asyncio.gather(
*(
create_eager_task(
@ -1860,7 +1876,10 @@ class ConfigEntries:
"""
# Setup Component if not set up yet
if domain not in self.hass.config.components:
result = await async_setup_component(self.hass, domain, self._hass_config)
with async_pause_setup(self.hass, SetupPhases.WAIT_BASE_PLATFORM_SETUP):
result = await async_setup_component(
self.hass, domain, self._hass_config
)
if not result:
return False