Add service to log all the current asyncio Tasks to the profiler (#116389)

* Add service to log all the current asyncio Tasks to the profiler

I have been helping users look for a task leaks, and need a
way to examine tasks at run time as trying to get someone to
run Home Assistant and attach aiomonitor is too difficult in
many cases.

* cover
This commit is contained in:
J. Nick Koston 2024-04-29 10:03:35 -05:00 committed by GitHub
parent f1e5bbcbca
commit 8bfcaf3524
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 64 additions and 10 deletions

View file

@ -18,6 +18,7 @@ from homeassistant.components.profiler import (
CONF_ENABLED,
CONF_SECONDS,
SERVICE_DUMP_LOG_OBJECTS,
SERVICE_LOG_CURRENT_TASKS,
SERVICE_LOG_EVENT_LOOP_SCHEDULED,
SERVICE_LOG_THREAD_FRAMES,
SERVICE_LRU_STATS,
@ -221,6 +222,28 @@ async def test_log_thread_frames(
await hass.async_block_till_done()
async def test_log_current_tasks(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test we can log current tasks."""
entry = MockConfigEntry(domain=DOMAIN)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert hass.services.has_service(DOMAIN, SERVICE_LOG_CURRENT_TASKS)
await hass.services.async_call(DOMAIN, SERVICE_LOG_CURRENT_TASKS, {}, blocking=True)
assert "test_log_current_tasks" in caplog.text
caplog.clear()
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
async def test_log_scheduled(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None: