From 5718be1c61d65375c5192ce79c7cfb92f5fd30b6 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 16 Sep 2019 05:43:09 -0300 Subject: [PATCH] log top memory usage on status if tracemalloc enabled --- lbry/lbry/extras/daemon/Daemon.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lbry/lbry/extras/daemon/Daemon.py b/lbry/lbry/extras/daemon/Daemon.py index fb158e055..cc3e78ff1 100644 --- a/lbry/lbry/extras/daemon/Daemon.py +++ b/lbry/lbry/extras/daemon/Daemon.py @@ -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()