start/stop tracemalloc over api

This commit is contained in:
Victor Shyba 2020-03-10 20:50:25 -03:00
parent 6814f2e38c
commit 56c8ad1221
2 changed files with 30 additions and 0 deletions

View file

@ -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 (<enable>)
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.
"""

View file

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