diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index c91c72f14..fa2a4f675 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -8,6 +8,7 @@ import inspect import typing import random import hashlib +import tracemalloc from urllib.parse import urlencode, quote from typing import Callable, Optional, List from binascii import hexlify, unhexlify @@ -4531,6 +4532,29 @@ class Daemon(metaclass=JSONRPCServerType): result['node_id'] = hexlify(self.dht_node.protocol.node_id).decode() return result + TRACEMALLOC_DOC = """ + Controls and queries tracemalloc memory tracing tools for troubleshooting. + """ + + def jsonrpc_tracemalloc_set(self, enable: bool): + """ + Enable/disable tracemalloc memory tracing + + Usage: + jsonrpc_tracemalloc_set () + + Options: + --enable : (bool) True enables, False disables + + Returns: + (bool) is it tracing? + """ + if enable: + tracemalloc.start() + else: + tracemalloc.stop() + return tracemalloc.is_tracing() + COMMENT_DOC = """ View, create and abandon comments. """ diff --git a/tests/integration/other/test_other_commands.py b/tests/integration/other/test_other_commands.py index 4ba5b9f10..ba95c6225 100644 --- a/tests/integration/other/test_other_commands.py +++ b/tests/integration/other/test_other_commands.py @@ -38,3 +38,9 @@ class SettingsManagement(CommandTestCase): self.assertTrue(self.daemon.analytics_manager.enabled) self.assertTrue(loggly.enabled) self.daemon.jsonrpc_settings_set('share_usage_data', False) + + +class TroubleshootingCommands(CommandTestCase): + async def test_tracemalloc_commands(self): + self.assertFalse(self.daemon.jsonrpc_tracemalloc_set(False)) + self.assertTrue(self.daemon.jsonrpc_tracemalloc_set(True))