From 99bbad8cdb9e23dbb040102e4531d4cdfbc00711 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Fri, 26 Jan 2024 18:06:21 +0800 Subject: [PATCH] perf profiling: Adjust the calculation of execution time (#3089) --- core/iwasm/aot/aot_runtime.c | 7 +++---- core/iwasm/interpreter/wasm_interp_classic.c | 7 +++---- core/iwasm/interpreter/wasm_interp_fast.c | 8 +++----- core/iwasm/interpreter/wasm_runtime.c | 7 +++---- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index ad57c4c0a..731cacbea 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -2845,14 +2845,13 @@ aot_free_frame(WASMExecEnv *exec_env) AOTFrame *prev_frame = cur_frame->prev_frame; #if WASM_ENABLE_PERF_PROFILING != 0 - cur_frame->func_perf_prof_info->total_exec_time += - os_time_thread_cputime_us() - cur_frame->time_started; + uint64 elapsed = os_time_thread_cputime_us() - cur_frame->time_started; + cur_frame->func_perf_prof_info->total_exec_time += elapsed; cur_frame->func_perf_prof_info->total_exec_cnt++; /* parent function */ if (prev_frame) - prev_frame->func_perf_prof_info->children_exec_time = - cur_frame->func_perf_prof_info->total_exec_time; + prev_frame->func_perf_prof_info->children_exec_time += elapsed; #endif wasm_exec_env_free_wasm_frame(exec_env, cur_frame); diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 0c0ab1f5b..7364a25fa 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -867,13 +867,12 @@ FREE_FRAME(WASMExecEnv *exec_env, WASMInterpFrame *frame) #if WASM_ENABLE_PERF_PROFILING != 0 if (frame->function) { WASMInterpFrame *prev_frame = frame->prev_frame; - frame->function->total_exec_time += - os_time_thread_cputime_us() - frame->time_started; + uint64 elapsed = os_time_thread_cputime_us() - frame->time_started; + frame->function->total_exec_time += elapsed; frame->function->total_exec_cnt++; if (prev_frame && prev_frame->function) - prev_frame->function->children_exec_time += - frame->function->total_exec_time; + prev_frame->function->children_exec_time += elapsed; } #endif wasm_exec_env_free_wasm_frame(exec_env, frame); diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index 889dafbf7..521f547f0 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -901,14 +901,12 @@ FREE_FRAME(WASMExecEnv *exec_env, WASMInterpFrame *frame) #if WASM_ENABLE_PERF_PROFILING != 0 if (frame->function) { WASMInterpFrame *prev_frame = frame->prev_frame; - - frame->function->total_exec_time += - os_time_thread_cputime_us() - frame->time_started; + uint64 elapsed = os_time_thread_cputime_us() - frame->time_started; + frame->function->total_exec_time += elapsed; frame->function->total_exec_cnt++; if (prev_frame && prev_frame->function) - prev_frame->function->children_exec_time += - frame->function->total_exec_time; + prev_frame->function->children_exec_time += elapsed; } #endif wasm_exec_env_free_wasm_frame(exec_env, frame); diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 79454539d..43844f2c6 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -3455,14 +3455,13 @@ llvm_jit_free_frame(WASMExecEnv *exec_env) #if WASM_ENABLE_PERF_PROFILING != 0 if (frame->function) { - frame->function->total_exec_time += - os_time_thread_cputime_us() - frame->time_started; + uint64 elapsed = os_time_thread_cputime_us() - frame->time_started; + frame->function->total_exec_time += elapsed; frame->function->total_exec_cnt++; /* parent function */ if (prev_frame) - prev_frame->function->children_exec_time = - frame->function->total_exec_time; + prev_frame->function->children_exec_time += elapsed; } #endif wasm_exec_env_free_wasm_frame(exec_env, frame);