From 4bb2b8795a60fe00ce8a106e09571c1e08905b79 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 3 Jul 2023 07:03:44 +0900 Subject: [PATCH] print linear memory sizes --- cli/repl.c | 1 + lib/instance.c | 13 +++++++++++++ lib/instance.h | 2 ++ 3 files changed, 16 insertions(+) diff --git a/cli/repl.c b/cli/repl.c index 5cc319b0..98ff08a0 100644 --- a/cli/repl.c +++ b/cli/repl.c @@ -981,6 +981,7 @@ toywasm_repl_invoke(struct repl_state *state, const char *modname, #endif if (state->opts.print_stats) { exec_context_print_stats(ctx); + instance_print_stats(inst); } if (ret == ETOYWASMTRAP) { diff --git a/lib/instance.c b/lib/instance.c index 3d8324cf..e579fdc3 100644 --- a/lib/instance.c +++ b/lib/instance.c @@ -8,6 +8,7 @@ #include "exec.h" #include "instance.h" #include "module.h" +#include "nbio.h" #include "shared_memory_impl.h" #include "suspend.h" #include "type.h" @@ -668,3 +669,15 @@ instance_execute_handle_restart(struct exec_context *ctx, int exec_ret) } while (IS_RESTARTABLE(ret)); return ret; } + +void +instance_print_stats(const struct instance *inst) +{ + printf("=== instance statistics ===\n"); + uint32_t i; + for (i = 0; i < inst->mems.lsize; i++) { + const struct meminst *mi = VEC_ELEM(inst->mems, i); + nbio_printf("memory[%" PRIu32 "] %zu bytes allocated\n", i, + mi->allocated); + } +} diff --git a/lib/instance.h b/lib/instance.h index 4da8f923..17828c90 100644 --- a/lib/instance.h +++ b/lib/instance.h @@ -126,3 +126,5 @@ void memory_instance_destroy(struct meminst *mi); */ int create_satisfying_shared_memories(const struct module *module, struct import_object **imop); + +void instance_print_stats(const struct instance *inst);