summaryrefslogtreecommitdiffstatshomepage
path: root/py/builtinmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/builtinmp.c')
-rw-r--r--py/builtinmp.c32
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