Implement performance profiler and call stack dump, and update toolchain document (#501)

And remove redundant FAST_INTERP macros in wasm_interp_fast.c, and fix wamrc --help wrong line order issue.

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
Wenyong Huang
2021-01-17 23:23:10 -06:00
committed by GitHub
parent 794028a968
commit 240ca2ed46
26 changed files with 752 additions and 109 deletions

View File

@ -1657,6 +1657,49 @@ wasm_get_exception(WASMModuleInstance *module_inst)
return module_inst->cur_exception;
}
#if WASM_ENABLE_PERF_PROFILING != 0
void
wasm_dump_perf_profiling(const WASMModuleInstance *module_inst)
{
WASMExportFuncInstance *export_func;
WASMFunctionInstance *func_inst;
char *func_name;
uint32 i, j;
os_printf("Performance profiler data:\n");
for (i = 0; i < module_inst->function_count; i++) {
func_inst = module_inst->functions + i;
if (func_inst->is_import_func) {
func_name = func_inst->u.func_import->field_name;
}
#if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
else if (func_inst->u.func->field_name) {
func_name = func_inst->u.func->field_name;
}
#endif
else {
func_name = NULL;
for (j = 0; j < module_inst->export_func_count; j++) {
export_func = module_inst->export_functions + j;
if (export_func->function == func_inst) {
func_name = export_func->name;
break;
}
}
}
if (func_name)
os_printf(" func %s, execution time: %.3f ms, execution count: %d times\n",
func_name, module_inst->functions[i].total_exec_time / 1000.0f,
module_inst->functions[i].total_exec_cnt);
else
os_printf(" func %d, execution time: %.3f ms, execution count: %d times\n",
i, module_inst->functions[i].total_exec_time / 1000.0f,
module_inst->functions[i].total_exec_cnt);
}
}
#endif
uint32
wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size,
void **p_native_addr)
@ -2205,7 +2248,7 @@ wasm_get_module_inst_mem_consumption(const WASMModuleInstance *module_inst,
#endif /* end of (WASM_ENABLE_MEMORY_PROFILING != 0)
|| (WASM_ENABLE_MEMORY_TRACING != 0) */
#if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
#if WASM_ENABLE_DUMP_CALL_STACK != 0
void
wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env)
{
@ -2214,18 +2257,33 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env)
WASMInterpFrame *cur_frame =
wasm_exec_env_get_cur_frame(exec_env);
WASMFunctionInstance *func_inst;
WASMExportFuncInstance *export_func;
const char *func_name = NULL;
uint32 n;
uint32 n, i;
os_printf("\n");
for (n = 0; cur_frame && cur_frame->function; n++) {
func_name = NULL;
func_inst = cur_frame->function;
if (func_inst->is_import_func) {
func_name = func_inst->u.func_import->field_name;
}
else {
#if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
func_name = func_inst->u.func->field_name;
#endif
/* if custom name section is not generated,
search symbols from export table */
if (!func_name) {
for (i = 0; i < module_inst->export_func_count; i++) {
export_func = module_inst->export_functions + i;
if (export_func->function == func_inst) {
func_name = export_func->name;
break;
}
}
}
}
/* function name not exported, print number instead */
@ -2240,4 +2298,4 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env)
}
os_printf("\n");
}
#endif /* end of WASM_ENABLE_CUSTOM_NAME_SECTION */
#endif /* end of WASM_ENABLE_DUMP_CALL_STACK */