From c6e47c5140b89c565905994b1b8ce519a9a5e971 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 15 Feb 2024 20:44:51 +0100 Subject: [PATCH] Add support for reporting key threads Signed-off-by: J-P Nurmi Change-Id: I1107fa0023a26df242f4325d19b4a0d56ea649fa codecheck formatting Change-Id: I035fa00614004a3fb1476c62c9b980426f170df5 --- .../frame_aware_policy/include/app_info.h | 5 +++ .../include/intellisense_server.h | 1 + .../core/frame_aware_policy/src/app_info.cpp | 16 ++++++++ .../src/intellisense_server.cpp | 39 +++++++++++++++++++ .../innerkits/frameintf/frame_msg_intf.cpp | 13 +++++++ .../innerkits/frameintf/frame_msg_intf.h | 1 + 6 files changed, 75 insertions(+) diff --git a/frameworks/core/frame_aware_policy/include/app_info.h b/frameworks/core/frame_aware_policy/include/app_info.h index 06919d5..556d058 100644 --- a/frameworks/core/frame_aware_policy/include/app_info.h +++ b/frameworks/core/frame_aware_policy/include/app_info.h @@ -18,6 +18,7 @@ #include #include +#include namespace OHOS { namespace RME { @@ -48,6 +49,9 @@ public: void SetRenderTid(const int tid); int GetRenderTid(); + void AddKeyTid(const int tid); + void RemoveKeyTid(const int tid); + std::unordered_set GetKeyTids(); void SetUiTid(const int tid); int GetUiTid(); void SetAppName(const std::string appName); @@ -66,6 +70,7 @@ private: int m_uid; int m_uiTid; int m_renderTid; + std::unordered_set m_keyTids; int m_isFocus; int m_rtGrp; AppState m_appState; diff --git a/frameworks/core/frame_aware_policy/include/intellisense_server.h b/frameworks/core/frame_aware_policy/include/intellisense_server.h index ed01efe..4b53d75 100644 --- a/frameworks/core/frame_aware_policy/include/intellisense_server.h +++ b/frameworks/core/frame_aware_policy/include/intellisense_server.h @@ -40,6 +40,7 @@ public: void ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup); void ReportWindowFocus(const int pid, const int uid, int isFocus); void ReportRenderThread(const int pid, const int uid, int renderTid); + void ReportKeyThread(const int pid, const int uid, int tid, int role); void ReportContinuousTask(const int pid, const int uid, const int status); bool ReadXml(); void SetPara(const int32_t currentFps, const int32_t currentRenderType); diff --git a/frameworks/core/frame_aware_policy/src/app_info.cpp b/frameworks/core/frame_aware_policy/src/app_info.cpp index 474d83e..25786ec 100644 --- a/frameworks/core/frame_aware_policy/src/app_info.cpp +++ b/frameworks/core/frame_aware_policy/src/app_info.cpp @@ -23,6 +23,7 @@ AppInfo::AppInfo(int pid, int uid) m_uid(uid), m_uiTid(0), m_renderTid(0), + m_keyTids({}), m_isFocus(0), m_rtGrp(0), m_appState(AppState::APP_TERMINATED) @@ -38,6 +39,21 @@ int AppInfo::GetRenderTid() return m_renderTid; } +void AppInfo::AddKeyTid(const int tid) +{ + this->m_keyTids.insert(tid); +} + +void AppInfo::RemoveKeyTid(const int tid) +{ + this->m_keyTids.erase(tid); +} + +std::unordered_set AppInfo::GetKeyTids() +{ + return m_keyTids; +} + void AppInfo::SetUiTid(const int tid) { this->m_uiTid = tid; diff --git a/frameworks/core/frame_aware_policy/src/intellisense_server.cpp b/frameworks/core/frame_aware_policy/src/intellisense_server.cpp index ce09546..10ab026 100644 --- a/frameworks/core/frame_aware_policy/src/intellisense_server.cpp +++ b/frameworks/core/frame_aware_policy/src/intellisense_server.cpp @@ -132,12 +132,16 @@ int IntelliSenseServer::TryCreateRtgForApp(AppInfo *app) app->SetRtgrp(grpId); int uiTid = app->GetUiTid(); int renderTid = app->GetRenderTid(); + auto keyTids = app->GetKeyTids(); if (uiTid > 0) { AddThreadToRtg(uiTid, grpId, 0); // add ui thread } if (renderTid > 0) { AddThreadToRtg(renderTid, grpId, 0); // add render thread } + for (int keyTid : keyTids) { + AddThreadToRtg(keyTid, grpId, 0); // add key thread + } return grpId; } @@ -225,6 +229,41 @@ void IntelliSenseServer::ReportRenderThread(const int pid, const int uid, int re } } +void IntelliSenseServer::ReportKeyThread(const int pid, const int uid, int tid, int role) +{ + if (uid >= WEB_BASE_UID && uid <= WEB_END_UID) { + return; + } + if (!m_switch) { + return; + } + HITRACE_METER(HITRACE_TAG_ACE); + auto record = GetRecordOfPid(pid); + if (record == m_historyApp.end()) { + RME_LOGE("Didn't find key in history app %{public}d with ui %{public}d", pid, tid); + return; + } + if (role) { + record->AddKeyTid(tid); + } else { + record->RemoveKeyTid(tid); + } + int grpId = record->GetRtgrp(); + if (grpId >= 0) { + int ret = 0; + if (!role) { + ret = RemoveRtgThread(tid); // remove key thread + } else if (record->GetAppState() == AppState::APP_FOREGROUND) { + ret = AddThreadToRtg(tid, grpId, 0); // add key thread + } + RME_LOGE("web test ReportKeyThread uid is %{public}d", uid); + if (ret != 0) { + RME_LOGE("[OnFore]:key thread fail! pid:%{public}d,rtg:%{public}d!ret:%{publid}d", + tid, grpId, ret); + } + } +} + void IntelliSenseServer::ReportContinuousTask(const int pid, const int uid, const int status) { if (!m_switch) { diff --git a/interfaces/innerkits/frameintf/frame_msg_intf.cpp b/interfaces/innerkits/frameintf/frame_msg_intf.cpp index 714856f..317b5aa 100644 --- a/interfaces/innerkits/frameintf/frame_msg_intf.cpp +++ b/interfaces/innerkits/frameintf/frame_msg_intf.cpp @@ -90,6 +90,19 @@ void FrameMsgIntf::ReportRenderThread(const int pid, const int uid, const int re }); } +void FrameMsgIntf::ReportKeyThread(const int pid, const int uid, const int tid, const int role) +{ + std::lock_guard autoLock(frameMsgIntfMutex_); + RME_LOGI("[ReportKeyThread]:key get %{public}d with id %{public}d role %{public}d", pid, tid, role); + if (taskQueue_ == nullptr) { + RME_LOGE("[ReportKeyThread]:taskQueue none!"); + return; + } + taskQueue_->submit([pid, uid, tid, role] { + IntelliSenseServer::GetInstance().ReportKeyThread(pid, uid, tid, role); + }); +} + void FrameMsgIntf::ReportAppInfo(const int pid, const int uid, const std::string bundleName, ThreadState state) { std::lock_guard autoLock(frameMsgIntfMutex_); diff --git a/interfaces/innerkits/frameintf/frame_msg_intf.h b/interfaces/innerkits/frameintf/frame_msg_intf.h index 37e42db..472a03b 100644 --- a/interfaces/innerkits/frameintf/frame_msg_intf.h +++ b/interfaces/innerkits/frameintf/frame_msg_intf.h @@ -33,6 +33,7 @@ public: void ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup); void ReportWindowFocus(const int pid, const int uid, const int isFocus); void ReportRenderThread(const int pid, const int uid, const int renderTid); + void ReportKeyThread(const int pid, const int uid, const int tid, const int role); void ReportContinuousTask(const int pid, const int uid, const int status); void ReportSlideEvent(const int pid, const int uid, const int64_t status); void Stop(); -- Gitee