Skip to content

Commit

Permalink
instrument with GC
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Nov 13, 2023
1 parent 3d90081 commit dca78c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Classes/PluginConf.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
"ThreadWriter": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": False,"Advanced": True,},
"ThreadCommunication": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": False,"Advanced": True,},
"ZLinky": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": False,"Advanced": True,},
"Garbage": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": False,"Advanced": True,},
"Garbage": {"type": "bool","default": 0,"current": None,"restart": 0,"hidden": True,"Advanced": True,},
},
},
# Others
Expand Down
29 changes: 18 additions & 11 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ def __init__(self):

def onStart(self):
Domoticz.Status( "Zigbee for Domoticz plugin starting")
# Enable the cycle detector
# gc.set_debug(gc.DEBUG_SAVEALL)


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

Expand Down Expand Up @@ -367,6 +365,11 @@ def onStart(self):
self.zigbee_communication, self.VersionNewFashion, self.DomoticzMajor, self.DomoticzMinor, Parameters["HomeFolder"], self.HardwareID
)

if self.pluginconf.pluginConf["Garbage"]:
# Enable the cycle detector
Domoticz.Log("Setup Garbage set_debug to %s" %gc.DEBUG_LEAK)
gc.set_debug(gc.DEBUG_LEAK)

# Create Domoticz Sub menu
if "DomoticzCustomMenu" in self.pluginconf.pluginConf and self.pluginconf.pluginConf["DomoticzCustomMenu"] :
install_Z4D_to_domoticz_custom_ui( )
Expand Down Expand Up @@ -431,7 +434,7 @@ def onStart(self):
self.zigbee_communication
and self.zigbee_communication == "zigpy"
and ( self.pluginconf.pluginConf["forceZigpy_noasyncio"] or self.domoticzdb_Hardware.multiinstances_z4d_plugin_instance())
):
):
# https://github.com/python/cpython/issues/91375
self.log.logging("Plugin", "Status", "Multi instances plugin detected. Enable zigpy workaround")
sys.modules["_asyncio"] = None
Expand Down Expand Up @@ -512,7 +515,6 @@ def onStart(self):
if "Model" in self.ListOfDevices[x] and self.ListOfDevices[x]["Model"] in ( "", {} ):
profalux_fake_deviceModel(self, x)


self.log.logging("Plugin", "Debug", "ListOfDevices after checkListOfDevice2Devices: " + str(self.ListOfDevices))
self.log.logging("Plugin", "Debug", "IEEE2NWK after checkListOfDevice2Devices : " + str(self.IEEE2NWK))

Expand Down Expand Up @@ -733,12 +735,17 @@ def onStop(self): # sourcery skip: class-extract-method
if self.adminWidgets:
self.adminWidgets.updateStatusWidget(Devices, "No Communication")

# objects = gc.get_objects()
# Domoticz.Log( "Garbage Collected objects: %s" %str(objects))
if self.pluginconf.pluginConf["Garbage"]:

# Domoticz.Log( "Garbage Collected objects:")
# objects = gc.get_objects()
# for item in objects:
# Domoticz.Log( "- %s" %str(item))

# Print detected cycles (garbage collectors)
# for item in gc.garbage:
# Domoticz.Log(item)
# Print detected cycles (garbage collectors)
Domoticz.Log( "Garbage Collected detected cycles:")
for item in gc.garbage:
Domoticz.Log("- %s" %str(item))



Expand Down Expand Up @@ -1679,8 +1686,8 @@ def do_python_garbage_collection( self ):
# Garbage collector ( experimental for now)
if self.internalHB % (3600 // HEARTBEAT) == 0:
self.log.logging("Garbage", "Debug", "Garbage Collection status: %s" % str(gc.get_count()) )
# self.log.logging("Garbage", "Debug", "Garbage Collection triggered: %s" % str(gc.collect()) )
self.log.logging("Garbage", "Debug", "Garbage collection statistics: %s" % str( gc.get_stats()) )
# self.log.logging("Garbage", "Debug", "Garbage Collection triggered: %s" % str(gc.collect()) )

def _check_if_busy(self):
busy_ = self.ControllerLink.loadTransmit() >= MAX_FOR_ZIGATE_BUZY
Expand Down

0 comments on commit dca78c7

Please sign in to comment.