Content-Length: 364400 | pFad | http://github.com/micropython/micropython/commit/a919ce26d325b0169a5cfaf65fe4a71ece9dfa1f

D4 webassembly/modjsffi: Add mem_info function to get detailed stats. · micropython/micropython@a919ce2 · GitHub
Skip to content

Commit a919ce2

Browse files
committed
webassembly/modjsffi: Add mem_info function to get detailed stats.
This allows querying the GC heap size/used/free values, as well as the number of alive JsProxy and PyProxy objects, referenced by proxy_c_ref and proxy_js_ref. Signed-off-by: Damien George <damien@micropython.org>
1 parent 57a9ffa commit a919ce2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Diff for: ports/webassembly/modjsffi.c

+40
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
#include "emscripten.h"
28+
#include "py/gc.h"
2829
#include "py/objmodule.h"
2930
#include "py/runtime.h"
3031
#include "proxy_c.h"
@@ -75,6 +76,44 @@ static mp_obj_t mp_jsffi_async_timeout_ms(mp_obj_t arg) {
7576
}
7677
static MP_DEFINE_CONST_FUN_OBJ_1(mp_jsffi_async_timeout_ms_obj, mp_jsffi_async_timeout_ms);
7778

79+
// *FORMAT-OFF*
80+
EM_JS(void, js_get_proxy_js_ref_info, (uint32_t * out), {
81+
let used = 0;
82+
for (const elem of proxy_js_ref) {
83+
if (elem !== undefined) {
84+
++used;
85+
}
86+
}
87+
Module.setValue(out, proxy_js_ref.length, "i32");
88+
Module.setValue(out + 4, used, "i32");
89+
});
90+
// *FORMAT-ON*
91+
92+
static mp_obj_t mp_jsffi_mem_info(void) {
93+
mp_obj_list_t *l = (mp_obj_list_t *)MP_OBJ_TO_PTR(MP_STATE_PORT(proxy_c_ref));
94+
mp_int_t used = 0;
95+
for (size_t i = 0; i < l->len; ++i) {
96+
if (l->items[i] != MP_OBJ_NULL) {
97+
++used;
98+
}
99+
}
100+
uint32_t proxy_js_ref_info[2];
101+
js_get_proxy_js_ref_info(proxy_js_ref_info);
102+
gc_info_t info;
103+
gc_info(&info);
104+
mp_obj_t elems[] = {
105+
MP_OBJ_NEW_SMALL_INT(info.total), // GC heap total bytes
106+
MP_OBJ_NEW_SMALL_INT(info.used), // GC heap used bytes
107+
MP_OBJ_NEW_SMALL_INT(info.free), // GC heap free bytes
108+
MP_OBJ_NEW_SMALL_INT(l->len), // proxy_c_ref allocated size
109+
MP_OBJ_NEW_SMALL_INT(used), // proxy_c_ref used
110+
MP_OBJ_NEW_SMALL_INT(proxy_js_ref_info[0]), // proxy_js_ref allocated size
111+
MP_OBJ_NEW_SMALL_INT(proxy_js_ref_info[1]), // proxy_js_ref used
112+
};
113+
return mp_obj_new_tuple(MP_ARRAY_SIZE(elems), elems);
114+
}
115+
static MP_DEFINE_CONST_FUN_OBJ_0(mp_jsffi_mem_info_obj, mp_jsffi_mem_info);
116+
78117
static const mp_rom_map_elem_t mp_module_jsffi_globals_table[] = {
79118
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_jsffi) },
80119

@@ -83,6 +122,7 @@ static const mp_rom_map_elem_t mp_module_jsffi_globals_table[] = {
83122
{ MP_ROM_QSTR(MP_QSTR_create_proxy), MP_ROM_PTR(&mp_jsffi_create_proxy_obj) },
84123
{ MP_ROM_QSTR(MP_QSTR_to_js), MP_ROM_PTR(&mp_jsffi_to_js_obj) },
85124
{ MP_ROM_QSTR(MP_QSTR_async_timeout_ms), MP_ROM_PTR(&mp_jsffi_async_timeout_ms_obj) },
125+
{ MP_ROM_QSTR(MP_QSTR_mem_info), MP_ROM_PTR(&mp_jsffi_mem_info_obj) },
86126
};
87127
static MP_DEFINE_CONST_DICT(mp_module_jsffi_globals, mp_module_jsffi_globals_table);
88128

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/micropython/micropython/commit/a919ce26d325b0169a5cfaf65fe4a71ece9dfa1f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy