From 8cd39f31dab79b3569f8c965223ee483e6784ab7 Mon Sep 17 00:00:00 2001 From: jinjiawei Date: Wed, 25 Jun 2025 14:42:56 +0800 Subject: [PATCH] add IDLE_MONITORING_INTERVAL Configurable Issue: https://gitee.com/openharmony/arkui_napi/issues/ICH4V8 Signed-off-by: jinjiawei Change-Id: Id8024050c7fe58883543f2411de07c765f58e163 --- native_engine/impl/ark/ark_idle_monitor.cpp | 18 ++++++++++++------ native_engine/impl/ark/ark_idle_monitor.h | 7 +++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/native_engine/impl/ark/ark_idle_monitor.cpp b/native_engine/impl/ark/ark_idle_monitor.cpp index 0a01eb549..6a15b8e4e 100644 --- a/native_engine/impl/ark/ark_idle_monitor.cpp +++ b/native_engine/impl/ark/ark_idle_monitor.cpp @@ -36,9 +36,15 @@ namespace panda::ecmascript { #if defined(ENABLE_EVENT_HANDLER) +uint64_t ArkIdleMonitor::gIdleMonitoringInterval = + OHOS::system::GetIntParameter("const.arkui.idle_monitoring_interval", 1000); // ms bool ArkIdleMonitor::gEnableIdleGC = OHOS::system::GetBoolParameter("persist.ark.enableidlegc", true); +#else +uint64_t ArkIdleMonitor::gIdleMonitoringInterval = 1000; // ms #endif +// gDelayOverTime Detect whether there is any process freezing during the delay process of the delay task +uint64_t ArkIdleMonitor::gDelayOverTime = gIdleMonitoringInterval + 100; // ms void ArkIdleMonitor::NotifyLooperIdleStart(int64_t timestamp, [[maybe_unused]] int idleTime) { @@ -169,17 +175,17 @@ void ArkIdleMonitor::IntervalMonitor() int64_t intervalDuration = nowTimestamp - intervalTimestamp_; if (numberOfLowIdleNotifyCycles_ >= checkCounts && numberOfHighIdleTimeRatio_ >= checkCounts && - intervalDuration < static_cast(DELAY_OVER_TIME)) { + intervalDuration < static_cast(gDelayOverTime)) { NotifyMainThreadTryCompressGC(); PostMonitorTask(SLEEP_MONITORING_INTERVAL); ClearIdleStats(); } else if (numberOfLowIdleNotifyCycles_ >= workThreadCheckCounts && numberOfHighIdleTimeRatio_ >= workThreadCheckCounts && - intervalDuration < static_cast(DELAY_OVER_TIME)) { + intervalDuration < static_cast(gDelayOverTime)) { NotifyOneWorkerThreadTryCompressGC(); - PostMonitorTask(IDLE_MONITORING_INTERVAL); + PostMonitorTask(gIdleMonitoringInterval); } else { - PostMonitorTask(IDLE_MONITORING_INTERVAL); + PostMonitorTask(gIdleMonitoringInterval); } intervalTimestamp_ = nowTimestamp; timerMutex_.unlock(); @@ -447,7 +453,7 @@ void ArkIdleMonitor::SwitchBackgroundCheckGCTask(int64_t timestamp, int64_t idle double idlePercentage = static_cast(sumIdleDuration) / static_cast(sumDuration); double cpuUsage = GetCpuUsage(); if (idlePercentage > BACKGROUND_IDLE_RATIO && cpuUsage <= IDLE_BACKGROUND_CPU_USAGE && - sumDuration < static_cast(DELAY_OVER_TIME)) { + sumDuration < static_cast(gDelayOverTime)) { NotifyMainThreadTryCompressGCByBackground(); } else { HILOG_INFO("ArkIdleMonitor cancel BGGCTask,idlePer:%{public}.2f;cpuUsage:%{public}.2f;duration:%{public}s", @@ -476,7 +482,7 @@ void ArkIdleMonitor::PostSwitchBackgroundGCTask() std::get<0>(*tuple)->SwitchBackgroundCheckGCTask(std::get<1>(*tuple), std::get<2>(*tuple)); delete tuple; }; - switchBackgroundTimerHandler_ = ffrt_timer_start(ffrt_qos_user_initiated, IDLE_MONITORING_INTERVAL, + switchBackgroundTimerHandler_ = ffrt_timer_start(ffrt_qos_user_initiated, gIdleMonitoringInterval, reinterpret_cast(data), task, false); #endif } diff --git a/native_engine/impl/ark/ark_idle_monitor.h b/native_engine/impl/ark/ark_idle_monitor.h index 1a83cebf6..97a938775 100644 --- a/native_engine/impl/ark/ark_idle_monitor.h +++ b/native_engine/impl/ark/ark_idle_monitor.h @@ -179,7 +179,7 @@ public: void NotifyLooperIdleStart(int64_t timestamp, int idleTime); void NotifyLooperIdleEnd(int64_t timestamp); - void PostMonitorTask(uint64_t delayMs = IDLE_MONITORING_INTERVAL); + void PostMonitorTask(uint64_t delayMs); void SetStartTimerCallback(); void PostLooperTriggerIdleGCTask(); void EnableIdleGC(NativeEngine *engine); @@ -215,10 +215,7 @@ private: static constexpr int IDLE_CHECK_INTERVAL_LENGTH = 4; static constexpr int MIN_TRIGGER_FULLGC_INTERVAL = 90; static constexpr int LOW_IDLE_NOTIFY_THRESHOLD = 10; - static constexpr uint64_t IDLE_MONITORING_INTERVAL = 1 * 1000; // ms static constexpr uint64_t SLEEP_MONITORING_INTERVAL = 90 * 1000; // ms - // DELAY_OVER_TIME Detect whether there is any process freezing during the delay process of the delay task - static constexpr uint64_t DELAY_OVER_TIME = IDLE_MONITORING_INTERVAL + 100; //ms static constexpr int64_t MIN_TRIGGER_GC_IDLE_INTERVAL = 10; // ms static constexpr int64_t MAX_TRIGGER_GC_RUNNING_INTERVAL = 1; //ms static constexpr double IDLE_RATIO = 0.985f; @@ -254,6 +251,8 @@ private: std::mutex timerMutex_; std::mutex queueMutex_; std::queue workerEnvQueue_; + static uint64_t gIdleMonitoringInterval; + static uint64_t gDelayOverTime; #if defined(ENABLE_EVENT_HANDLER) std::shared_ptr mainThreadHandler_ {}; static bool gEnableIdleGC; -- Gitee