Skip to content

Commit

Permalink
print linear memory sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Jul 3, 2023
1 parent 5e37d11 commit 4bb2b87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions lib/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions lib/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 4bb2b87

Please sign in to comment.