From 1799386c788e4fd1c0c24e0ac45cfa4a7da3035a Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Mon, 21 Oct 2024 15:54:04 +0200 Subject: [PATCH] wip mem profiling, DO NOT USE --- .github/workflows/core.yml | 1 - core/src/apps/bitcoin/sign_tx/__init__.py | 10 ++++++++++ python/src/trezorlib/btc.py | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/core.yml b/.github/workflows/core.yml index 699db9e492..1895901710 100644 --- a/.github/workflows/core.yml +++ b/.github/workflows/core.yml @@ -438,7 +438,6 @@ jobs: core_memory_profile: name: Memory allocation report - if: false # NOTE manual job, comment out to run runs-on: ubuntu-latest env: TREZOR_MODEL: T diff --git a/core/src/apps/bitcoin/sign_tx/__init__.py b/core/src/apps/bitcoin/sign_tx/__init__.py index 17063fc3de..20f62da273 100644 --- a/core/src/apps/bitcoin/sign_tx/__init__.py +++ b/core/src/apps/bitcoin/sign_tx/__init__.py @@ -93,6 +93,16 @@ async def sign_tx( request_class, req = req assert TxRequest.is_type_of(req) if req.request_type == RequestType.TXFINISHED: + try: + import micropython + + print("micropython.mem_info() from received_message_handler.py") + micropython.mem_info() + print("Allocation count:", micropython.alloc_count()) # type: ignore ["alloc_count" is not a known attribute of module] + except AttributeError: + print( + "To show allocation count, create the build with TREZOR_MEMPERF=1" + ) return req res = await call(req, request_class) elif isinstance(req, helpers.UiConfirm): diff --git a/python/src/trezorlib/btc.py b/python/src/trezorlib/btc.py index 3ccb1a9595..ed5834776f 100644 --- a/python/src/trezorlib/btc.py +++ b/python/src/trezorlib/btc.py @@ -13,6 +13,8 @@ # # You should have received a copy of the License along with this library. # If not, see . + +import time import warnings from copy import copy from decimal import Decimal @@ -358,7 +360,12 @@ def sign_tx( ) R = messages.RequestType + start2 = time.time() + end2 = time.time() + while isinstance(res, messages.TxRequest): + print(end2 - start2) + start2 = time.time() # If there's some part of signed transaction, let's add it if res.serialized: if res.serialized.serialized_tx: @@ -420,6 +427,7 @@ def sign_tx( ) res = session.call(messages.TxAck(tx=msg)) + end2 = time.time() if not isinstance(res, messages.TxRequest): raise exceptions.TrezorException("Unexpected message")