Make memory profiling show native stack usage (#1917)

This commit is contained in:
YAMAMOTO Takashi
2023-02-01 12:52:15 +09:00
committed by GitHub
parent 0435acdd43
commit 7d3b2a8773
15 changed files with 182 additions and 9 deletions

View File

@ -211,6 +211,7 @@ wasm_exec_env_set_thread_info(WASMExecEnv *exec_env)
exec_env->handle = os_self_thread();
exec_env->native_stack_boundary =
stack_boundary ? stack_boundary + WASM_STACK_GUARD_SIZE : NULL;
exec_env->native_stack_top_min = (void *)UINTPTR_MAX;
}
#if WASM_ENABLE_THREAD_MGR != 0

View File

@ -84,6 +84,12 @@ typedef struct WASMExecEnv {
void **native_symbol;
#endif
/*
* The lowest stack pointer value observed.
* Assumption: native stack grows to the lower address.
*/
uint8 *native_stack_top_min;
#if WASM_ENABLE_FAST_JIT != 0
/**
* Cache for
@ -165,6 +171,17 @@ typedef struct WASMExecEnv {
} wasm_stack;
} WASMExecEnv;
#if WASM_ENABLE_MEMORY_PROFILING != 0
#define RECORD_STACK_USAGE(e, p) \
do { \
if ((e)->native_stack_top_min > (p)) { \
(e)->native_stack_top_min = (p); \
} \
} while (0)
#else
#define RECORD_STACK_USAGE(e, p) (void)0
#endif
WASMExecEnv *
wasm_exec_env_create_internal(struct WASMModuleInstanceCommon *module_inst,
uint32 stack_size);

View File

@ -1399,6 +1399,22 @@ wasm_runtime_dump_mem_consumption(WASMExecEnv *exec_env)
else
os_printf("Total aux stack used: no enough info to profile\n");
/*
* Report the native stack usage estimation.
*
* Unlike the aux stack above, we report the amount unused
* because we don't know the stack "bottom".
*
* Note that this is just about what the runtime itself observed.
* It doesn't cover host func implementations, signal handlers, etc.
*/
if (exec_env->native_stack_top_min != (void *)UINTPTR_MAX)
os_printf("Native stack left: %zd\n",
exec_env->native_stack_top_min
- exec_env->native_stack_boundary);
else
os_printf("Native stack left: no enough info to profile\n");
os_printf("Total app heap used: %u\n", app_heap_peak_size);
}
#endif /* end of (WASM_ENABLE_MEMORY_PROFILING != 0) \