From 13ed10db3be333d276fb86aa37edddfebce016d6 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 6 Aug 2022 14:11:35 +0800 Subject: [PATCH] add user Signed-off-by: unknown --- ability_runtime.gni | 2 +- frameworks/native/appkit/app/watchdog.cpp | 16 ++++++++++------ hisysevent.yaml | 8 ++++++++ interfaces/kits/native/appkit/app/watchdog.h | 6 ++++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ability_runtime.gni b/ability_runtime.gni index 193344edfd..6d5a35961a 100644 --- a/ability_runtime.gni +++ b/ability_runtime.gni @@ -53,7 +53,7 @@ declare_args() { ability_runtime_resource = true ability_runtime_appspawn = true efficiency_manager = true - ability_command_for_test = false + ability_command_for_test = true if (!defined(global_parts_info) || defined(global_parts_info.account_os_account)) { diff --git a/frameworks/native/appkit/app/watchdog.cpp b/frameworks/native/appkit/app/watchdog.cpp index 71f24c88ff..8fe695d9d4 100644 --- a/frameworks/native/appkit/app/watchdog.cpp +++ b/frameworks/native/appkit/app/watchdog.cpp @@ -50,9 +50,10 @@ void WatchDog::ProcessEvent(const OHOS::AppExecFwk::InnerEvent::Pointer &event) if (eventId == MAIN_THREAD_IS_ALIVE) { WatchDog::appMainThreadIsAlive_ = true; if (currentHandler_ != nullptr) { - currentHandler_->RemoveTask(MAIN_THREAD_IS_ALIVE_MSG); + currentHandler_->RemoveTask(MAIN_THREAD_TIMEOUT_TASK); } timeOut_.store(false); + isSixSecondEvent_.store(false); } } @@ -137,18 +138,21 @@ bool WatchDog::Timer() return true; } while (!stopWatchDog_) { - if (WaitForDuration(INI_TIMER_SECOND)) { + if (WaitForDuration(CHECK_INTERVAL_TIME)) { HILOG_DEBUG("cvWatchDog2 is stopped"); return true; } auto timeoutTask = [&]() { - timeOut_.store(true); + if (isSixSecondEvent_) { + timeOut_.store(true); + } appMainThreadIsAlive_ = false; - std::string eventType = "THREAD_BLOCK_3S"; + std::string eventType = isSixSecondEvent_ ? "THREAD_BLOCK_6S" : "THREAD_BLOCK_3S"; std::string msgContent = "App main thread is not response!"; MainHandlerDumper handlerDumper; appMainHandler_->Dump(handlerDumper); msgContent += handlerDumper.GetDumpInfo(); + isSixSecondEvent_.store(true); if (applicationInfo_ != nullptr) { OHOS::HiviewDFX::HiSysEvent::Write(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, eventType, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, @@ -171,11 +175,11 @@ bool WatchDog::Timer() const char *hook_mode = "startup:"; int ret = GetParameter("libc.hook_mode", "", paramOutBuf, bufferLen); if (ret <= 0 || strncmp(paramOutBuf, hook_mode, strlen(hook_mode)) != 0) { - currentHandler_->PostTask(timeoutTask, MAIN_THREAD_IS_ALIVE_MSG, MAIN_THREAD_TIMEOUT_TIME); + currentHandler_->PostTask(timeoutTask, MAIN_THREAD_TIMEOUT_TASK, CHECK_INTERVAL_TIME); } } if (appMainHandler_ != nullptr) { - appMainHandler_->SendEvent(MAIN_THREAD_IS_ALIVE); + appMainHandler_->SendEvent(CHECK_MAIN_THREAD_IS_ALIVE_MSG); } } return true; diff --git a/hisysevent.yaml b/hisysevent.yaml index c006318bbc..26a6418a3d 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -47,6 +47,14 @@ THREAD_BLOCK_3S: PROCESS_NAME: {type: STRING, desc: process name} MSG: {type: STRING, desc: application event message} +THREAD_BLOCK_6S: + __BASE: {type: FAULT, level: CRITICAL, tag: STABILITY, desc: application freeze} + PID: {type: INT32, desc: pid} + UID: {type: INT32, desc: uid} + PACKAGE_NAME: {type: STRING, desc: package name} + PROCESS_NAME: {type: STRING, desc: process name} + MSG: {type: STRING, desc: application event message} + # fault event START_ABILITY_ERROR: diff --git a/interfaces/kits/native/appkit/app/watchdog.h b/interfaces/kits/native/appkit/app/watchdog.h index ca9951f03e..743954016e 100644 --- a/interfaces/kits/native/appkit/app/watchdog.h +++ b/interfaces/kits/native/appkit/app/watchdog.h @@ -26,10 +26,11 @@ namespace OHOS { namespace AppExecFwk { constexpr uint32_t MAIN_THREAD_IS_ALIVE = 0; -constexpr uint32_t MAIN_THREAD_TIMEOUT_TIME = 6000; +constexpr uint32_t CHECK_INTERVAL_TIME = 3000; constexpr uint32_t INI_TIMER_FIRST_SECOND = 10000; -constexpr uint32_t INI_TIMER_SECOND = 3000; +constexpr const char* CHECK_MAIN_THREAD_IS_ALIVE_MSG = "CHECK_MAIN_THREAD_IS_ALIVE"; constexpr const char* MAIN_THREAD_IS_ALIVE_MSG = "MAIN_THREAD_IS_ALIVE"; +constexpr const char* MAIN_THREAD_TIMEOUT_TASK = "MAIN_THREAD_TIMEOUT_TASK"; class WatchDog : public EventHandler { public: WatchDog(const std::shared_ptr &runner); @@ -97,6 +98,7 @@ private: std::atomic_bool stopWatchDog_ = false; std::atomic timeOut_ = false; + std::atomic_bool isSixSecondEvent_ = false; std::shared_ptr applicationInfo_ = nullptr; std::shared_ptr watchDogThread_ = nullptr; std::shared_ptr watchDogRunner_ = nullptr;