From daea4fa1cd3d2b092983d4b2e37d292a587cb5ff Mon Sep 17 00:00:00 2001 From: Jessica Date: Sat, 22 Feb 2025 18:47:57 +0800 Subject: [PATCH 1/5] add dfx hilog to solve problem of catching stacks too late. Signed-off-by: Jessica --- .../native/appkit/dfr/appfreeze_inner.cpp | 11 +++++-- services/appdfr/src/appfreeze_manager.cpp | 32 ++++++++++++++----- services/appmgr/src/app_mgr_service_inner.cpp | 13 ++++++-- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/frameworks/native/appkit/dfr/appfreeze_inner.cpp b/frameworks/native/appkit/dfr/appfreeze_inner.cpp index a98723eea8..1817a744f8 100644 --- a/frameworks/native/appkit/dfr/appfreeze_inner.cpp +++ b/frameworks/native/appkit/dfr/appfreeze_inner.cpp @@ -179,6 +179,8 @@ int AppfreezeInner::AppfreezeHandle(const FaultData& faultData, bool onlyMainThr handlinglist_.emplace_back(faultData); constexpr int HANDLING_MIN_SIZE = 1; if (handlinglist_.size() <= HANDLING_MIN_SIZE) { + TAG_LOGI(AAFwkTag::APPDFR, "submit reportAppFreeze, eventName:%{public}s, startTime:%{public}s\n", + faultData.errorObject.name.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); ffrt::submit(reportFreeze, {}, {}, ffrt::task_attr().name("reportAppFreeze")); } } @@ -199,7 +201,11 @@ int AppfreezeInner::AcquireStack(const FaultData& info, bool onlyMainThread) HITRACE_METER_FMT(HITRACE_TAG_APP, "AppfreezeInner::AcquireStack name:%s", info.errorObject.name.c_str()); std::string stack = ""; std::string msgContent; + TAG_LOGI(AAFwkTag::APPDFR, "get mainhandler dump, eventName:%{public}s, startTime:%{public}s\n", + info.errorObject.name.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); GetMainHandlerDump(msgContent); + TAG_LOGI(AAFwkTag::APPDFR, "get mainhandler dump, eventName:%{public}s, endTime:%{public}s\n", + info.errorObject.name.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); std::lock_guard lock(handlingMutex_); for (auto it = handlinglist_.begin(); it != handlinglist_.end(); it = handlinglist_.erase(it)) { @@ -261,8 +267,9 @@ int AppfreezeInner::NotifyANR(const FaultData& faultData) } int32_t pid = static_cast(getpid()); - TAG_LOGW(AAFwkTag::APPDFR, "NotifyAppFault:%{public}s, pid:%{public}d, bundleName:%{public}s", - faultData.errorObject.name.c_str(), pid, applicationInfo->bundleName.c_str()); + TAG_LOGW(AAFwkTag::APPDFR, "NotifyAppFault:%{public}s, pid:%{public}d, bundleName:%{public}s " + "currentTime:%{public}s\n", faultData.errorObject.name.c_str(), pid, applicationInfo->bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); int ret = DelayedSingleton::GetInstance()->NotifyAppFault(faultData); if (ret != 0) { diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index 0bac16e613..889d81178a 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -156,7 +156,14 @@ void AppfreezeManager::CollectFreezeSysMemory(std::string& memoryContent) int AppfreezeManager::MergeNotifyInfo(FaultData& faultNotifyData, const AppfreezeManager::AppInfo& appInfo) { std::string memoryContent = ""; + TAG_LOGW(AAFwkTag::APPDFR, "collect memory info, eventName:%{public}s, bundleName:%{public}s, " + "startTime:%{public}s", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); CollectFreezeSysMemory(memoryContent); + TAG_LOGW(AAFwkTag::APPDFR, "collect memory info, eventName:%{public}s, bundleName:%{public}s, " + "endTime:%{public}s", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + std::string fileName = faultNotifyData.errorObject.name + "_" + AbilityRuntime::TimeUtil::FormatTime("%Y%m%d%H%M%S") + "_" + std::to_string(appInfo.pid) + "_stack"; std::string catcherStack = ""; @@ -168,12 +175,17 @@ int AppfreezeManager::MergeNotifyInfo(FaultData& faultNotifyData, const Appfreez fullStackPath = WriteToFile(fileName, catcherStack); faultNotifyData.errorObject.stack = fullStackPath; } else { - auto start = GetMilliseconds(); - std::string timeStamp = "\nTimestamp:" + AbilityRuntime::TimeUtil::FormatTime("%Y-%m-%d %H:%M:%S") + - ":" + std::to_string(start % SEC_TO_MILLISEC); - faultNotifyData.errorObject.message += timeStamp; + std::string currentTime = AbilityRuntime::TimeUtil::DefaultCurrentTimeStr(); + faultNotifyData.errorObject.message += "\nTimestamp:" + currentTime; + TAG_LOGW(AAFwkTag::APPDFR, "catch stack, eventName:%{public}s, bundleName:%{public}s, " + "startTime:%{public}s", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), + currentTime.c_str()); catchJsonStack += CatchJsonStacktrace(appInfo.pid, faultNotifyData.errorObject.name, faultNotifyData.errorObject.stack); + TAG_LOGW(AAFwkTag::APPDFR, "catch stack, eventName:%{public}s, bundleName:%{public}s, " + "endTime:%{public}s", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + fullStackPath = WriteToFile(fileName, catchJsonStack); faultNotifyData.errorObject.stack = fullStackPath; } @@ -191,8 +203,9 @@ int AppfreezeManager::MergeNotifyInfo(FaultData& faultNotifyData, const Appfreez int AppfreezeManager::AppfreezeHandleWithStack(const FaultData& faultData, const AppfreezeManager::AppInfo& appInfo) { - TAG_LOGD(AAFwkTag::APPDFR, "called %{public}s, bundleName %{public}s, name_ %{public}s", - faultData.errorObject.name.c_str(), appInfo.bundleName.c_str(), name_.c_str()); + TAG_LOGW(AAFwkTag::APPDFR, "NotifyAppFaultTask called, eventName:%{public}s, bundleName:%{public}s, " + "name_:%{public}s, currentTime:%{public}s", faultData.errorObject.name.c_str(), appInfo.bundleName.c_str(), + name_.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); if (!IsHandleAppfreeze(appInfo.bundleName)) { return -1; } @@ -343,6 +356,9 @@ int AppfreezeManager::NotifyANR(const FaultData& faultData, const AppfreezeManag DelayedSingleton::GetInstance()->GetAppRunningUniqueIdByPid(appInfo.pid, appRunningUniqueId); int ret = 0; + TAG_LOGW(AAFwkTag::APPDFR, "write hisysevent, eventName:%{public}s, bundleName:%{public}s, " + "startTime:%{public}s", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); if (faultData.errorObject.name == AppFreezeType::APP_INPUT_BLOCK) { ret = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, faultData.errorObject.name, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, EVENT_UID, appInfo.uid, EVENT_PID, appInfo.pid, @@ -360,9 +376,9 @@ int AppfreezeManager::NotifyANR(const FaultData& faultData, const AppfreezeManag } TAG_LOGI(AAFwkTag::APPDFR, "reportEvent:%{public}s, pid:%{public}d, tid:%{public}d, bundleName:%{public}s, appRunningUniqueId:%{public}s" - ", eventId:%{public}d hisysevent write ret: %{public}d", + ", endTime:%{public}s, eventId:%{public}d hisysevent write ret: %{public}d", faultData.errorObject.name.c_str(), appInfo.pid, faultData.tid, appInfo.bundleName.c_str(), - appRunningUniqueId.c_str(), faultData.eventId, ret); + appRunningUniqueId.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), faultData.eventId, ret); return 0; } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 109abb7482..8821859adc 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -6449,9 +6449,14 @@ int32_t AppMgrServiceInner::SubmitDfxFaultTask(const FaultData &faultData, const TAG_LOGW(AAFwkTag::APPMGR, "get dfx handler fail"); return ERR_INVALID_VALUE; } - TAG_LOGI(AAFwkTag::APPMGR, "dfx submit freeze task start."); + TAG_LOGW(AAFwkTag::APPDFR, "submit NotifyAppFaultTask, eventName:%{public}s, bundleName:%{public}s, " + "startTime:%{public}s", faultData.errorObject.name.c_str(), bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); dfxTaskHandler_->SubmitTask(notifyAppTask, "NotifyAppFaultTask"); - TAG_LOGI(AAFwkTag::APPMGR, "dfx submit freeze task end."); + TAG_LOGW(AAFwkTag::APPDFR, "submit NotifyAppFaultTask, eventName:%{public}s, bundleName:%{public}s, " + "endTime:%{public}s", faultData.errorObject.name.c_str(), bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + constexpr int delayTime = 15 * 1000; // 15s auto task = [pid, innerService = shared_from_this()]() { AppExecFwk::AppfreezeManager::GetInstance()->DeleteStack(pid); @@ -6476,6 +6481,10 @@ int32_t AppMgrServiceInner::NotifyAppFault(const FaultData &faultData) return ERR_OK; } std::string bundleName = appRecord->GetBundleName(); + + TAG_LOGW(AAFwkTag::APPDFR, "called, eventName:%{public}s, bundleName:%{public}s, currentTime:%{public}s", + faultData.errorObject.name.c_str(), bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); if (AppExecFwk::AppfreezeManager::GetInstance()->IsProcessDebug(pid, bundleName)) { TAG_LOGW(AAFwkTag::APPMGR, "don't report event and kill:%{public}s, pid:%{public}d, bundleName:%{public}s", From 7840ce21af0911e2d5117de83dd026035038a4f5 Mon Sep 17 00:00:00 2001 From: Jessica Date: Mon, 24 Feb 2025 10:34:51 +0800 Subject: [PATCH 2/5] add dfx hilog to solve problem of catching stacks too late. Signed-off-by: Jessica --- services/appdfr/src/appfreeze_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index 889d81178a..1f6e339399 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -357,8 +357,8 @@ int AppfreezeManager::NotifyANR(const FaultData& faultData, const AppfreezeManag appRunningUniqueId); int ret = 0; TAG_LOGW(AAFwkTag::APPDFR, "write hisysevent, eventName:%{public}s, bundleName:%{public}s, " - "startTime:%{public}s", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), - AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + "startTime:%{public}s", faultData.errorObject.name.c_str(), appInfo.bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); if (faultData.errorObject.name == AppFreezeType::APP_INPUT_BLOCK) { ret = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, faultData.errorObject.name, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, EVENT_UID, appInfo.uid, EVENT_PID, appInfo.pid, From 8f8143d2ef287ba50055f6ccfcb8091c068e26b6 Mon Sep 17 00:00:00 2001 From: Jessica Date: Mon, 24 Feb 2025 19:19:37 +0800 Subject: [PATCH 3/5] add dfx hilog to solve problem of catching stacks too late. Signed-off-by: Jessica --- .../native/appkit/dfr/appfreeze_inner.cpp | 10 +++---- services/appdfr/src/appfreeze_manager.cpp | 27 ++++++++----------- services/appmgr/src/app_mgr_service_inner.cpp | 8 +++--- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/frameworks/native/appkit/dfr/appfreeze_inner.cpp b/frameworks/native/appkit/dfr/appfreeze_inner.cpp index 1817a744f8..19743cb59b 100644 --- a/frameworks/native/appkit/dfr/appfreeze_inner.cpp +++ b/frameworks/native/appkit/dfr/appfreeze_inner.cpp @@ -179,7 +179,7 @@ int AppfreezeInner::AppfreezeHandle(const FaultData& faultData, bool onlyMainThr handlinglist_.emplace_back(faultData); constexpr int HANDLING_MIN_SIZE = 1; if (handlinglist_.size() <= HANDLING_MIN_SIZE) { - TAG_LOGI(AAFwkTag::APPDFR, "submit reportAppFreeze, eventName:%{public}s, startTime:%{public}s\n", + TAG_LOGW(AAFwkTag::APPDFR, "submit reportAppFreeze, eventName:%{public}s, startTime:%{public}s\n", faultData.errorObject.name.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); ffrt::submit(reportFreeze, {}, {}, ffrt::task_attr().name("reportAppFreeze")); } @@ -201,11 +201,11 @@ int AppfreezeInner::AcquireStack(const FaultData& info, bool onlyMainThread) HITRACE_METER_FMT(HITRACE_TAG_APP, "AppfreezeInner::AcquireStack name:%s", info.errorObject.name.c_str()); std::string stack = ""; std::string msgContent; - TAG_LOGI(AAFwkTag::APPDFR, "get mainhandler dump, eventName:%{public}s, startTime:%{public}s\n", - info.errorObject.name.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + int64_t startTime = AbilityRuntime::TimeUtil::CurrentTimeMillis(); GetMainHandlerDump(msgContent); - TAG_LOGI(AAFwkTag::APPDFR, "get mainhandler dump, eventName:%{public}s, endTime:%{public}s\n", - info.errorObject.name.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + TAG_LOGW(AAFwkTag::APPDFR, "get mainhandler dump, eventName:%{public}s, endTime:%{public}s, interval:%{public}ldms", + info.errorObject.name.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), + AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); std::lock_guard lock(handlingMutex_); for (auto it = handlinglist_.begin(); it != handlinglist_.end(); it = handlinglist_.erase(it)) { diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index 1f6e339399..180f40d9a6 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -156,13 +156,11 @@ void AppfreezeManager::CollectFreezeSysMemory(std::string& memoryContent) int AppfreezeManager::MergeNotifyInfo(FaultData& faultNotifyData, const AppfreezeManager::AppInfo& appInfo) { std::string memoryContent = ""; - TAG_LOGW(AAFwkTag::APPDFR, "collect memory info, eventName:%{public}s, bundleName:%{public}s, " - "startTime:%{public}s", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), - AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + int64_t startTime = AbilityRuntime::TimeUtil::CurrentTimeMillis(); CollectFreezeSysMemory(memoryContent); TAG_LOGW(AAFwkTag::APPDFR, "collect memory info, eventName:%{public}s, bundleName:%{public}s, " - "endTime:%{public}s", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), - AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + "endTime:%{public}s, interval:%{public}ldms", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); std::string fileName = faultNotifyData.errorObject.name + "_" + AbilityRuntime::TimeUtil::FormatTime("%Y%m%d%H%M%S") + "_" + std::to_string(appInfo.pid) + "_stack"; @@ -176,15 +174,13 @@ int AppfreezeManager::MergeNotifyInfo(FaultData& faultNotifyData, const Appfreez faultNotifyData.errorObject.stack = fullStackPath; } else { std::string currentTime = AbilityRuntime::TimeUtil::DefaultCurrentTimeStr(); + int64_t startTime = AbilityRuntime::TimeUtil::CurrentTimeMillis(); faultNotifyData.errorObject.message += "\nTimestamp:" + currentTime; - TAG_LOGW(AAFwkTag::APPDFR, "catch stack, eventName:%{public}s, bundleName:%{public}s, " - "startTime:%{public}s", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), - currentTime.c_str()); catchJsonStack += CatchJsonStacktrace(appInfo.pid, faultNotifyData.errorObject.name, faultNotifyData.errorObject.stack); TAG_LOGW(AAFwkTag::APPDFR, "catch stack, eventName:%{public}s, bundleName:%{public}s, " - "endTime:%{public}s", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), - AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + "endTime:%{public}s, interval:%{public}ldms", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); fullStackPath = WriteToFile(fileName, catchJsonStack); faultNotifyData.errorObject.stack = fullStackPath; @@ -356,9 +352,7 @@ int AppfreezeManager::NotifyANR(const FaultData& faultData, const AppfreezeManag DelayedSingleton::GetInstance()->GetAppRunningUniqueIdByPid(appInfo.pid, appRunningUniqueId); int ret = 0; - TAG_LOGW(AAFwkTag::APPDFR, "write hisysevent, eventName:%{public}s, bundleName:%{public}s, " - "startTime:%{public}s", faultData.errorObject.name.c_str(), appInfo.bundleName.c_str(), - AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + int64_t startTime = AbilityRuntime::TimeUtil::CurrentTimeMillis(); if (faultData.errorObject.name == AppFreezeType::APP_INPUT_BLOCK) { ret = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, faultData.errorObject.name, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, EVENT_UID, appInfo.uid, EVENT_PID, appInfo.pid, @@ -374,11 +368,12 @@ int AppfreezeManager::NotifyANR(const FaultData& faultData, const AppfreezeManag faultData.errorObject.message, EVENT_STACK, faultData.errorObject.stack, BINDER_INFO, binderInfo, APP_RUNNING_UNIQUE_ID, appRunningUniqueId, FREEZE_MEMORY, memoryContent); } - TAG_LOGI(AAFwkTag::APPDFR, + TAG_LOGW(AAFwkTag::APPDFR, "reportEvent:%{public}s, pid:%{public}d, tid:%{public}d, bundleName:%{public}s, appRunningUniqueId:%{public}s" - ", endTime:%{public}s, eventId:%{public}d hisysevent write ret: %{public}d", + ", endTime:%{public}s, interval:%{public}ldms, eventId:%{public}d hisysevent write ret: %{public}d", faultData.errorObject.name.c_str(), appInfo.pid, faultData.tid, appInfo.bundleName.c_str(), - appRunningUniqueId.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), faultData.eventId, ret); + appRunningUniqueId.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), + AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime, faultData.eventId, ret); return 0; } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 8821859adc..0169877b8f 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -6449,13 +6449,11 @@ int32_t AppMgrServiceInner::SubmitDfxFaultTask(const FaultData &faultData, const TAG_LOGW(AAFwkTag::APPMGR, "get dfx handler fail"); return ERR_INVALID_VALUE; } - TAG_LOGW(AAFwkTag::APPDFR, "submit NotifyAppFaultTask, eventName:%{public}s, bundleName:%{public}s, " - "startTime:%{public}s", faultData.errorObject.name.c_str(), bundleName.c_str(), - AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + int64_t startTime = AbilityRuntime::TimeUtil::CurrentTimeMillis(); dfxTaskHandler_->SubmitTask(notifyAppTask, "NotifyAppFaultTask"); TAG_LOGW(AAFwkTag::APPDFR, "submit NotifyAppFaultTask, eventName:%{public}s, bundleName:%{public}s, " - "endTime:%{public}s", faultData.errorObject.name.c_str(), bundleName.c_str(), - AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str()); + "endTime:%{public}s, interval:%{public}ldms", faultData.errorObject.name.c_str(), bundleName.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); constexpr int delayTime = 15 * 1000; // 15s auto task = [pid, innerService = shared_from_this()]() { From 100bf53b2aa0ee6a159d4e5e4d35419215b98f03 Mon Sep 17 00:00:00 2001 From: Jessica Date: Mon, 24 Feb 2025 20:04:23 +0800 Subject: [PATCH 4/5] add dfx hilog to solve problem of catching stacks too late. Signed-off-by: Jessica --- frameworks/native/appkit/dfr/appfreeze_inner.cpp | 2 +- services/appdfr/src/appfreeze_manager.cpp | 12 +++++++----- services/appmgr/src/app_mgr_service_inner.cpp | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/frameworks/native/appkit/dfr/appfreeze_inner.cpp b/frameworks/native/appkit/dfr/appfreeze_inner.cpp index 19743cb59b..9917a8ad90 100644 --- a/frameworks/native/appkit/dfr/appfreeze_inner.cpp +++ b/frameworks/native/appkit/dfr/appfreeze_inner.cpp @@ -203,7 +203,7 @@ int AppfreezeInner::AcquireStack(const FaultData& info, bool onlyMainThread) std::string msgContent; int64_t startTime = AbilityRuntime::TimeUtil::CurrentTimeMillis(); GetMainHandlerDump(msgContent); - TAG_LOGW(AAFwkTag::APPDFR, "get mainhandler dump, eventName:%{public}s, endTime:%{public}s, interval:%{public}ldms", + TAG_LOGW(AAFwkTag::APPDFR, "get mainhandler dump, eventName:%{public}s, endTime:%{public}s, interval:%{public}lld ms", info.errorObject.name.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index 180f40d9a6..36496cd2b9 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -159,8 +159,9 @@ int AppfreezeManager::MergeNotifyInfo(FaultData& faultNotifyData, const Appfreez int64_t startTime = AbilityRuntime::TimeUtil::CurrentTimeMillis(); CollectFreezeSysMemory(memoryContent); TAG_LOGW(AAFwkTag::APPDFR, "collect memory info, eventName:%{public}s, bundleName:%{public}s, " - "endTime:%{public}s, interval:%{public}ldms", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), - AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); + "endTime:%{public}s, interval:%{public}lld ms", faultNotifyData.errorObject.name.c_str(), + appInfo.bundleName.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), + AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); std::string fileName = faultNotifyData.errorObject.name + "_" + AbilityRuntime::TimeUtil::FormatTime("%Y%m%d%H%M%S") + "_" + std::to_string(appInfo.pid) + "_stack"; @@ -179,8 +180,9 @@ int AppfreezeManager::MergeNotifyInfo(FaultData& faultNotifyData, const Appfreez catchJsonStack += CatchJsonStacktrace(appInfo.pid, faultNotifyData.errorObject.name, faultNotifyData.errorObject.stack); TAG_LOGW(AAFwkTag::APPDFR, "catch stack, eventName:%{public}s, bundleName:%{public}s, " - "endTime:%{public}s, interval:%{public}ldms", faultNotifyData.errorObject.name.c_str(), appInfo.bundleName.c_str(), - AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); + "endTime:%{public}s, interval:%{public}lld ms", faultNotifyData.errorObject.name.c_str(), + appInfo.bundleName.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), + AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); fullStackPath = WriteToFile(fileName, catchJsonStack); faultNotifyData.errorObject.stack = fullStackPath; @@ -370,7 +372,7 @@ int AppfreezeManager::NotifyANR(const FaultData& faultData, const AppfreezeManag } TAG_LOGW(AAFwkTag::APPDFR, "reportEvent:%{public}s, pid:%{public}d, tid:%{public}d, bundleName:%{public}s, appRunningUniqueId:%{public}s" - ", endTime:%{public}s, interval:%{public}ldms, eventId:%{public}d hisysevent write ret: %{public}d", + ", endTime:%{public}s, interval:%{public}lld ms, eventId:%{public}d hisysevent write ret: %{public}d", faultData.errorObject.name.c_str(), appInfo.pid, faultData.tid, appInfo.bundleName.c_str(), appRunningUniqueId.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime, faultData.eventId, ret); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 0169877b8f..7321b21bf2 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -6452,8 +6452,9 @@ int32_t AppMgrServiceInner::SubmitDfxFaultTask(const FaultData &faultData, const int64_t startTime = AbilityRuntime::TimeUtil::CurrentTimeMillis(); dfxTaskHandler_->SubmitTask(notifyAppTask, "NotifyAppFaultTask"); TAG_LOGW(AAFwkTag::APPDFR, "submit NotifyAppFaultTask, eventName:%{public}s, bundleName:%{public}s, " - "endTime:%{public}s, interval:%{public}ldms", faultData.errorObject.name.c_str(), bundleName.c_str(), - AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); + "endTime:%{public}s, interval:%{public}lld ms", faultData.errorObject.name.c_str(), + bundleName.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), + AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); constexpr int delayTime = 15 * 1000; // 15s auto task = [pid, innerService = shared_from_this()]() { From 015ea25b62e3f9637fb2a21c36f7eabf6ac94dd6 Mon Sep 17 00:00:00 2001 From: Jessica Date: Mon, 24 Feb 2025 20:58:35 +0800 Subject: [PATCH 5/5] add dfx hilog to solve problem of catching stacks too late. Signed-off-by: Jessica --- frameworks/native/appkit/dfr/appfreeze_inner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frameworks/native/appkit/dfr/appfreeze_inner.cpp b/frameworks/native/appkit/dfr/appfreeze_inner.cpp index 9917a8ad90..bfc3b75d7c 100644 --- a/frameworks/native/appkit/dfr/appfreeze_inner.cpp +++ b/frameworks/native/appkit/dfr/appfreeze_inner.cpp @@ -203,8 +203,9 @@ int AppfreezeInner::AcquireStack(const FaultData& info, bool onlyMainThread) std::string msgContent; int64_t startTime = AbilityRuntime::TimeUtil::CurrentTimeMillis(); GetMainHandlerDump(msgContent); - TAG_LOGW(AAFwkTag::APPDFR, "get mainhandler dump, eventName:%{public}s, endTime:%{public}s, interval:%{public}lld ms", - info.errorObject.name.c_str(), AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), + TAG_LOGW(AAFwkTag::APPDFR, "get mainhandler dump, eventName:%{public}s, endTime:%{public}s, " + "interval:%{public}lld ms", info.errorObject.name.c_str(), + AbilityRuntime::TimeUtil::DefaultCurrentTimeStr().c_str(), AbilityRuntime::TimeUtil::CurrentTimeMillis() - startTime); std::lock_guard lock(handlingMutex_);