From 3e9173235c158ce5888abc7b14242e3afba7fe39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E5=86=AC=E5=86=AC=E5=86=AC?= Date: Thu, 7 Aug 2025 21:28:36 +0800 Subject: [PATCH] Message:fixCodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 郑冬冬冬 --- .../native/appkit/dfr/appfreeze_inner.cpp | 22 +++++++++++++++---- services/appdfr/src/appfreeze_manager.cpp | 17 +++++++++----- .../appdfr/src/application_anr_listener.cpp | 10 +++++++++ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/frameworks/native/appkit/dfr/appfreeze_inner.cpp b/frameworks/native/appkit/dfr/appfreeze_inner.cpp index f94a3cda4e9..7a9a1f27ca2 100644 --- a/frameworks/native/appkit/dfr/appfreeze_inner.cpp +++ b/frameworks/native/appkit/dfr/appfreeze_inner.cpp @@ -30,6 +30,7 @@ #include "parameter.h" #include "xcollie/watchdog.h" #include "time_util.h" +#include "parameters.h" namespace OHOS { using AbilityRuntime::FreezeUtil; @@ -43,6 +44,7 @@ constexpr char EVENT_PROCESS_NAME[] = "PROCESS_NAME"; constexpr char EVENT_STACK[] = "STACK"; constexpr int32_t HALF_DURATION = 3000; constexpr int32_t HALF_INTERVAL = 300; +const bool BETA_VERSION = OHOS::system::GetParameter("const.logsystem.versiontype", "unknown") == "beta"; } std::weak_ptr AppfreezeInner::appMainHandler_; std::shared_ptr AppfreezeInner::instance_ = nullptr; @@ -151,11 +153,17 @@ void AppfreezeInner::AppfreezeHandleOverReportCount(bool isSixSecondEvent) "\nFault time:" + AbilityRuntime::TimeUtil::FormatTime("%Y/%m/%d-%H:%M:%S") + "\n"; faultData.errorObject.message += "App main thread is not response!"; faultData.faultType = FaultDataType::APP_FREEZE; - faultData.timeoutMarkers = ""; + int32_t pid = static_cast(getpid()); if (isSixSecondEvent) { faultData.errorObject.name = AppFreezeType::THREAD_BLOCK_6S; - faultData.procStatm = GetProcStatm(static_cast(getpid())); + faultData.procStatm = GetProcStatm(pid); } else { + if (!BETA_VERSION) { + int32_t ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::AAFWK, "HIVIEW_HALF_FREEZE_LOG", + HiviewDFX::HiSysEvent::EventType::FAULT, "PID", pid, "PACKAGE_NAME", ""); + TAG_LOGW(AAFwkTag::APPDFR, "hisysevent write HIVIEW_HALF_FREEZE_LOG, pid:%{public}d, packageName:," + " ret:%{public}d", pid, ret); + } faultData.errorObject.name = AppFreezeType::THREAD_BLOCK_3S; } if (!IsHandleAppfreeze()) { @@ -251,6 +259,7 @@ void AppfreezeInner::ThreadBlock(std::atomic_bool& isSixSecondEvent) faultData.errorObject.message += "App main thread is not response!"; faultData.faultType = FaultDataType::APP_FREEZE; bool onlyMainThread = false; + int32_t pid = static_cast(getpid()); if (isSixSecondEvent) { faultData.errorObject.name = AppFreezeType::THREAD_BLOCK_6S; @@ -258,15 +267,20 @@ void AppfreezeInner::ThreadBlock(std::atomic_bool& isSixSecondEvent) #ifdef APP_NO_RESPONSE_DIALOG isSixSecondEvent.store(false); #endif - faultData.procStatm = GetProcStatm(static_cast(getpid())); + faultData.procStatm = GetProcStatm(pid); } else { + if (!BETA_VERSION) { + int32_t ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::AAFWK, "HIVIEW_HALF_FREEZE_LOG", + HiviewDFX::HiSysEvent::EventType::FAULT, "PID", pid, "PACKAGE_NAME", ""); + TAG_LOGW(AAFwkTag::APPDFR, "hisysevent write HIVIEW_HALF_FREEZE_LOG, pid:%{public}d, packageName:," + " ret:%{public}d", pid, ret); + } faultData.errorObject.name = AppFreezeType::THREAD_BLOCK_3S; isSixSecondEvent.store(true); std::string outFile; OHOS::HiviewDFX::Watchdog::GetInstance().StartSample(HALF_DURATION, HALF_INTERVAL, outFile); faultData.appfreezeInfo = outFile; } - faultData.timeoutMarkers = ""; if (!IsHandleAppfreeze()) { return; diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index fc6e4f1a548..5ee8cd1f845 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -178,17 +178,15 @@ void AppfreezeManager::CollectFreezeSysMemory(std::string& memoryContent) int AppfreezeManager::MergeNotifyInfo(FaultData& faultNotifyData, const AppfreezeManager::AppInfo& appInfo) { - std::string memoryContent = ""; + std::string memoryContent; CollectFreezeSysMemory(memoryContent); std::string fileName = faultNotifyData.errorObject.name + "_" + AbilityRuntime::TimeUtil::FormatTime("%Y%m%d%H%M%S") + "_" + std::to_string(appInfo.pid) + "_stack"; - std::string catcherStack = ""; + std::string catcherStack; faultNotifyData.errorObject.message += "\nCatche stack trace start time: " + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr() + "\n"; if (faultNotifyData.errorObject.name == AppFreezeType::LIFECYCLE_HALF_TIMEOUT || - faultNotifyData.errorObject.name == AppFreezeType::LIFECYCLE_HALF_TIMEOUT_WARNING || - faultNotifyData.errorObject.name == AppFreezeType::LIFECYCLE_TIMEOUT || - faultNotifyData.errorObject.name == AppFreezeType::LIFECYCLE_TIMEOUT_WARNING) { + faultNotifyData.errorObject.name == AppFreezeType::LIFECYCLE_HALF_TIMEOUT_WARNING) { catcherStack += CatcherStacktrace(appInfo.pid, faultNotifyData.errorObject.stack); } else { catcherStack += CatchJsonStacktrace(appInfo.pid, faultNotifyData.errorObject.name, @@ -273,12 +271,19 @@ int AppfreezeManager::LifecycleTimeoutHandle(const ParamInfo& info, FreezeUtil:: && info.eventName != AppFreezeType::LIFECYCLE_HALF_TIMEOUT_WARNING) { return -1; } + if (!g_betaVersion && info.eventName == AppFreezeType::LIFECYCLE_HALF_TIMEOUT) { + int32_t ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::AAFWK, "HIVIEW_HALF_FREEZE_LOG", + HiviewDFX::HiSysEvent::EventType::FAULT, "PID", info.pid, "PACKAGE_NAME", info.bundleName); + TAG_LOGW(AAFwkTag::APPDFR, "hisysevent write HIVIEW_HALF_FREEZE_LOG, pid:%{public}d, packageName:%{public}s," + " ret:%{public}d", info.pid, info.bundleName.c_str(), ret); + } + TAG_LOGD(AAFwkTag::APPDFR, "called %{public}s, name_ %{public}s", info.bundleName.c_str(), name_.c_str()); HITRACE_METER_FMT(HITRACE_TAG_APP, "LifecycleTimeoutHandle:%{public}s bundleName:%{public}s", info.eventName.c_str(), info.bundleName.c_str()); AppFaultDataBySA faultDataSA; - if (info.eventName.find("HALF") == std::string::npos) { + if (info.eventName == AppFreezeType::LIFECYCLE_TIMEOUT) { std::ifstream statmStream("/proc/" + std::to_string(info.pid) + "/statm"); if (statmStream) { std::string procStatm; diff --git a/services/appdfr/src/application_anr_listener.cpp b/services/appdfr/src/application_anr_listener.cpp index 5dc02de9829..2a227ac69e6 100644 --- a/services/appdfr/src/application_anr_listener.cpp +++ b/services/appdfr/src/application_anr_listener.cpp @@ -25,15 +25,25 @@ #include "hilog_tag_wrapper.h" #include "hisysevent.h" #include "time_util.h" +#include "parameters.h" namespace OHOS { namespace AAFwk { +namespace { +const bool BETA_VERSION = OHOS::system::GetParameter("const.logsystem.versiontype", "unknown") == "beta"; +} ApplicationAnrListener::ApplicationAnrListener() {} ApplicationAnrListener::~ApplicationAnrListener() {} void ApplicationAnrListener::OnAnr(int32_t pid, int32_t eventId) const { + if (!BETA_VERSION) { + int32_t ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::AAFWK, "HIVIEW_HALF_FREEZE_LOG", + HiviewDFX::HiSysEvent::EventType::FAULT, "PID", pid, "PACKAGE_NAME", ""); + TAG_LOGW(AAFwkTag::APPDFR, "hisysevent write HIVIEW_HALF_FREEZE_LOG, pid:%{public}d, packageName:," + " ret:%{public}d", pid, ret); + } AppExecFwk::AppFaultDataBySA faultData; std::ifstream statmStream("/proc/" + std::to_string(pid) + "/statm"); if (statmStream) { -- Gitee