1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef RESSCHED_EXECUTOR_SERVICES_RESSCHEDEXEMGR_INCLUDE_RES_SCHED_EXE_MGR_H 17 #define RESSCHED_EXECUTOR_SERVICES_RESSCHEDEXEMGR_INCLUDE_RES_SCHED_EXE_MGR_H 18 19 #include <cstdint> 20 #include <string> 21 #include <sys/types.h> 22 23 #include "event_handler.h" 24 #include "nlohmann/json.hpp" 25 #include "single_instance.h" 26 27 namespace OHOS { 28 namespace ResourceSchedule { 29 class ResSchedExeMgr { 30 DECLARE_SINGLE_INSTANCE(ResSchedExeMgr); 31 32 public: 33 /** 34 * Init resource schedule manager. 35 */ 36 void Init(); 37 38 /** 39 * Stop resource schedule manager. 40 */ 41 void Stop(); 42 43 /** 44 * Send request sync inner, will report resource schedule executor data. 45 * 46 * @param resType Resource type. 47 * @param value bit64 content. 48 * @param payload Extra content. 49 * @param reply Reply content. 50 */ 51 int32_t SendRequestSync(uint32_t resType, int64_t value, 52 const nlohmann::json& payload, nlohmann::json& reply); 53 54 /** 55 * Send request async inner, will report resource schedule executor data. 56 * 57 * @param resType Resource type. 58 * @param value bit64 content. 59 * @param payload Extra content. 60 */ 61 void SendRequestAsync(uint32_t resType, int64_t value, const nlohmann::json& payload = nullptr); 62 63 /** 64 * @brief Send kill process request async to the ressched_executor. 65 * 66 * @param pid the pid whiche will be killed. 67 */ 68 int32_t KillProcess(pid_t pid); 69 70 private: 71 std::string BuildTraceStr(const std::string& func, uint32_t resType, int64_t value); 72 void InitPluginMgr(const nlohmann::json& payload); 73 void HandleRequestForCgroup(uint32_t resType, const nlohmann::json& payload, nlohmann::json& reply); 74 void GetCgroupFileContent(uint32_t resType, const nlohmann::json& payload, nlohmann::json& reply); 75 void CheckProcTaskForCgroup(uint32_t resType, const nlohmann::json& payload, nlohmann::json& reply); 76 77 bool isInit = false; 78 }; 79 } // namespace ResourceSchedule 80 } // namespace OHOS 81 82 #endif // RESSCHED_EXECUTOR_SERVICES_RESSCHEDEXEMGR_INCLUDE_RES_SCHED_EXE_MGR_H 83