Browse Source

util.profiler: add "min_threshold" arg

master
SomberNight 3 years ago
parent
commit
ad5f95cb87
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/gui/qt/utxo_list.py
  2. 14
      electrum/util.py
  3. 1
      electrum/wallet.py

2
electrum/gui/qt/utxo_list.py

@ -35,6 +35,7 @@ from electrum.i18n import _
from electrum.bitcoin import is_address
from electrum.transaction import PartialTxInput, PartialTxOutput
from electrum.lnutil import LN_MAX_FUNDING_SAT, MIN_FUNDING_SAT
from electrum.util import profiler
from .util import ColorScheme, MONOSPACE_FONT, EnterButton
from .my_treeview import MyTreeView
@ -87,6 +88,7 @@ class UTXOList(MyTreeView):
menu.addAction(_('Coin control'), lambda: self.add_selection_to_coincontrol())
return toolbar
@profiler(min_threshold=0.05)
def update(self):
# not calling maybe_defer_update() as it interferes with coincontrol status bar
utxos = self.wallet.get_utxos()

14
electrum/util.py

@ -46,6 +46,7 @@ from ipaddress import IPv4Address, IPv6Address
import random
import secrets
import functools
from functools import partial
from abc import abstractmethod, ABC
import socket
@ -449,15 +450,22 @@ def constant_time_compare(val1, val2):
return hmac.compare_digest(to_bytes(val1, 'utf8'), to_bytes(val2, 'utf8'))
# decorator that prints execution time
_profiler_logger = _logger.getChild('profiler')
def profiler(func):
def profiler(func=None, *, min_threshold: Union[int, float, None] = None):
"""Function decorator that logs execution time.
min_threshold: if set, only log if time taken is higher than threshold
NOTE: does not work with async methods.
"""
if func is None:
return partial(profiler, min_threshold=min_threshold)
def do_profile(args, kw_args):
name = func.__qualname__
t0 = time.time()
o = func(*args, **kw_args)
t = time.time() - t0
_profiler_logger.debug(f"{name} {t:,.4f} sec")
if min_threshold is None or t > min_threshold:
_profiler_logger.debug(f"{name} {t:,.4f} sec")
return o
return lambda *args, **kw_args: do_profile(args, kw_args)

1
electrum/wallet.py

@ -1657,6 +1657,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
return False
return True
@profiler(min_threshold=0.1)
def make_unsigned_transaction(
self, *,
coins: Sequence[PartialTxInput],

Loading…
Cancel
Save