Enhancements on wasm function execution time statistic (#2985)

Enhance the statistic of wasm function execution time, or the performance
profiling feature:
- Add os_time_thread_cputime_us() to get the cputime of a thread,
  and use it to calculate the execution time of a wasm function
- Support the statistic of the children execution time of a function,
  and dump it in wasm_runtime_dump_perf_profiling
- Expose two APIs:
  wasm_runtime_sum_wasm_exec_time
  wasm_runtime_get_wasm_func_exec_time

And rename os_time_get_boot_microsecond to os_time_get_boot_us.
This commit is contained in:
liang.he
2024-01-17 09:51:54 +08:00
committed by GitHub
parent 25ccc9f2d5
commit 5c8b8a17a6
24 changed files with 336 additions and 86 deletions

View File

@ -1690,8 +1690,43 @@ wasm_runtime_dump_perf_profiling(WASMModuleInstanceCommon *module_inst)
}
#endif
}
double
wasm_runtime_sum_wasm_exec_time(WASMModuleInstanceCommon *inst)
{
#if WASM_ENABLE_INTERP != 0
if (inst->module_type == Wasm_Module_Bytecode)
return wasm_summarize_wasm_execute_time((WASMModuleInstance *)inst);
#endif
#if WASM_ENABLE_AOT != 0
if (inst->module_type == Wasm_Module_AoT)
return aot_summarize_wasm_execute_time((AOTModuleInstance *)inst);
#endif
return 0.0;
}
double
wasm_runtime_get_wasm_func_exec_time(WASMModuleInstanceCommon *inst,
const char *func_name)
{
#if WASM_ENABLE_INTERP != 0
if (inst->module_type == Wasm_Module_Bytecode)
return wasm_get_wasm_func_exec_time((WASMModuleInstance *)inst,
func_name);
#endif
#if WASM_ENABLE_AOT != 0
if (inst->module_type == Wasm_Module_AoT)
return aot_get_wasm_func_exec_time((AOTModuleInstance *)inst,
func_name);
#endif
return 0.0;
}
#endif /* WASM_ENABLE_PERF_PROFILING != 0 */
WASMModuleInstanceCommon *
wasm_runtime_get_module_inst(WASMExecEnv *exec_env)
{