Skip to content

Commit

Permalink
drop profiler.memory due to zhuyifei1999/guppy3#41
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Feb 13, 2023
1 parent 8324f1d commit b144e6f
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 101 deletions.
51 changes: 0 additions & 51 deletions homeassistant/components/profiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from .const import DOMAIN

SERVICE_START = "start"
SERVICE_MEMORY = "memory"
SERVICE_START_LOG_OBJECTS = "start_log_objects"
SERVICE_STOP_LOG_OBJECTS = "stop_log_objects"
SERVICE_DUMP_LOG_OBJECTS = "dump_log_objects"
Expand All @@ -32,7 +31,6 @@

SERVICES = (
SERVICE_START,
SERVICE_MEMORY,
SERVICE_START_LOG_OBJECTS,
SERVICE_STOP_LOG_OBJECTS,
SERVICE_DUMP_LOG_OBJECTS,
Expand All @@ -58,10 +56,6 @@ async def _async_run_profile(call: ServiceCall) -> None:
async with lock:
await _async_generate_profile(hass, call)

async def _async_run_memory_profile(call: ServiceCall) -> None:
async with lock:
await _async_generate_memory_profile(hass, call)

async def _async_start_log_objects(call: ServiceCall) -> None:
if LOG_INTERVAL_SUB in domain_data:
domain_data[LOG_INTERVAL_SUB]()
Expand Down Expand Up @@ -162,16 +156,6 @@ async def _async_dump_scheduled(call: ServiceCall) -> None:
),
)

async_register_admin_service(
hass,
DOMAIN,
SERVICE_MEMORY,
_async_run_memory_profile,
schema=vol.Schema(
{vol.Optional(CONF_SECONDS, default=60.0): vol.Coerce(float)}
),
)

async_register_admin_service(
hass,
DOMAIN,
Expand Down Expand Up @@ -265,37 +249,6 @@ async def _async_generate_profile(hass: HomeAssistant, call: ServiceCall):
)


async def _async_generate_memory_profile(hass: HomeAssistant, call: ServiceCall):
# Imports deferred to avoid loading modules
# in memory since usually only one part of this
# integration is used at a time
from guppy import hpy # pylint: disable=import-outside-toplevel

start_time = int(time.time() * 1000000)
persistent_notification.async_create(
hass,
(
"The memory profile has started. This notification will be updated when it"
" is complete."
),
title="Profile Started",
notification_id=f"memory_profiler_{start_time}",
)
heap_profiler = hpy()
heap_profiler.setref()
await asyncio.sleep(float(call.data[CONF_SECONDS]))
heap = heap_profiler.heap()

heap_path = hass.config.path(f"heap_profile.{start_time}.hpy")
await hass.async_add_executor_job(_write_memory_profile, heap, heap_path)
persistent_notification.async_create(
hass,
f"Wrote heapy memory profile to {heap_path}",
title="Profile Complete",
notification_id=f"memory_profiler_{start_time}",
)


def _write_profile(profiler, cprofile_path, callgrind_path):
# Imports deferred to avoid loading modules
# in memory since usually only one part of this
Expand All @@ -307,10 +260,6 @@ def _write_profile(profiler, cprofile_path, callgrind_path):
convert(profiler.getstats(), callgrind_path)


def _write_memory_profile(heap, heap_path):
heap.byrcs.dump(heap_path)


def _log_objects(*_):
# Imports deferred to avoid loading modules
# in memory since usually only one part of this
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/profiler/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/profiler",
"quality_scale": "internal",
"requirements": ["pyprof2calltree==1.4.5", "guppy3==3.1.2", "objgraph==3.5.0"]
"requirements": ["pyprof2calltree==1.4.5", "objgraph==3.5.0"]
}
13 changes: 0 additions & 13 deletions homeassistant/components/profiler/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@ start:
min: 1
max: 3600
unit_of_measurement: seconds
memory:
name: Memory
description: Start the Memory Profiler
fields:
seconds:
name: Seconds
description: The number of seconds to run the memory profiler.
default: 60.0
selector:
number:
min: 1
max: 3600
unit_of_measurement: seconds
start_log_objects:
name: Start log objects
description: Start logging growth of objects in memory
Expand Down
3 changes: 0 additions & 3 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,6 @@ gspread==5.5.0
# homeassistant.components.gstreamer
gstreamer-player==1.1.2

# homeassistant.components.profiler
guppy3==3.1.2

# homeassistant.components.iaqualink
h2==4.1.0

Expand Down
3 changes: 0 additions & 3 deletions requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,6 @@ growattServer==1.3.0
# homeassistant.components.google_sheets
gspread==5.5.0

# homeassistant.components.profiler
guppy3==3.1.2

# homeassistant.components.iaqualink
h2==4.1.0

Expand Down
30 changes: 0 additions & 30 deletions tests/components/profiler/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
SERVICE_DUMP_LOG_OBJECTS,
SERVICE_LOG_EVENT_LOOP_SCHEDULED,
SERVICE_LOG_THREAD_FRAMES,
SERVICE_MEMORY,
SERVICE_START,
SERVICE_START_LOG_OBJECTS,
SERVICE_STOP_LOG_OBJECTS,
Expand Down Expand Up @@ -52,35 +51,6 @@ def _mock_path(filename):
await hass.async_block_till_done()


async def test_memory_usage(hass, tmpdir):
"""Test we can setup and the service is registered."""
test_dir = tmpdir.mkdir("profiles")

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_MEMORY)

last_filename = None

def _mock_path(filename):
nonlocal last_filename
last_filename = f"{test_dir}/{filename}"
return last_filename

with patch("guppy.hpy") as mock_hpy, patch.object(hass.config, "path", _mock_path):
await hass.services.async_call(DOMAIN, SERVICE_MEMORY, {CONF_SECONDS: 0.000001})
await hass.async_block_till_done()

mock_hpy.assert_called_once()

assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()


async def test_object_growth_logging(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
Expand Down

0 comments on commit b144e6f

Please sign in to comment.