Make memory profiling show native stack usage (#1917)
This commit is contained in:
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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) \
|
||||
|
||||
Reference in New Issue
Block a user