Skip to content

Commit

Permalink
enable possibility of race memory allocations with tracemalloc
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Oct 30, 2024
1 parent 95fc966 commit e2043f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions Classes/PluginConf.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@
"param": {
"reconnectonIEEEaddr": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": True,"Advanced": True,},
"reconnectonNWKaddr": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": True,"Advanced": True,},
"tracememoryAllocation": {"type": "bool","default": 0,"current": None,"restart": 1,"hidden": True,"Advanced": True,},
"disableZCLDefaultResponse": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": True,"Advanced": True,},
"ControllerInHybridMode": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": True,"Advanced": True,},
"ControllerInRawMode": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": False,"Advanced": True,},
Expand Down
42 changes: 33 additions & 9 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@
from Modules.zigpyBackup import handle_zigpy_backup
from Zigbee.zdpCommands import zdp_get_permit_joint_status

try:
import tracemalloc
except ImportError:
pass



VERSION_FILENAME = ".hidden/VERSION"

TEMPO_NETWORK = 2 # Start HB totrigget Network Status
Expand Down Expand Up @@ -302,10 +309,14 @@ def __init__(self):

self.device_settings = {}
initialize_device_settings(self)

self.tracemalloc_snapshot1 = None
self.tracemalloc_snapshot2 = None


def onStart(self):
Domoticz.Status( "Welcome to Zigbee for Domoticz (Z4D) plugin.")

_current_python_version_major = sys.version_info.major
_current_python_version_minor = sys.version_info.minor

Expand Down Expand Up @@ -390,14 +401,20 @@ def onStart(self):
self.zigbee_communication, self.VersionNewFashion, self.DomoticzMajor, self.DomoticzMinor, Parameters["HomeFolder"], self.HardwareID
)

if self.pluginconf.pluginConf.get("tracememoryAllocation", False):
try:
Domoticz.Log("!!! Z4D enabling Memory Allocation Tracing !!!")
tracemalloc.start()
self.tracemalloc_snapshot1 = tracemalloc.take_snapshot()
except Exception:
pass

if self.internet_available is None:
self.internet_available = is_internet_available()

if self.internet_available:
if check_requirements( Parameters[ "HomeFolder"] ):
# Check_requirements() return True if requirements not meet.
self.onStop()
return
if self.internet_available and check_requirements( Parameters[ "HomeFolder"] ):
self.onStop()
return

# Create Domoticz Sub menu
if "DomoticzCustomMenu" in self.pluginconf.pluginConf and self.pluginconf.pluginConf["DomoticzCustomMenu"] :
Expand Down Expand Up @@ -522,7 +539,7 @@ def onStart(self):
)
self.onStop()
return

# Log ListOfDevices dictionary
self.log.logging("Plugin", "Debug", "ListOfDevices:")
for key, value in self.ListOfDevices.items():
Expand Down Expand Up @@ -597,8 +614,7 @@ def onStop(self):
None
"""
Domoticz.Log("onStop()")



if self.log:
self.log.logging("Plugin", "Status", "Flushing to disk")

Expand Down Expand Up @@ -654,6 +670,14 @@ def onStop(self):
if self.adminWidgets:
self.adminWidgets.updateStatusWidget(Devices, "No Communication")

if self.pluginconf.pluginConf.get("tracememoryAllocation", False) and self.tracemalloc_snapshot1:
self.tracemalloc_snapshot2 = tracemalloc.take_snapshot()
top_stats = self.tracemalloc_snapshot2.compare_to(self.tracemalloc_snapshot1, 'lineno')
Domoticz.Log("[ Top 15 differences (tracemalloc)]")
for stat in top_stats[:15]:
Domoticz.Log( "-- " + str(stat))



def onDeviceRemoved(self, Unit):
# def onDeviceRemoved(self, DeviceID, Unit):
Expand Down

0 comments on commit e2043f9

Please sign in to comment.