From d33d8ceb666a886fb110cba0c4de5bd6c619e8d6 Mon Sep 17 00:00:00 2001 From: milkpotatoes Date: Tue, 29 Jul 2025 12:40:07 +0000 Subject: [PATCH] Optimize log level Issue: https://gitee.com/openharmony/arkui_napi/issues/ICPQNR Signed-off-by: milkpotatoes --- native_engine/impl/ark/ark_idle_monitor.cpp | 8 +-- native_engine/impl/ark/ark_native_engine.cpp | 43 ++++++------- native_engine/native_api.cpp | 67 ++++++-------------- native_engine/native_async_hook_context.h | 1 - native_engine/native_async_work.cpp | 4 +- native_engine/native_engine.cpp | 59 +++++------------ native_engine/native_engine.h | 1 - native_engine/native_safe_async_work.cpp | 33 ++++------ 8 files changed, 75 insertions(+), 141 deletions(-) diff --git a/native_engine/impl/ark/ark_idle_monitor.cpp b/native_engine/impl/ark/ark_idle_monitor.cpp index acd359007..d2cf70b2a 100644 --- a/native_engine/impl/ark/ark_idle_monitor.cpp +++ b/native_engine/impl/ark/ark_idle_monitor.cpp @@ -69,7 +69,7 @@ void ArkIdleMonitor::CheckShortIdleTask(int64_t timestamp, int idleTime) timerHandlerQueue_.pop(); int ret = ffrt_timer_stop(ffrt_qos_user_initiated, handler); if (ret != 0) { - HILOG_ERROR("ArkIdleMonitor: ffrt_timer_stop error handler: timerHandler='%{public}d', ret='%{public}d'", + HILOG_WARN("ArkIdleMonitor: ffrt_timer_stop error handler: timerHandler='%{public}d', ret='%{public}d'", handler, ret); } handlerWaitToStopCount_--; @@ -162,7 +162,7 @@ void ArkIdleMonitor::IntervalMonitor() int64_t recordTotalDuration = nowTimestamp - startRecordTimestamp_; if (recordTotalDuration <= 0) { numberOfHighIdleTimeRatio_ = 0U; - HILOG_ERROR("ArkIdleMonitor: recordTotalDuration <= 0"); + HILOG_WARN("ArkIdleMonitor: recordTotalDuration <= 0"); } else { double idleTimeRatio = static_cast(idleDuration) / recordTotalDuration; HILOG_DEBUG("ArkIdleMonitor: idleTimeRatio '%{public}.2f'", idleTimeRatio); @@ -203,7 +203,7 @@ void ArkIdleMonitor::PostMonitorTask(uint64_t delayMs) if (waitForStopTimerHandler_ != -1) { int ret = ffrt_timer_stop(ffrt_qos_user_initiated, waitForStopTimerHandler_); if (ret != 0) { - HILOG_ERROR("ArkIdleMonitor: ffrt_timer_stop error handler: timerHandler='%{public}d', ret='%{public}d'", + HILOG_WARN("ArkIdleMonitor: ffrt_timer_stop error handler: timerHandler='%{public}d', ret='%{public}d'", waitForStopTimerHandler_, ret); } } @@ -376,7 +376,7 @@ double ArkIdleMonitor::GetCpuUsage() const HILOG_DEBUG("ArkIdleMonitor cpu usage: %{public}.2f", collectResult.data); return collectResult.data; } - HILOG_ERROR("ArkIdleMonitor get cpu usage failed, error code:%{public}d", collectResult.retCode); + HILOG_WARN("ArkIdleMonitor get cpu usage failed, error code:%{public}d", collectResult.retCode); #endif return 0.0f; } diff --git a/native_engine/impl/ark/ark_native_engine.cpp b/native_engine/impl/ark/ark_native_engine.cpp index 28d650ab3..932638f4f 100644 --- a/native_engine/impl/ark/ark_native_engine.cpp +++ b/native_engine/impl/ark/ark_native_engine.cpp @@ -426,7 +426,7 @@ bool ArkNativeEngine::SetModuleValidateCallback(NapiModuleValidateCallback valid return false; } if (moduleValidateCallback_.load()) { - HILOG_ERROR("Module Validate Callback is already set by another module or thread."); + HILOG_WARN("Module Validate Callback is already set by another module or thread."); return false; } moduleValidateCallback_ = validateCallback; @@ -716,11 +716,11 @@ void ArkNativeEngine::DeconstructCtxEnv() } if (HasNonCallbackRef()) { - HILOG_ERROR("Non-callback napi_ref is leak after context env teardown, counts: %{public}" PRIu64, + HILOG_WARN("Non-callback napi_ref is leak after context env teardown, counts: %{public}" PRIu64, GetNonCallbackRefCount()); } if (HasCallbackbleRef()) { - HILOG_ERROR("Callbackble napi_ref is leak after context env teardown, counts: %{public}" PRIu64, + HILOG_WARN("Callbackble napi_ref is leak after context env teardown, counts: %{public}" PRIu64, GetCallbackbleRefCount()); } parentEngine_ = nullptr; @@ -832,7 +832,6 @@ Local ArkNativeEngine::LoadNativeModule( auto exportObject = LoadArkModule(buffer, module->jsCodeLen, fileName); if (exportObject->IsUndefined()) { - HILOG_ERROR("load module failed"); return scope.Escape(exports); } else { exports = exportObject; @@ -857,7 +856,7 @@ Local ArkNativeEngine::LoadNativeModule( exports = exportObj; loadedModules_[module] = Global(vm_, exports); } else { - HILOG_ERROR("init module failed"); + HILOG_ERROR("module dose not provided an valid entry"); return scope.Escape(exports); } @@ -948,7 +947,7 @@ Local ArkNativeEngine::RequireNapiForCtxEnv(JsiRuntimeCallInfo *info std::string modNameCstr = moduleName->ToString(ecmaVm); NapiModuleValidateCallback modCheckCb = moduleValidateCallback_.load(); if (modCheckCb == nullptr) { - HILOG_ERROR("Cannot load native modules: module validation callback is null."); + HILOG_WARN("Cannot load native modules: module validation callback is null."); return scope.Escape(exports); } if (!modCheckCb(modNameCstr.c_str())) { @@ -1005,10 +1004,10 @@ Local ArkNativeEngine::RequireInternal(JsiRuntimeCallInfo *info) if (module != nullptr && arkNativeEngine) { if (module->registerCallback == nullptr) { if (module->name != nullptr) { - HILOG_ERROR("requireInternal Init function is nullptr. module name: %{public}s", + HILOG_WARN("requireInternal Init function is nullptr. module name: %{public}s", module->name); } else { - HILOG_ERROR("requireInternal Init function is nullptr."); + HILOG_WARN("requireInternal Init function is nullptr."); } return scope.Escape(exports); } @@ -1454,12 +1453,12 @@ panda::Local ArkNativeEngine::GetModuleFromName( napi_status status = napi_get_named_property( reinterpret_cast(this), nExport, instanceName.c_str(), &exportInstance); if (status != napi_ok) { - HILOG_ERROR("GetModuleFromName napi_get_named_property status != napi_ok"); + HILOG_WARN("GetModuleFromName napi_get_named_property status != napi_ok"); } status = napi_unwrap(reinterpret_cast(this), exportInstance, reinterpret_cast(instance)); if (status != napi_ok) { - HILOG_ERROR("GetModuleFromName napi_unwrap status != napi_ok"); + HILOG_WARN("GetModuleFromName napi_unwrap status != napi_ok"); } exports = exportObj; } @@ -1642,8 +1641,7 @@ napi_value ArkNativeEngine::CallFunction( Local value = funcObj->Call(vm_, thisObj, args.data(), argc); if (JSNApi::HasPendingException(vm_)) { - HILOG_ERROR("pending exception when js function called"); - HILOG_ERROR("print exception info: "); + HILOG_ERROR("Pending exception when js function called. Print exception info: "); JSNApi::PrintExceptionInfo(vm_); return nullptr; } @@ -1818,7 +1816,7 @@ std::string ArkNativeEngine::GetOhmurl(std::string path) path.erase(path.find_last_not_of(" ") + 1); bool ret = std::regex_match(path, reg); if (!ret) { - HILOG_ERROR("ArkNativeEngine:The module name doesn't comply with the naming rules"); + HILOG_ERROR("The module name doesn't comply with the naming rules"); return ""; } std::string systemModule = path.substr(1); @@ -1843,7 +1841,7 @@ Local ArkNativeEngine::NapiLoadNativeModule(std::string path) napi_value ArkNativeEngine::NapiLoadModule(const char* path) { if (path == nullptr) { - HILOG_ERROR("ArkNativeEngine:The module name is empty"); + HILOG_ERROR("The module name is empty"); return nullptr; } HILOG_INFO("ArkNativeEngine::NapiLoadModule path:%{public}s", path); @@ -1894,7 +1892,7 @@ napi_value ArkNativeEngine::NapiLoadModuleWithInfo(const char* path, const char* napi_value ArkNativeEngine::NapiLoadModuleWithInfoForHybridApp(const char* path, const char* module_info) { if (path == nullptr) { - HILOG_ERROR("ArkNativeEngine:The module name is empty"); + HILOG_ERROR("The module name is empty"); return nullptr; } panda::EscapeLocalScope scope(vm_); @@ -1910,7 +1908,7 @@ napi_value ArkNativeEngine::NapiLoadModuleWithInfoForHybridApp(const char* path, } if (JSNApi::HasPendingException(vm_)) { - HILOG_WARN("ArkNativeEngine:NapiLoadModuleWithInfo failed."); + HILOG_WARN("Load module with info failed."); JSNApi::PrintExceptionInfo(vm_); JSNApi::GetAndClearUncaughtException(vm_); // clear exception here return JsValueFromLocalValue(scope.Escape(undefObj)); @@ -1965,7 +1963,7 @@ napi_value ArkNativeEngine::CreateInstance(napi_value constructor, napi_value co Local instance = value->Constructor(vm_, args.data(), argc); Local excep = JSNApi::GetUncaughtException(vm_); if (!excep.IsNull()) { - HILOG_ERROR("ArkNativeEngineImpl::CreateInstance occur Exception"); + HILOG_ERROR("Occur exception"); return nullptr; } return JsValueFromLocalValue(scope.Escape(instance)); @@ -2052,7 +2050,7 @@ void ArkNativeEngine::PostFinalizeTasks() delete asynWork; }, uv_qos_t(napi_qos_background)); if (ret != 0) { - HILOG_ERROR("uv_queue_work fail ret '%{public}d'", ret); + HILOG_WARN("uv_queue_work fail ret '%{public}d'", ret); RunAsyncCallbacks(asyncFinalizers); delete asynWork; delete asyncFinalizers; @@ -2093,7 +2091,7 @@ void ArkNativeEngine::PostFinalizeTasks() delete finalizersPack; }, uv_qos_t(napi_qos_background)); if (ret != 0) { - HILOG_ERROR("uv_queue_work fail ret '%{public}d'", ret); + HILOG_WARN("uv_queue_work fail ret '%{public}d'", ret); panda::JsiNativeScope nativeScope(vm_); RunCallbacks(finalizersPack); delete syncWork; @@ -2129,7 +2127,7 @@ void ArkNativeEngine::PostAsyncTask(AsyncNativeCallbacksPack *callBacksPack) delete finalizers; }, uv_qos_t(napi_qos_background)); if (ret != 0) { - HILOG_ERROR("uv_queue_work fail ret '%{public}d'", ret); + HILOG_WARN("uv_queue_work fail ret '%{public}d'", ret); panda::JsiNativeScope nativeScope(vm_); RunCallbacks(callBacksPack); delete callBacksPack; @@ -2149,7 +2147,7 @@ void ArkNativeEngine::PostTriggerGCTask(TriggerGCData& data) delete triggerGCData; }, uv_qos_t(napi_qos_user_initiated)); if (ret != 0) { - HILOG_ERROR("uv_queue_work fail ret '%{public}d'", ret); + HILOG_WARN("uv_queue_work fail ret '%{public}d'", ret); RunCallbacks(triggerGCData); delete syncWork; delete triggerGCData; @@ -2931,7 +2929,7 @@ bool DumpHybridStack(const EcmaVM* vm, std::string &stack, uint32_t ignore, int3 if (unwinder->UnwindLocal(false, false, backtraceDeepth, skipedFrames)) { frames = unwinder->GetFrames(); } else { - HILOG_ERROR("Failed to unwind local"); + HILOG_WARN("Failed to unwind local"); } for (auto &frame : frames) { @@ -3022,7 +3020,6 @@ bool ArkNativeEngine::IsValidPandaFile(const char* path) bool ArkNativeEngine::IsValidScriptBuffer(uint8_t* scriptBuffer, size_t bufferSize) { if (scriptBuffer == nullptr) { - HILOG_ERROR("buffer is nullptr"); return false; } constexpr size_t headerLen = sizeof(uint64_t); diff --git a/native_engine/native_api.cpp b/native_engine/native_api.cpp index 56e1f425d..cf7c8f5a8 100644 --- a/native_engine/native_api.cpp +++ b/native_engine/native_api.cpp @@ -2719,13 +2719,9 @@ NAPI_EXTERN napi_status napi_create_buffer(napi_env env, size_t size, void** dat RETURN_STATUS_IF_FALSE(env, size > 0, napi_invalid_arg); uint8_t** value = reinterpret_cast(data); - if (!value) { - HILOG_ERROR("value is empty"); - return napi_set_last_error(env, napi_invalid_arg); - } if (size > MAX_BYTE_LENGTH) { - HILOG_ERROR("Creat failed, current size: %{public}2f MiB, limit size: %{public}2f MiB", + HILOG_ERROR("Create failed, current size: %{public}2f MiB, limit size: %{public}2f MiB", static_cast(size) / static_cast(ONEMIB_BYTE_SIZE), static_cast(MAX_BYTE_LENGTH) / static_cast(ONEMIB_BYTE_SIZE)); *value = nullptr; @@ -2759,12 +2755,8 @@ NAPI_EXTERN napi_status napi_create_buffer_copy(napi_env env, uint8_t** value = reinterpret_cast(result_data); const uint8_t* recvdata = (uint8_t*)data; - if (!value) { - HILOG_ERROR("value is empty"); - return napi_set_last_error(env, napi_invalid_arg); - } if (length > MAX_BYTE_LENGTH) { - HILOG_ERROR("Creat failed, current size: %{public}2f MiB, limit size: %{public}2f MiB", + HILOG_ERROR("Create failed, current size: %{public}2f MiB, limit size: %{public}2f MiB", static_cast(length) / static_cast(ONEMIB_BYTE_SIZE), static_cast(MAX_BYTE_LENGTH) / static_cast(ONEMIB_BYTE_SIZE)); *value = nullptr; @@ -2802,12 +2794,8 @@ NAPI_EXTERN napi_status napi_create_external_buffer(napi_env env, RETURN_STATUS_IF_FALSE(env, length > 0, napi_invalid_arg); auto callback = reinterpret_cast(finalize_cb); - if (!data) { - HILOG_ERROR("data is empty"); - return napi_set_last_error(env, napi_invalid_arg); - } if (length > MAX_BYTE_LENGTH) { - HILOG_ERROR("Creat failed, current size: %{public}2f MiB, limit size: %{public}2f MiB", + HILOG_ERROR("Create failed, current size: %{public}2f MiB, limit size: %{public}2f MiB", static_cast(length) / static_cast(ONEMIB_BYTE_SIZE), static_cast(MAX_BYTE_LENGTH) / static_cast(ONEMIB_BYTE_SIZE)); data = nullptr; @@ -2903,7 +2891,6 @@ NAPI_EXTERN napi_status napi_create_typedarray(napi_env env, if (!reinterpret_cast(env)->NapiNewTypedArray(typedArrayType, arrayBuf, byte_offset, length, result)) { - HILOG_ERROR("%{public}s invalid arg", __func__); return napi_set_last_error(env, napi_invalid_arg); } return GET_RETURN_STATUS(env); @@ -2936,7 +2923,6 @@ NAPI_EXTERN napi_status napi_create_sendable_typedarray(napi_env env, if (!reinterpret_cast(env)->NapiNewSendableTypedArray(typedArrayType, arrayBuf, byte_offset, length, result)) { - HILOG_ERROR("%{public}s invalid arg", __func__); return napi_set_last_error(env, napi_invalid_arg); } return GET_RETURN_STATUS(env); @@ -2996,7 +2982,6 @@ NAPI_EXTERN napi_status napi_get_typedarray_info(napi_env env, *byte_offset = byteOffset; } } else { - HILOG_ERROR("%{public}s invalid arg", __func__); return napi_set_last_error(env, napi_invalid_arg); } @@ -3147,18 +3132,17 @@ NAPI_EXTERN napi_status napi_set_promise_rejection_callback(napi_env env, napi_r auto rejectCallbackRef = reinterpret_cast(ref); auto checkCallbackRef = reinterpret_cast(checkRef); if (rejectCallbackRef == nullptr || checkCallbackRef == nullptr) { - HILOG_ERROR("rejectCallbackRef or checkCallbackRef is nullptr"); - } else { - auto engine = reinterpret_cast(env); - if (!engine->IsMainEnvContext()) { - HILOG_FATAL("multi-context does not support this interface"); - } - auto vm = const_cast(engine->GetEcmaVm()); - engine->SetPromiseRejectCallBackRef(rejectCallbackRef); - engine->SetCheckCallbackRef(checkCallbackRef); - panda::JSNApi::SetHostPromiseRejectionTracker(const_cast(vm), engine->GetPromiseRejectCallback(), - reinterpret_cast(engine)); + HILOG_WARN("rejectCallbackRef or checkCallbackRef is nullptr"); + } + auto engine = reinterpret_cast(env); + if (!engine->IsMainEnvContext()) { + HILOG_FATAL("multi-context does not support this interface"); } + auto vm = const_cast(engine->GetEcmaVm()); + engine->SetPromiseRejectCallBackRef(rejectCallbackRef); + engine->SetCheckCallbackRef(checkCallbackRef); + panda::JSNApi::SetHostPromiseRejectionTracker(const_cast(vm), engine->GetPromiseRejectCallback(), + reinterpret_cast(engine)); return napi_clear_last_error(env); } @@ -3725,7 +3709,7 @@ NAPI_EXTERN napi_status napi_get_all_property_names( break; default: *result = nullptr; - HILOG_ERROR("%{public}s invalid arg", __func__); + HILOG_WARN("invalid arg key_mode"); return napi_set_last_error(env, napi_invalid_arg); } @@ -3738,7 +3722,7 @@ NAPI_EXTERN napi_status napi_get_all_property_names( break; default: *result = nullptr; - HILOG_ERROR("%{public}s invalid arg", __func__); + HILOG_WARN("invalid arg key_conversion"); return napi_set_last_error(env, napi_invalid_arg); } Local arrayVal = obj->GetAllPropertyNames(vm, filter); @@ -3789,7 +3773,6 @@ NAPI_EXTERN napi_status napi_type_tag_object(napi_env env, napi_value js_object, result = obj->Set(vm, key, value); } if (!result) { - HILOG_ERROR("%{public}s invalid arg", __func__); return napi_set_last_error(env, napi_invalid_arg); } @@ -3888,7 +3871,6 @@ NAPI_EXTERN napi_status napi_get_date_value(napi_env env, napi_value value, doub if (IsDate_result) { *result = dateObj->GetTime(vm); } else { - HILOG_ERROR("%{public}s date expected", __func__); return napi_set_last_error(env, napi_date_expected); } @@ -3945,7 +3927,6 @@ NAPI_EXTERN napi_status napi_create_bigint_words(napi_env env, Local value = panda::BigIntRef::CreateBigWords(vm, sign, size, words); if (panda::JSNApi::HasPendingException(vm)) { - HILOG_ERROR("%{public}s pending exception", __func__); return napi_set_last_error(env, napi_pending_exception); } *result = JsValueFromLocalValue(value); @@ -4119,7 +4100,7 @@ NAPI_EXTERN napi_status napi_queue_async_work_with_queue(napi_env env, auto asyncWork = reinterpret_cast(work); bool res = asyncWork->QueueOrdered(reinterpret_cast(env), qos, taskId); if (!res) { - HILOG_ERROR("QueueOrdered failed"); + HILOG_WARN("QueueOrdered failed"); return napi_status::napi_generic_failure; } return napi_status::napi_ok; @@ -4128,7 +4109,7 @@ NAPI_EXTERN napi_status napi_queue_async_work_with_queue(napi_env env, static void* DetachFuncCallback(void* engine, void* object, void* hint, void* detachData) { if (detachData == nullptr || (engine == nullptr || object == nullptr)) { - HILOG_ERROR("DetachFuncCallback params has nullptr"); + HILOG_WARN("DetachFuncCallback params has nullptr"); return nullptr; } DetachCallback detach = reinterpret_cast(detachData); @@ -4139,12 +4120,12 @@ static void* DetachFuncCallback(void* engine, void* object, void* hint, void* de static Local AttachFuncCallback(void* engine, void* buffer, void* hint, void* attachData) { if (engine == nullptr) { - HILOG_ERROR("AttachFuncCallback engine is nullptr"); + HILOG_WARN("AttachFuncCallback engine is nullptr"); return Local(); } auto vm = reinterpret_cast(engine)->GetEcmaVm(); if (attachData == nullptr || buffer == nullptr) { - HILOG_ERROR("AttachFuncCallback params has nullptr"); + HILOG_WARN("AttachFuncCallback params has nullptr"); return panda::JSValueRef::Undefined(vm); } EscapeLocalScope scope(vm); @@ -4182,7 +4163,6 @@ NAPI_EXTERN napi_status napi_coerce_to_native_binding_object(napi_env env, panda::JSNApi::NativeBindingInfo* data = panda::JSNApi::NativeBindingInfo::CreateNewInstance(); if (data == nullptr) { - HILOG_ERROR("data is nullptr"); return napi_set_last_error(env, napi_invalid_arg); } data->env = env; @@ -4264,7 +4244,6 @@ NAPI_EXTERN napi_status napi_run_event_loop(napi_env env, napi_event_mode mode) CHECK_ENV(env); if (mode < napi_event_mode_default || mode > napi_event_mode_nowait) { - HILOG_ERROR("invalid mode %{public}d", static_cast(mode)); return napi_status::napi_invalid_arg; } @@ -4276,7 +4255,6 @@ NAPI_EXTERN napi_status napi_run_event_loop(napi_env env, napi_event_mode mode) auto result = nativeEngine->RunEventLoop(mode); if (result != napi_status::napi_ok) { - HILOG_ERROR("failed due to error %{public}d", static_cast(result)); return napi_set_last_error(env, result); } @@ -4294,7 +4272,6 @@ NAPI_EXTERN napi_status napi_stop_event_loop(napi_env env) } auto result = nativeEngine->StopEventLoop(); if (result != napi_status::napi_ok) { - HILOG_ERROR("stop event loop failed due to error %{public}d", static_cast(result)); return napi_set_last_error(env, result); } return napi_clear_last_error(env); @@ -4359,15 +4336,11 @@ NAPI_EXTERN napi_status napi_call_threadsafe_function_with_priority(napi_threads CHECK_ENV(func); if (priority < napi_priority_immediate || priority > napi_priority_idle) { - HILOG_ERROR("invalid priority %{public}d", static_cast(priority)); return napi_status::napi_invalid_arg; } auto safeAsyncWork = reinterpret_cast(func); int32_t innerPriority = static_cast(priority); auto res = safeAsyncWork->PostTask(data, innerPriority, isTail); - if (res != napi_ok) { - HILOG_ERROR("post task failed due to error %{public}d", res); - } return res; } @@ -4512,7 +4485,7 @@ NAPI_EXTERN napi_status napi_create_ark_context(napi_env env, napi_env* newEnv) auto vm = nativeEngine->GetEcmaVm(); // cannot to utilize a created env to generate a new env if (!nativeEngine->IsMainEnvContext()) { - HILOG_ERROR("env cannot be generate by using a created env"); + HILOG_WARN("env cannot be generate by using a created env"); return napi_set_last_error(env, napi_invalid_arg); } diff --git a/native_engine/native_async_hook_context.h b/native_engine/native_async_hook_context.h index 5decc855f..8b5e609bb 100755 --- a/native_engine/native_async_hook_context.h +++ b/native_engine/native_async_hook_context.h @@ -155,7 +155,6 @@ static panda::JSValueRef* InternalMakeCallback(NativeEngine* engine, panda::Func { auto vm = engine->GetEcmaVm(); if (funRef == nullptr) { - HILOG_ERROR("funRef is nullptr!"); return *panda::JSValueRef::Undefined(vm); } diff --git a/native_engine/native_async_work.cpp b/native_engine/native_async_work.cpp index f2e7671b2..8c2380609 100644 --- a/native_engine/native_async_work.cpp +++ b/native_engine/native_async_work.cpp @@ -77,7 +77,7 @@ NativeAsyncWork::NativeAsyncWork(NativeEngine* engine, asyncResourceName.c_str(), reinterpret_cast(this), taskTraceId_.GetChainId()) < 0) { - HILOG_ERROR("Get traceStr fail"); + HILOG_WARN("Get traceStr fail"); } traceDescription_ = traceStr; if (createdTraceId) { @@ -205,7 +205,7 @@ bool NativeAsyncWork::Cancel(NativeEngine* engine) int status = uv_cancel((uv_req_t*)&work_); if (status != 0) { - HILOG_ERROR("uv_cancel failed"); + HILOG_WARN("uv_cancel failed"); return false; } return true; diff --git a/native_engine/native_engine.cpp b/native_engine/native_engine.cpp index 77f1ad131..9cf187be0 100644 --- a/native_engine/native_engine.cpp +++ b/native_engine/native_engine.cpp @@ -98,16 +98,16 @@ NativeEngine::NativeEngine(NativeEngine* parent) : jsEngine_(parent->jsEngine_), void NativeEngine::InitUvField() { if (memset_s(&uvAsync_, sizeof(uvAsync_), 0, sizeof(uvAsync_)) != EOK) { - HILOG_ERROR("failed to init uvAsync_"); + HILOG_WARN("failed to init uvAsync_"); return; } if (memset_s(&uvSem_, sizeof(uvSem_), 0, sizeof(uvSem_)) != EOK) { - HILOG_ERROR("failed to init uvSem_"); + HILOG_WARN("failed to init uvSem_"); return; } #if !defined(PREVIEW) if (memset_s(&uvThread_, sizeof(uvThread_), 0, sizeof(uvThread_)) != EOK) { - HILOG_ERROR("failed to init uvThread_"); + HILOG_WARN("failed to init uvThread_"); return; } #endif @@ -172,7 +172,7 @@ void NativeEngine::Deinit() uv_run(loop_, UV_RUN_DEFAULT); if (uv_loop_close(loop_) != EOK) { // it maybe up to fatal level later - HILOG_ERROR("faild to close uv_loop, after reran."); + HILOG_WARN("faild to close uv_loop, after reran."); } }; delete loop_; @@ -394,7 +394,6 @@ void NativeEngine::EncodeToUtf8(napi_value value, char* buffer, uint32_t* writte { auto nativeValue = LocalValueFromJsValue(value); if (nativeValue->IsNull() || nchars == nullptr || written == nullptr) { - HILOG_ERROR("NativeEngine EncodeToUtf8 args is nullptr"); return; } @@ -402,7 +401,7 @@ void NativeEngine::EncodeToUtf8(napi_value value, char* buffer, uint32_t* writte LocalScope scope(vm); auto nativeString = nativeValue->ToString(vm); if (!nativeString->IsString(vm)) { - HILOG_ERROR("nativeValue not is string"); + HILOG_ERROR("nativeValue is not a string"); return; } @@ -460,7 +459,6 @@ static void SubEncodeToChinese(const EcmaVM* vm, void NativeEngine::EncodeToChinese(napi_value value, std::string& buffer, const std::string& encoding) { if (value == nullptr) { - HILOG_ERROR("nativeValue GetInterface is nullptr"); return; } @@ -469,7 +467,7 @@ void NativeEngine::EncodeToChinese(napi_value value, std::string& buffer, const LocalScope scope(vm); auto nativeString = nativeValue->ToString(vm); if (!nativeString->IsString(vm)) { - HILOG_ERROR("nativeValue not is string"); + HILOG_ERROR("nativeValue is not a string"); return; } @@ -555,15 +553,6 @@ void NativeEngine::SetPostTask(PostTask postTask) postTask_ = postTask; } -void NativeEngine::TriggerPostTask() -{ - if (postTask_ == nullptr) { - HILOG_ERROR("postTask_ is nullptr"); - return; - } - postTask_(false); -} - void* NativeEngine::GetJsEngine() { return jsEngine_; @@ -725,8 +714,7 @@ napi_status NativeEngine::AddCleanupFinalizer(CleanupFinalizerCallBack fun, void return napi_ok; } - HILOG_ERROR("AddCleanupFinalizer Failed, This may cause memory leaks or unexpected behavior."); - + HILOG_FATAL("AddCleanupFinalizer Failed, This may cause memory leaks or unexpected behavior."); return napi_generic_failure; } @@ -741,7 +729,7 @@ napi_status NativeEngine::RemoveCleanupFinalizer(CleanupFinalizerCallBack fun, v const char *failedReason = cleanupHook == instanceFinalizer_.end() ? "data is not registered or already unregistered" : "callback not equals to last registered"; - HILOG_ERROR("RemoveCleanupHook Failed, %{public}s, " + HILOG_FATAL("RemoveCleanupHook Failed, %{public}s, " "This may cause memory leaks or unexpected behavior.", failedReason); return napi_generic_failure; @@ -795,14 +783,14 @@ napi_status NativeEngine::AddCleanupHook(CleanupCallback fun, void* arg) std::string stack; if (IsCrossThreadCheckEnabled()) { if (DumpHybridStack(GetEcmaVm(), stack, 1, 8)) { // 1: skipd frames, 8: backtrace deepth - HILOG_ERROR("AddCleanupHook Failed, data cannot register multiple times." + HILOG_WARN("AddCleanupHook Failed, data cannot register multiple times." "\n%{public}s", stack.c_str()); } else { - HILOG_ERROR("AddCleanupHook Failed, data cannot register multiple times, " + HILOG_WARN("AddCleanupHook Failed, data cannot register multiple times, " "backtrace failed or unsupported platform."); } } else { - HILOG_ERROR("AddCleanupHook Failed, data cannot register multiple times, " + HILOG_WARN("AddCleanupHook Failed, data cannot register multiple times, " "enable cross-thread check for more information."); } @@ -822,14 +810,14 @@ napi_status NativeEngine::RemoveCleanupHook(CleanupCallback fun, void* arg) std::string stack; if (IsCrossThreadCheckEnabled()) { if (DumpHybridStack(GetEcmaVm(), stack, 1, 8)) { // 1: skiped frames, 8: backtrace deepth - HILOG_ERROR("RemoveCleanupHook Failed, %{public}s" + HILOG_WARN("RemoveCleanupHook Failed, %{public}s" ".\n%{public}s", failedReason, stack.c_str()); } else { - HILOG_ERROR("RemoveCleanupHook Failed %{public}s, " + HILOG_WARN("RemoveCleanupHook Failed %{public}s, " "backtrace failed or unsupported platform.", failedReason); } } else { - HILOG_ERROR("RemoveCleanupHook Failed, %{public}s, " + HILOG_WARN("RemoveCleanupHook Failed, %{public}s, " "enable cross thread check for more information.", failedReason); } @@ -851,8 +839,7 @@ void NativeEngine::RunCleanupHooks(bool waitTasks) // Sort in descending order so that the most recently inserted callbacks are run first. return a.second.second > b.second.second; }); - HILOG_DEBUG( - "NativeEngine::RunCleanup cleanup_hooks callbacks size:%{public}d", (int32_t)callbacks.size()); + HILOG_INFO("cleanup_hooks callbacks size:%{public}d", (int32_t)callbacks.size()); for (const CleanupCallbackTuple& cb : callbacks) { void* data = cb.first; if (cleanupHooks_.find(data) == cleanupHooks_.end()) { @@ -875,7 +862,6 @@ void NativeEngine::RunCleanupHooks(bool waitTasks) void NativeEngine::RunCleanup() { - HILOG_DEBUG("%{public}s, start.", __func__); CleanupHandles(); RunCleanupHooks(true); @@ -896,8 +882,6 @@ void NativeEngine::RunCleanup() uv_walk(loop_, ensureClosing, nullptr); while (uv_run(loop_, UV_RUN_DEFAULT) != 0) {}; - - HILOG_DEBUG("%{public}s, end.", __func__); } void NativeEngine::CleanupHandles() @@ -907,8 +891,7 @@ void NativeEngine::CleanupHandles() } while (requestWaiting_.load() > 0) { - HILOG_INFO("%{public}s, request waiting:%{public}d.", __func__, - requestWaiting_.load(std::memory_order_relaxed)); + HILOG_INFO("request waiting:%{public}d.", requestWaiting_.load(std::memory_order_relaxed)); uv_run(loop_, UV_RUN_ONCE); } } @@ -973,13 +956,12 @@ napi_value NativeEngine::RunScriptForAbc(const char* path, char* entryPoint) void* mapper = nullptr; if (!GetAbcBuffer(normalizedPath.c_str(), &scriptContent, &scriptContentSize, content, ami, &mapper, true)) { - HILOG_ERROR("RunScript: GetAbcBuffer failed"); + HILOG_WARN("RunScript: GetAbcBuffer failed"); return nullptr; } HILOG_DEBUG("RunScriptForAbc: GetAmi: %{private}s", ami.c_str()); // if buffer is empty, return directly. if (scriptContentSize == 0) { - HILOG_ERROR("asset size is %{public}zu", scriptContentSize); ThrowException("RunScriptForAbc: abc file is empty."); return nullptr; } @@ -1072,7 +1054,6 @@ bool NativeEngine::GetAbcBuffer(const char* path, uint8_t **buffer, size_t* buff void NativeEngine::SetInstanceData(void* data, NativeFinalize finalize_cb, void* hint) { - HILOG_DEBUG("NativeEngineWraper::%{public}s, start.", __func__); std::lock_guard insLock(instanceDataLock_); FinalizerInstanceData(); instanceDataInfo_.engine = this; @@ -1083,7 +1064,6 @@ void NativeEngine::SetInstanceData(void* data, NativeFinalize finalize_cb, void* void NativeEngine::GetInstanceData(void** data) { - HILOG_DEBUG("NativeEngineWraper::%{public}s, start.", __func__); std::lock_guard insLock(instanceDataLock_); if (data) { *data = instanceDataInfo_.nativeObject; @@ -1103,13 +1083,10 @@ void NativeEngine::FinalizerInstanceData(void) const char* NativeEngine::GetModuleFileName() { - HILOG_DEBUG("%{public}s, start.", __func__); if (moduleFileName_.empty()) { NativeModuleManager* moduleManager = GetModuleManager(); - HILOG_DEBUG("NativeEngineWraper::GetFileName GetModuleManager"); if (moduleManager != nullptr) { std::string moduleFileName = moduleManager->GetModuleFileName(moduleName_.c_str(), isAppModule_); - HILOG_INFO("NativeEngineWraper::GetFileName end filename:%{public}s", moduleFileName.c_str()); SetModuleFileName(moduleFileName); } } @@ -1148,7 +1125,6 @@ void NativeEngine::SetModuleLoadChecker(const std::shared_ptrProcessAsyncHandle(); @@ -60,20 +60,11 @@ void NativeSafeAsyncWork::AsyncCallback(uv_async_t* asyncHandler) void NativeSafeAsyncWork::CallJs(NativeEngine* engine, napi_value js_call_func, void* context, void* data) { if (engine == nullptr || js_call_func == nullptr) { - HILOG_ERROR("CallJs failed. engine or js_call_func is nullptr!"); - return; - } - napi_value value = nullptr; - napi_get_undefined(reinterpret_cast(engine), &value); - if (value == nullptr) { - HILOG_ERROR("CreateUndefined failed"); + HILOG_ERROR("CallJs failed. Engine or js_call_func is nullptr!"); return; } - auto resultValue = engine->CallFunction(value, js_call_func, nullptr, 0); - if (resultValue == nullptr) { - HILOG_ERROR("CallFunction failed"); - } + engine->CallFunction(nullptr, js_call_func, nullptr, 0); } NativeSafeAsyncWork::NativeSafeAsyncWork(NativeEngine* engine, @@ -149,7 +140,7 @@ bool NativeSafeAsyncWork::Init() int ret = uv_async_init(loop, &asyncHandler_, AsyncCallback); if (ret != 0) { - HILOG_ERROR("uv async send failed in Init ret = %{public}d", ret); + HILOG_ERROR("uv async send failed, ret = %{public}d", ret); return false; } @@ -213,7 +204,7 @@ SafeAsyncCode NativeSafeAsyncWork::Send(void* data, NativeThreadSafeFunctionCall queue_.emplace_back(data); auto ret = uv_async_send(&asyncHandler_); if (ret != 0) { - HILOG_ERROR("uv async send failed in Send ret = %{public}d", ret); + HILOG_ERROR("uv async send failed, ret = %{public}d", ret); return SafeAsyncCode::SAFE_ASYNC_FAILED; } } @@ -247,12 +238,12 @@ SafeAsyncCode NativeSafeAsyncWork::Release(NativeThreadSafeFunctionReleaseMode m if (status_ == SafeAsyncStatus::SAFE_ASYNC_STATUS_CLOSED || status_ == SafeAsyncStatus::SAFE_ASYNC_STATUS_CLOSING) { - HILOG_WARN("Do not release, thread is closed!"); + HILOG_WARN("Do not release, threadsafe function is closed!"); return SafeAsyncCode::SAFE_ASYNC_CLOSED; } if (threadCount_ == 0) { - HILOG_ERROR("Do not release, thread count is zero."); + HILOG_ERROR("Do not release, acquired thread count is already zero."); return SafeAsyncCode::SAFE_ASYNC_INVALID_ARGS; } @@ -275,7 +266,7 @@ SafeAsyncCode NativeSafeAsyncWork::Release(NativeThreadSafeFunctionReleaseMode m // trigger async handle auto ret = uv_async_send(&asyncHandler_); if (ret != 0) { - HILOG_ERROR("uv async send failed in Release ret = %{public}d", ret); + HILOG_ERROR("uv async send failed, ret = %{public}d", ret); return SafeAsyncCode::SAFE_ASYNC_FAILED; } } @@ -316,12 +307,12 @@ void NativeSafeAsyncWork::ProcessAsyncHandle() { std::unique_lock lock(mutex_); if (status_ == SafeAsyncStatus::SAFE_ASYNC_STATUS_CLOSED) { - HILOG_ERROR("Process failed, thread is closed!"); + HILOG_ERROR("Process failed, threadsafe function is closed!"); return; } if (status_ == SafeAsyncStatus::SAFE_ASYNC_STATUS_CLOSING) { - HILOG_ERROR("thread is closing!"); + HILOG_INFO("Threadsafe function is releasing!"); CloseHandles(); return; } @@ -365,7 +356,7 @@ void NativeSafeAsyncWork::ProcessAsyncHandle() if (!queue_.empty()) { auto ret = uv_async_send(&asyncHandler_); if (ret != 0) { - HILOG_ERROR("uv async send failed in ProcessAsyncHandle ret = %{public}d", ret); + HILOG_ERROR("uv async send failed, ret = %{public}d", ret); } } @@ -379,7 +370,7 @@ SafeAsyncCode NativeSafeAsyncWork::CloseHandles() HILOG_DEBUG("NativeSafeAsyncWork::CloseHandles called"); if (status_ == SafeAsyncStatus::SAFE_ASYNC_STATUS_CLOSED) { - HILOG_INFO("Close failed, thread is closed!"); + HILOG_WARN("Close failed, threadsafe function is closed!"); return SafeAsyncCode::SAFE_ASYNC_CLOSED; } -- Gitee