Skip to content

Commit

Permalink
xmr: debugging logging only in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Sep 13, 2018
1 parent c7c8d3c commit 25bf70d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
6 changes: 4 additions & 2 deletions src/apps/monero/protocol/key_image_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ async def sync(self, ctx, tds):
from trezor.messages.MoneroExportedKeyImage import MoneroExportedKeyImage
from trezor.messages.MoneroKeyImageSyncStepAck import MoneroKeyImageSyncStepAck

log.debug(__name__, "ki_sync, step i")
if __debug__:
log.debug(__name__, "ki_sync, step i")

self.ctx = ctx
if self.blocked:
Expand All @@ -77,7 +78,8 @@ async def sync(self, ctx, tds):
if self.c_idx >= self.num:
raise ValueError("Too many outputs")

log.debug(__name__, "ki_sync, step i: %d", self.c_idx)
if __debug__:
log.debug(__name__, "ki_sync, step i: %d", self.c_idx)
chash = key_image.compute_hash(td)

self.hasher.update(chash)
Expand Down
16 changes: 8 additions & 8 deletions src/apps/monero/protocol/tsx_sign_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ def state_save(self):
return t

def _log_trace(self, x=None, collect=False):
log.debug(
__name__,
"Log trace: %s, ... F: %s A: %s",
x,
gc.mem_free(),
gc.mem_alloc(),
# micropython.stack_use(),
)
if __debug__:
log.debug(
__name__,
"Log trace: %s, ... F: %s A: %s",
x,
gc.mem_free(),
gc.mem_alloc(),
)
if collect:
gc.collect()

Expand Down
20 changes: 11 additions & 9 deletions src/apps/monero/protocol_lite/lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def __init__(self, **kwargs):
self.r_len = 0

def _log_trace(self, x=None, collect=False):
log.debug(
__name__,
"Log trace %s, ... F: %s A: %s, S: %s",
x,
gc.mem_free(),
gc.mem_alloc(),
micropython.stack_use(),
)
if __debug__:
log.debug(
__name__,
"Log trace %s, ... F: %s A: %s",
x,
gc.mem_free(),
gc.mem_alloc(),
)
if collect:
gc.collect()

Expand Down Expand Up @@ -642,7 +642,9 @@ async def dispatch(self, ctx, ins, p1, p2, input):

sw = 0x6F01
try:
log.debug(__name__, "Ins: %s, %s %s", ins, p1, p2)
if __debug__:
log.debug(__name__, "Ins: %s, %s %s", ins, p1, p2)

sw = await self._sub_dispatch(ins, p1)
except Exception as e:
log.error(__name__, "Exception dispatching: %s", e)
Expand Down
21 changes: 11 additions & 10 deletions src/apps/monero/xmr/serialize/xmrserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def import_def(module, name):
if module not in sys.modules:
if not module.startswith("apps.monero"):
raise ValueError("Module not allowed: %s" % module)

log.debug(__name__, "Importing: from %s import %s", module, name)
if __debug__:
log.debug(__name__, "Importing: from %s import %s", module, name)
__import__(module, None, None, (name,), 0)

r = getattr(sys.modules[module], name)
Expand Down Expand Up @@ -300,14 +300,15 @@ def _get_type(self, elem_type):
m = elem_type.__module__
r = import_def(m, cname)
sub_test = issubclass(r, XmrType)
log.debug(
__name__,
"resolved %s, sub: %s, id_e: %s, id_mod: %s",
r,
sub_test,
id(r),
id(sys.modules[m]),
)
if __debug__:
log.debug(
__name__,
"resolved %s, sub: %s, id_e: %s, id_mod: %s",
r,
sub_test,
id(r),
id(sys.modules[m]),
)
if not sub_test:
log.warning(__name__, "resolution hierarchy broken")

Expand Down

0 comments on commit 25bf70d

Please sign in to comment.