diff --git a/native_engine/impl/ark/ark_idle_monitor.cpp b/native_engine/impl/ark/ark_idle_monitor.cpp index 0a01eb549742477220fe804c175d22ea05ffd4c9..6a15b8e4e2f231a47a937f052f23134aad7a5db7 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 1a83cebf678cd387210b0b8fbd47fd5667d5f4ba..97a93877522964138c318ba43255c74993d945b4 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;