Skip to content

Commit d78e6f6

Browse files
committed
pybricks.common.system: Add umm_info() function.
Add a umm_info() to print debug info about umm memory usage similar to micropython.mem_info(). This is used on EV3 for allocating memory for images.
1 parent 118accf commit d78e6f6

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

bricks/ev3/dbglog/dbglog.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2025 The Pybricks Authors
3+
//
4+
// Hack to allow umm_info() to print in MicroPython.
5+
6+
#include "py/mpprint.h"
7+
8+
#undef DBGLOG_FORCE
9+
#define DBGLOG_FORCE(force, fmt, ...) mp_printf(&mp_plat_print, fmt,##__VA_ARGS__)
10+
11+
#define DBGLOG_32_BIT_PTR(p) (p)

bricks/ev3/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define PYBRICKS_PY_COMMON_MOTORS (1)
2626
#define PYBRICKS_PY_COMMON_SPEAKER (1)
2727
#define PYBRICKS_PY_COMMON_SYSTEM (1)
28+
#define PYBRICKS_PY_COMMON_SYSTEM_UMM_INFO (1)
2829
#define PYBRICKS_PY_EV3DEVICES (1)
2930
#define PYBRICKS_PY_EXPERIMENTAL (1)
3031
#define PYBRICKS_PY_HUBS (1)

lib/pbio/platform/ev3/umm_malloc_cfgport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
// We only use this for large allocations, like images and we have a lot of RAM
88
// on the EV3, so we can use a larger block size to reduce overhead.
99
#define UMM_BLOCK_BODY_SIZE 256
10+
11+
#define UMM_INFO
12+
#define DBGLOG_ENABLE

pybricks/common/pb_type_system.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ static MP_DEFINE_CONST_FUN_OBJ_0(pb_type_System_reset_storage_obj, pb_type_Syste
150150

151151
#endif // PBIO_CONFIG_ENABLE_SYS
152152

153+
#if PYBRICKS_PY_COMMON_SYSTEM_UMM_INFO
154+
155+
// Not in library header for some reason.
156+
extern void *umm_info(void *ptr, bool force);
157+
158+
// Prints out umm usage similar to micropython.mem_info().
159+
static mp_obj_t pb_type_System_umm_info(void) {
160+
umm_info(NULL, false);
161+
return mp_const_none;
162+
}
163+
static MP_DEFINE_CONST_FUN_OBJ_0(pb_type_System_umm_info_obj, pb_type_System_umm_info);
164+
165+
#endif // PYBRICKS_PY_COMMON_SYSTEM_UMM_INFO
166+
153167
// dir(pybricks.common.System)
154168
static const mp_rom_map_elem_t common_System_locals_dict_table[] = {
155169
{ MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&pb_type_System_name_obj) },
@@ -163,6 +177,9 @@ static const mp_rom_map_elem_t common_System_locals_dict_table[] = {
163177
{ MP_ROM_QSTR(MP_QSTR_shutdown), MP_ROM_PTR(&pb_type_System_shutdown_obj) },
164178
{ MP_ROM_QSTR(MP_QSTR_storage), MP_ROM_PTR(&pb_type_System_storage_obj) },
165179
#endif
180+
#if PYBRICKS_PY_COMMON_SYSTEM_UMM_INFO
181+
{ MP_ROM_QSTR(MP_QSTR_umm_info), MP_ROM_PTR(&pb_type_System_umm_info_obj) },
182+
#endif
166183
};
167184
static MP_DEFINE_CONST_DICT(common_System_locals_dict, common_System_locals_dict_table);
168185

0 commit comments

Comments
 (0)