2014-01-19 23:53:15 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mpconfig.h"
|
2014-01-21 21:40:13 +00:00
|
|
|
#include "qstr.h"
|
2014-01-19 23:53:15 +00:00
|
|
|
#include "obj.h"
|
2014-01-20 10:30:24 +00:00
|
|
|
#include "runtime.h"
|
2014-01-19 23:53:15 +00:00
|
|
|
#include "builtin.h"
|
|
|
|
|
|
|
|
// Various builtins specific to MicroPython runtime,
|
|
|
|
// living in micropython module
|
|
|
|
|
|
|
|
#if MICROPY_MEM_STATS
|
2014-02-12 16:31:30 +00:00
|
|
|
STATIC mp_obj_t mem_total() {
|
2014-01-20 10:30:24 +00:00
|
|
|
return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_total_bytes_allocated());
|
2014-01-19 23:53:15 +00:00
|
|
|
}
|
|
|
|
|
2014-02-12 16:31:30 +00:00
|
|
|
STATIC mp_obj_t mem_current() {
|
2014-01-20 10:30:24 +00:00
|
|
|
return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_current_bytes_allocated());
|
2014-01-19 23:53:15 +00:00
|
|
|
}
|
|
|
|
|
2014-02-12 16:31:30 +00:00
|
|
|
STATIC mp_obj_t mem_peak() {
|
2014-01-20 10:30:24 +00:00
|
|
|
return MP_OBJ_NEW_SMALL_INT((machine_int_t)m_get_peak_bytes_allocated());
|
2014-01-19 23:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2014-01-20 10:30:24 +00:00
|
|
|
|
|
|
|
void mp_module_micropython_init(void) {
|
|
|
|
mp_obj_t m_mp = mp_obj_new_module(MP_QSTR_micropython);
|
|
|
|
rt_store_name(MP_QSTR_micropython, m_mp);
|
|
|
|
|
|
|
|
#if MICROPY_MEM_STATS
|
2014-01-21 21:40:13 +00:00
|
|
|
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);
|
2014-01-20 10:30:24 +00:00
|
|
|
#endif
|
|
|
|
}
|