diff options
-rw-r--r-- | py/modmicropython.c | 15 | ||||
-rw-r--r-- | py/mpconfig.h | 5 | ||||
-rw-r--r-- | py/qstrdefs.h | 2 | ||||
-rw-r--r-- | stmhal/mpconfigport.h | 1 | ||||
-rw-r--r-- | unix/mpconfigport.h | 1 |
5 files changed, 23 insertions, 1 deletions
diff --git a/py/modmicropython.c b/py/modmicropython.c index 035956ffcc..52b1cd0e5e 100644 --- a/py/modmicropython.c +++ b/py/modmicropython.c @@ -26,6 +26,7 @@ #include <stdio.h> +#include "py/mpstate.h" #include "py/builtin.h" #include "py/stackctrl.h" #include "py/gc.h" @@ -33,6 +34,8 @@ // Various builtins specific to MicroPython runtime, // living in micropython module +#if MICROPY_PY_MICROPYTHON_MEM_INFO + #if MICROPY_MEM_STATS STATIC mp_obj_t mp_micropython_mem_total() { return MP_OBJ_NEW_SMALL_INT(m_get_total_bytes_allocated()); @@ -48,11 +51,18 @@ STATIC mp_obj_t mp_micropython_mem_peak() { return MP_OBJ_NEW_SMALL_INT(m_get_peak_bytes_allocated()); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_peak_obj, mp_micropython_mem_peak); +#endif mp_obj_t mp_micropython_mem_info(mp_uint_t n_args, const mp_obj_t *args) { +#if MICROPY_MEM_STATS printf("mem: total=" UINT_FMT ", current=" UINT_FMT ", peak=" UINT_FMT "\n", m_get_total_bytes_allocated(), m_get_current_bytes_allocated(), m_get_peak_bytes_allocated()); +#endif +#if MICROPY_STACK_CHECK + printf("stack: " UINT_FMT " out of " INT_FMT "\n", mp_stack_usage(), MP_STATE_VM(stack_limit) - mp_stack_usage()); +#else printf("stack: " UINT_FMT "\n", mp_stack_usage()); +#endif #if MICROPY_ENABLE_GC gc_dump_info(); if (n_args == 1) { @@ -72,7 +82,8 @@ STATIC mp_obj_t qstr_info(void) { return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_qstr_info_obj, qstr_info); -#endif + +#endif // MICROPY_PY_MICROPYTHON_MEM_INFO #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF && (MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE == 0) STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_alloc_emergency_exception_buf_obj, mp_alloc_emergency_exception_buf); @@ -80,10 +91,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_alloc_emergency_exception_buf_obj, mp_alloc_ STATIC const mp_map_elem_t mp_module_micropython_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_micropython) }, +#if MICROPY_PY_MICROPYTHON_MEM_INFO #if MICROPY_MEM_STATS { MP_OBJ_NEW_QSTR(MP_QSTR_mem_total), (mp_obj_t)&mp_micropython_mem_total_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_mem_current), (mp_obj_t)&mp_micropython_mem_current_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_mem_peak), (mp_obj_t)&mp_micropython_mem_peak_obj }, +#endif { MP_OBJ_NEW_QSTR(MP_QSTR_mem_info), (mp_obj_t)&mp_micropython_mem_info_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_qstr_info), (mp_obj_t)&mp_micropython_qstr_info_obj }, #endif diff --git a/py/mpconfig.h b/py/mpconfig.h index 57f54a590e..bf1a8bda52 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -369,6 +369,11 @@ typedef double mp_float_t; #define MICROPY_PY___FILE__ (1) #endif +// Whether to provide mem-info related functions in micropython module +#ifndef MICROPY_PY_MICROPYTHON_MEM_INFO +#define MICROPY_PY_MICROPYTHON_MEM_INFO (0) +#endif + // Whether to provide "array" module. Note that large chunk of the // underlying code is shared with "bytearray" builtin type, so to // get real savings, it should be disabled too. diff --git a/py/qstrdefs.h b/py/qstrdefs.h index b8eacc68c7..04890a800f 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -363,10 +363,12 @@ Q(polar) Q(rect) #endif +#if MICROPY_PY_MICROPYTHON_MEM_INFO #if MICROPY_MEM_STATS Q(mem_total) Q(mem_current) Q(mem_peak) +#endif Q(mem_info) Q(qstr_info) #endif diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 86682d87bc..a121cd1cbd 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -57,6 +57,7 @@ #define MICROPY_PY_BUILTINS_MEMORYVIEW (1) #define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_BUILTINS_EXECFILE (1) +#define MICROPY_PY_MICROPYTHON_MEM_INFO (1) #define MICROPY_PY_SYS_EXIT (1) #define MICROPY_PY_SYS_STDFILES (1) #define MICROPY_PY_CMATH (1) diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index 463907eb8e..a874503a13 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -57,6 +57,7 @@ #define MICROPY_PY_BUILTINS_MEMORYVIEW (1) #define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_BUILTINS_COMPILE (1) +#define MICROPY_PY_MICROPYTHON_MEM_INFO (1) #define MICROPY_PY_SYS_EXIT (1) #define MICROPY_PY_SYS_PLATFORM "linux" #define MICROPY_PY_SYS_MAXSIZE (1) |