summaryrefslogtreecommitdiffstatshomepage
path: root/py/builtinmp.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-20 02:01:50 -0800
committerDamien George <damien.p.george@gmail.com>2014-01-20 02:01:50 -0800
commit589233622ccbed5d7684890a181ac7e61839f630 (patch)
tree0965140285b1c79bb6ae3481d293fb2096f24e8b /py/builtinmp.c
parent164774c1c1195a16757652730ccc1cac74353f42 (diff)
parent440cc3f028c7eff54f6f713182c55c5e8b205bab (diff)
downloadmicropython-589233622ccbed5d7684890a181ac7e61839f630.tar.gz
micropython-589233622ccbed5d7684890a181ac7e61839f630.zip
Merge pull request #198 from pfalcon/expose-memstat
Expose memory stats functions via "micropython" module.
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