From b9ffeb80ad5c804d9db6afbc73d433eb2e7a1c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=A4=A9=E6=80=A1?= Date: Wed, 8 Mar 2023 09:05:40 +0000 Subject: [PATCH 1/2] add dump MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 朱天怡 --- services/native/src/work_policy_manager.cpp | 15 +++++++++++++++ services/native/src/work_scheduler_service.cpp | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/services/native/src/work_policy_manager.cpp b/services/native/src/work_policy_manager.cpp index 2055b82..1170c72 100644 --- a/services/native/src/work_policy_manager.cpp +++ b/services/native/src/work_policy_manager.cpp @@ -187,6 +187,21 @@ shared_ptr WorkPolicyManager::FindWorkStatus(WorkInfo& workInfo, int return nullptr; } +shared_ptr WorkPolicyManager::StartWorkByDump(int32_t workId, int32_t uid) +{ + WS_HILOGD("Start work by dump with workId=%{public}d, uid=%{public}d.", workId, uid); + shared_ptr work; + std::lock_guard lock(uidMapMutex_); + if (uidQueueMap_.count(uid) > 0) { + work = uidQueueMap_.at(uid)->Find(WorkStatus::MakeWorkId(workInfo.GetWorkId(), uid)); + } + if (!work) { + RealStartWork(work); + } else { + WS_HILOGE("Failed to start work because work does not exist."); + } +} + void WorkPolicyManager::RemoveFromUidQueue(std::shared_ptr workStatus, int32_t uid) { std::lock_guard lock(uidMapMutex_); diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 87b83be..928611a 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -657,6 +657,20 @@ void WorkSchedulerService::DumpParamSet(std::string &key, std::string &value, st } } +void WorkSchedulerService::DumpParamSet(std::string &key, std::string ¶m, std::string &value, std::string &result) +{ + if (key == "-d") { + EventPublisher eventPublisher; + eventPublisher.Dump(result, param, value); + } else if (key == "-startwork") { + int32_t workId = std::stoi(param); + int32_t uid = std::stoi(value); + workPolicyManager_->SetMemoryByDump(std::stoi(value)); + } else { + result.append("Error params."); + } +} + void WorkSchedulerService::RefreshPersistedWorks() { Json::Value root; -- Gitee From 58207539c12b60bba305b352259810bad1d91c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=A4=A9=E6=80=A1?= Date: Wed, 8 Mar 2023 09:13:05 +0000 Subject: [PATCH 2/2] add dump MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 朱天怡 --- services/native/include/work_policy_manager.h | 7 +++++++ services/native/include/work_scheduler_service.h | 1 + services/native/src/work_policy_manager.cpp | 2 +- services/native/src/work_scheduler_service.cpp | 10 +++------- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/services/native/include/work_policy_manager.h b/services/native/include/work_policy_manager.h index c662a0d..5ee5602 100644 --- a/services/native/include/work_policy_manager.h +++ b/services/native/include/work_policy_manager.h @@ -203,6 +203,13 @@ public: * @return The time of watchdog. */ int32_t GetWatchdogTime(); + /** + * @brief Start work by dump. + * + * @param workId The workId. + * @param uid The uid. + */ + void StartWorkByDump(int32_t workId, int32_t uid); private: int32_t GetMaxRunningCount(); diff --git a/services/native/include/work_scheduler_service.h b/services/native/include/work_scheduler_service.h index c586f59..ba7ed48 100644 --- a/services/native/include/work_scheduler_service.h +++ b/services/native/include/work_scheduler_service.h @@ -276,6 +276,7 @@ private: bool IsBaseAbilityReady(); void DumpUsage(std::string &result); void DumpParamSet(std::string &key, std::string &value, std::string &result); + void DumpParamSet(std::string &key, std::string ¶m, std::string &value, std::string &result); }; } // namespace WorkScheduler } // namespace OHOS diff --git a/services/native/src/work_policy_manager.cpp b/services/native/src/work_policy_manager.cpp index 1170c72..8ec3bc5 100644 --- a/services/native/src/work_policy_manager.cpp +++ b/services/native/src/work_policy_manager.cpp @@ -187,7 +187,7 @@ shared_ptr WorkPolicyManager::FindWorkStatus(WorkInfo& workInfo, int return nullptr; } -shared_ptr WorkPolicyManager::StartWorkByDump(int32_t workId, int32_t uid) +void WorkPolicyManager::StartWorkByDump(int32_t workId, int32_t uid) { WS_HILOGD("Start work by dump with workId=%{public}d, uid=%{public}d.", workId, uid); shared_ptr work; diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index 928611a..8bb5ed9 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -577,12 +577,7 @@ int32_t WorkSchedulerService::Dump(int32_t fd, const std::vector DumpParamSet(argsInStr[DUMP_OPTION], argsInStr[DUMP_PARAM_INDEX], result); break; case DUMP_VALUE_INDEX + 1: - if (argsInStr[DUMP_OPTION] == "-d") { - EventPublisher eventPublisher; - eventPublisher.Dump(result, argsInStr[DUMP_PARAM_INDEX], argsInStr[DUMP_VALUE_INDEX]); - } else { - result.append("Error params."); - } + DumpParamSet(argsInStr[DUMP_OPTION], argsInStr[DUMP_PARAM_INDEX], argsInStr[DUMP_VALUE_INDEX], result); break; default: result.append("Error params."); @@ -665,7 +660,8 @@ void WorkSchedulerService::DumpParamSet(std::string &key, std::string ¶m, st } else if (key == "-startwork") { int32_t workId = std::stoi(param); int32_t uid = std::stoi(value); - workPolicyManager_->SetMemoryByDump(std::stoi(value)); + workPolicyManager_->StartWorkByDump(workId, uid); + result.append("Start work with workId=" + std::to_string(workId) + ", uid=" + std::to_string(uid) + "\n"); } else { result.append("Error params."); } -- Gitee