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/runtime.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/runtime.c')
-rw-r--r-- | py/runtime.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/py/runtime.c b/py/runtime.c index 830bcc6aa8..09e4237aff 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -153,15 +153,18 @@ void rt_init(void) { mp_map_add_qstr(&map_builtins, MP_QSTR_bytearray, (mp_obj_t)&mp_builtin_bytearray_obj); #if MICROPY_CPYTHON_COMPAT - // Add (empty) micropython module, so it was possible to "import micropython", - // which can be a placeholder module on CPython. - mp_obj_t m_mp = mp_obj_new_module(qstr_from_str_static("micropython")); - rt_store_name(qstr_from_str_static("micropython"), m_mp); - // Precreate sys module, so "import sys" didn't throw exceptions. mp_obj_new_module(qstr_from_str_static("sys")); #endif + mp_obj_t m_mp = mp_obj_new_module(qstr_from_str_static("micropython")); + rt_store_name(qstr_from_str_static("micropython"), m_mp); +#if MICROPY_MEM_STATS + rt_store_attr(m_mp, qstr_from_str_static("mem_total"), (mp_obj_t)&mp_builtin_mem_total_obj); + rt_store_attr(m_mp, qstr_from_str_static("mem_current"), (mp_obj_t)&mp_builtin_mem_current_obj); + rt_store_attr(m_mp, qstr_from_str_static("mem_peak"), (mp_obj_t)&mp_builtin_mem_peak_obj); +#endif + next_unique_code_id = 1; // 0 indicates "no code" unique_codes_alloc = 0; unique_codes = NULL; |