diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-20 01:53:15 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-20 02:20:40 +0200 |
commit | 440cc3f028c7eff54f6f713182c55c5e8b205bab (patch) | |
tree | 0965140285b1c79bb6ae3481d293fb2096f24e8b /py/builtinmp.c | |
parent | 164774c1c1195a16757652730ccc1cac74353f42 (diff) | |
download | micropython-440cc3f028c7eff54f6f713182c55c5e8b205bab.tar.gz micropython-440cc3f028c7eff54f6f713182c55c5e8b205bab.zip |
Expose memory stats functions via "micropython" module.
These are micropython.mem_total(), .mem_current(), .mem_peak(). These are 3
individual functions with simple scalar return value to make sure that
calls to these functions themselves have minimal (hopefully zero) impact on
memory allocation.
Diffstat (limited to 'py/builtinmp.c')
-rw-r--r-- | py/builtinmp.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/py/builtinmp.c b/py/builtinmp.c new file mode 100644 index 0000000000..bbfdab0d57 --- /dev/null +++ b/py/builtinmp.c @@ -0,0 +1,32 @@ +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#include <assert.h> + +#include "misc.h" +#include "mpconfig.h" +#include "obj.h" +#include "builtin.h" + +// Various builtins specific to MicroPython runtime, +// living in micropython module + +#if MICROPY_MEM_STATS +static mp_obj_t mem_total() { + return MP_OBJ_NEW_SMALL_INT(m_get_total_bytes_allocated()); +} + +static mp_obj_t mem_current() { + return MP_OBJ_NEW_SMALL_INT(m_get_current_bytes_allocated()); +} + +static mp_obj_t mem_peak() { + return MP_OBJ_NEW_SMALL_INT(m_get_peak_bytes_allocated()); +} + +MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_mem_total_obj, mem_total); +MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_mem_current_obj, mem_current); +MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_mem_peak_obj, mem_peak); +#endif |