summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-07-15 17:58:38 -0700
committerScott Shawcroft <scott@tannewt.org>2020-07-17 17:15:03 -0700
commit518d909b2c20aed5b3ff1ca849731cdadea4ba4c (patch)
tree25192dc16d6905379e5c466349f7f164c0f31feb /py
parent9cdf5e148a8fcc506da6e2a8598fa2963bbcde2e (diff)
Add memorymonitor module
Diffstat (limited to 'py')
-rw-r--r--py/circuitpy_defns.mk6
-rw-r--r--py/circuitpy_mpconfig.h12
-rw-r--r--py/circuitpy_mpconfig.mk3
-rwxr-xr-xpy/gc.c16
4 files changed, 37 insertions, 0 deletions
diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk
index 815ee2e62..a39e0c9dd 100644
--- a/py/circuitpy_defns.mk
+++ b/py/circuitpy_defns.mk
@@ -174,6 +174,9 @@ endif
ifeq ($(CIRCUITPY__EVE),1)
SRC_PATTERNS += _eve/%
endif
+ifeq ($(CIRCUITPY_MEMORYMONITOR),1)
+SRC_PATTERNS += memorymonitor/%
+endif
ifeq ($(CIRCUITPY_MICROCONTROLLER),1)
SRC_PATTERNS += microcontroller/%
endif
@@ -398,6 +401,9 @@ SRC_SHARED_MODULE_ALL = \
gamepad/__init__.c \
gamepadshift/GamePadShift.c \
gamepadshift/__init__.c \
+ memorymonitor/__init__.c \
+ memorymonitor/AllocationAlarm.c \
+ memorymonitor/AllocationSize.c \
network/__init__.c \
os/__init__.c \
random/__init__.c \
diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h
index d05a246fc..3c2df37ff 100644
--- a/py/circuitpy_mpconfig.h
+++ b/py/circuitpy_mpconfig.h
@@ -429,6 +429,16 @@ extern const struct _mp_obj_module_t _eve_module;
#define _EVE_MODULE
#endif
+#if CIRCUITPY_MEMORYMONITOR
+extern const struct _mp_obj_module_t memorymonitor_module;
+#define MEMORYMONITOR_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_memorymonitor), (mp_obj_t)&memorymonitor_module },
+#define MEMORYMONITOR_ROOT_POINTERS mp_obj_t active_allocationsizes; \
+ mp_obj_t active_allocationalarms;
+#else
+#define MEMORYMONITOR_MODULE
+#define MEMORYMONITOR_ROOT_POINTERS
+#endif
+
#if CIRCUITPY_MICROCONTROLLER
extern const struct _mp_obj_module_t microcontroller_module;
#define MICROCONTROLLER_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)&microcontroller_module },
@@ -708,6 +718,7 @@ extern const struct _mp_obj_module_t watchdog_module;
JSON_MODULE \
MATH_MODULE \
_EVE_MODULE \
+ MEMORYMONITOR_MODULE \
MICROCONTROLLER_MODULE \
NEOPIXEL_WRITE_MODULE \
NETWORK_MODULE \
@@ -765,6 +776,7 @@ extern const struct _mp_obj_module_t watchdog_module;
mp_obj_t terminal_tilegrid_tiles; \
BOARD_UART_ROOT_POINTER \
FLASH_ROOT_POINTERS \
+ MEMORYMONITOR_ROOT_POINTERS \
NETWORK_ROOT_POINTERS \
void supervisor_run_background_tasks_if_tick(void);
diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk
index 2d4a5ecee..baa29e26b 100644
--- a/py/circuitpy_mpconfig.mk
+++ b/py/circuitpy_mpconfig.mk
@@ -118,6 +118,9 @@ CFLAGS += -DCIRCUITPY_MATH=$(CIRCUITPY_MATH)
CIRCUITPY__EVE ?= 0
CFLAGS += -DCIRCUITPY__EVE=$(CIRCUITPY__EVE)
+CIRCUITPY_MEMORYMONITOR ?= 0
+CFLAGS += -DCIRCUITPY_MEMORYMONITOR=$(CIRCUITPY_MEMORYMONITOR)
+
CIRCUITPY_MICROCONTROLLER ?= 1
CFLAGS += -DCIRCUITPY_MICROCONTROLLER=$(CIRCUITPY_MICROCONTROLLER)
diff --git a/py/gc.c b/py/gc.c
index 2f3f63522..0f08ffb2e 100755
--- a/py/gc.c
+++ b/py/gc.c
@@ -33,6 +33,10 @@
#include "supervisor/shared/safe_mode.h"
+#if CIRCUITPY_MEMORYMONITOR
+#include "shared-module/memorymonitor/AllocationSize.h"
+#endif
+
#if MICROPY_ENABLE_GC
#if MICROPY_DEBUG_VERBOSE // print debugging info
@@ -653,6 +657,10 @@ void *gc_alloc(size_t n_bytes, bool has_finaliser, bool long_lived) {
gc_dump_alloc_table();
#endif
+ #if CIRCUITPY_MEMORYMONITOR
+ memorymonitor_allocationsizes_track_allocation(end_block - start_block + 1);
+ #endif
+
return ret_ptr;
}
@@ -906,6 +914,10 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
gc_log_change(block, new_blocks);
#endif
+ #if CIRCUITPY_MEMORYMONITOR
+ memorymonitor_allocationsizes_track_allocation(new_blocks);
+ #endif
+
return ptr_in;
}
@@ -935,6 +947,10 @@ void *gc_realloc(void *ptr_in, size_t n_bytes, bool allow_move) {
gc_log_change(block, new_blocks);
#endif
+ #if CIRCUITPY_MEMORYMONITOR
+ memorymonitor_allocationsizes_track_allocation(new_blocks);
+ #endif
+
return ptr_in;
}