diff options
| author | Dan Halbert <halbert@halwitz.org> | 2017-07-23 15:32:05 -0400 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2017-07-23 15:32:05 -0400 |
| commit | f91493c97e20eef1d39a9cdc6c42a25cfd511734 (patch) | |
| tree | 7e7062c9c12220d798cfa154e0729b7cf3e6447b /atmel-samd | |
| parent | af1ede930ba643d68850c541ef4075d5f7fd4f02 (diff) | |
Measure and report maximum stack usage. (#175)
Add max stack usage tracking, visible via debug module ustack.
Add separate cpp flag for enabling modules: MICROPY_DEBUG_MODULES
Diffstat (limited to 'atmel-samd')
| -rw-r--r-- | atmel-samd/Makefile | 7 | ||||
| -rw-r--r-- | atmel-samd/main.c | 7 | ||||
| -rw-r--r-- | atmel-samd/mpconfigport.h | 9 |
3 files changed, 19 insertions, 4 deletions
diff --git a/atmel-samd/Makefile b/atmel-samd/Makefile index cc3e0b399..ed5981d09 100644 --- a/atmel-samd/Makefile +++ b/atmel-samd/Makefile @@ -128,10 +128,10 @@ CFLAGS_CORTEX_M0 = \ CFLAGS = $(INC) -Wall -Werror -std=gnu11 -nostdlib $(CFLAGS_CORTEX_M0) $(CFLAGS_MOD) $(COPT) #Debugging/Optimization -# TODO(tannewt): Figure out what NDEBUG does. Adding it to the debug build -# reduces code size pretty dramatically. ifeq ($(DEBUG), 1) -CFLAGS += -Os -ggdb -DNDEBUG -DENABLE_MICRO_TRACE_BUFFER +# NDEBUG disables assert() statements. This reduces code size pretty dramatically, per tannewt. +# Turn on Python modules useful for debugging (e.g. uheap, ustack). +CFLAGS += -Os -ggdb -DNDEBUG -DENABLE_MICRO_TRACE_BUFFER -DMICROPY_DEBUG_MODULES else CFLAGS += -Os -DNDEBUG -flto endif @@ -279,6 +279,7 @@ SRC_SHARED_MODULE = \ random/__init__.c \ storage/__init__.c \ uheap/__init__.c \ + ustack/__init__.c SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ $(addprefix shared-module/, $(SRC_SHARED_MODULE)) diff --git a/atmel-samd/main.c b/atmel-samd/main.c index 64b7d8c7f..842dae451 100644 --- a/atmel-samd/main.c +++ b/atmel-samd/main.c @@ -581,6 +581,13 @@ int main(void) { mp_stack_ctrl_init(); mp_stack_set_limit((char*)&_estack - (char*)&_ebss - 1024); + +#if MICROPY_MAX_STACK_USAGE + // _ezero (same as _ebss) is an int, so start 4 bytes above it. + mp_stack_set_bottom(&_ezero + 1); + mp_stack_fill_with_sentinel(); +#endif + init_flash_fs(); // Reset everything and prep MicroPython to run boot.py. diff --git a/atmel-samd/mpconfigport.h b/atmel-samd/mpconfigport.h index dd62a9f05..7755959ea 100644 --- a/atmel-samd/mpconfigport.h +++ b/atmel-samd/mpconfigport.h @@ -105,6 +105,11 @@ #define MICROPY_STACK_CHECK (1) +// Track stack usage on a debug build. Expose results via ustack module. +#ifdef MICROPY_DEBUG_MODULES +#define MICROPY_MAX_STACK_USAGE (1) +#endif + // This port is intended to be 32-bit, but unfortunately, int32_t for // different targets may be defined in different ways - either as int // or as long. This requires different printf formatting specifiers @@ -145,6 +150,7 @@ extern const struct _mp_obj_module_t storage_module; extern const struct _mp_obj_module_t time_module; extern const struct _mp_obj_module_t neopixel_write_module; extern const struct _mp_obj_module_t uheap_module; +extern const struct _mp_obj_module_t ustack_module; extern const struct _mp_obj_module_t samd_module; extern const struct _mp_obj_module_t touchio_module; extern const struct _mp_obj_module_t usb_hid_module; @@ -188,7 +194,8 @@ extern const struct _mp_obj_module_t usb_hid_module; EXTRA_BUILTIN_MODULES #define MICROPY_PORT_BUILTIN_DEBUG_MODULES \ - { MP_OBJ_NEW_QSTR(MP_QSTR_uheap),(mp_obj_t)&uheap_module } + { MP_OBJ_NEW_QSTR(MP_QSTR_uheap),(mp_obj_t)&uheap_module }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR_ustack),(mp_obj_t)&ustack_module } #ifndef MICROPY_PIN_DEFS_PORT_H #define MICROPY_PIN_DEFS_PORT_H "pins.h" |
