log top memory usage on status if tracemalloc enabled

This commit is contained in:
Victor Shyba 2019-09-16 05:43:09 -03:00
parent 5c151a3a09
commit 5718be1c61

View file

@ -9,6 +9,7 @@ import base58
import random
import ecdsa
import hashlib
import tracemalloc
from urllib.parse import urlencode, quote
from typing import Callable, Optional, List
from binascii import hexlify, unhexlify
@ -145,6 +146,14 @@ DHT_HAS_CONTACTS = "dht_has_contacts"
WALLET_IS_UNLOCKED = "wallet_is_unlocked"
def debug_log_tracemalloc():
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')
log.debug("[ Top 10 memory usage ]")
for stat in top_stats[:10]:
log.debug(stat)
class DHTHasContacts(RequiredCondition):
name = DHT_HAS_CONTACTS
component = DHT_COMPONENT
@ -795,6 +804,8 @@ class Daemon(metaclass=JSONRPCServerType):
}
}
"""
if tracemalloc.is_tracing():
debug_log_tracemalloc()
connection_code = await self.get_connection_status()