1 /* 2 * Copyright (c) 2022-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 SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_CONFIG_H 17 #define SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_CONFIG_H 18 19 #include "libxml/tree.h" 20 #include "socperf_common.h" 21 #include <string> 22 #include <vector> 23 24 namespace OHOS { 25 namespace SOCPERF { 26 using ReportDataFunc = int (*)(const std::vector<int32_t>& resId, const std::vector<int64_t>& value, 27 const std::vector<int64_t>& endTime, const std::string& msgStr); 28 using PerfScenarioFunc = int (*)(const std::string& msgStr); 29 class SocPerfConfig { 30 public: 31 bool Init(); 32 bool IsGovResId(int32_t resId) const; 33 bool IsValidResId(int32_t resId) const; 34 static SocPerfConfig& GetInstance(); 35 36 public: 37 ReportDataFunc reportFunc_ = nullptr; 38 PerfScenarioFunc scenarioFunc_ = nullptr; 39 std::mutex resourceNodeMutex_; 40 std::mutex sceneResourceMutex_; 41 std::unordered_map<int32_t, std::shared_ptr<ResourceNode>> resourceNodeInfo_; 42 std::unordered_map<std::string, std::shared_ptr<SceneResNode>> sceneResourceInfo_; 43 std::mutex perfActionsMutex_; 44 std::unordered_map<std::string, std::unordered_map<int32_t, std::shared_ptr<Actions>>> configPerfActionsInfo_; 45 std::vector<std::shared_ptr<InterAction>> interAction_; 46 int32_t minThermalLvl_ = INVALID_THERMAL_LVL; 47 48 private: 49 SocPerfConfig(); 50 ~SocPerfConfig(); 51 std::string GetRealConfigPath(const std::string& configFile); 52 std::vector<std::string> GetAllRealConfigPath(const std::string& configFile); 53 bool LoadAllConfigXmlFile(const std::string& configFile); 54 bool LoadConfigXmlFile(const std::string& realConfigFile); 55 void InitPerfFunc(const char* perfSoPath, const char* perfReportFunc, const char* perfScenarioFunc); 56 void InitPerfScenarioFunc(const char* perfSoPath, const char* perfScenarioFunc); 57 bool ParseBoostXmlFile(const xmlNode* rootNode, const std::string& realConfigFile, xmlDoc* file); 58 bool ParseResourceXmlFile(const xmlNode* rootNode, const std::string& realConfigFile, xmlDoc* file); 59 bool LoadResource(xmlNode* rootNode, const std::string& configFile); 60 bool TraversalFreqResource(xmlNode* grandson, const std::string& configFile); 61 bool LoadFreqResourceContent(int32_t persistMode, xmlNode* greatGrandson, const std::string& configFile, 62 std::shared_ptr<ResNode> resNode); 63 int32_t GetXmlIntProp(const xmlNode* xmlNode, const char* propName, int32_t def) const; 64 bool LoadGovResource(xmlNode* rootNode, const std::string& configFile); 65 bool TraversalGovResource(int32_t persistMode, xmlNode* greatGrandson, const std::string& configFile, 66 std::shared_ptr<GovResNode> govResNode); 67 void LoadInfo(xmlNode* child, const std::string& configFile); 68 bool LoadConfig(const xmlNode* rootNode, const std::string& configFile); 69 bool TraversalBoostResource(xmlNode* grandson, const std::string& configFile, std::shared_ptr<Actions> actions); 70 bool ParseDuration(xmlNode* greatGrandson, const std::string& configFile, std::shared_ptr<Action> action) const; 71 bool ParseResValue(xmlNode* greatGrandson, const std::string& configFile, std::shared_ptr<Action> action); 72 bool CheckResourceTag(const char* id, const char* name, const char* pair, const char* mode, 73 const char* persistMode, const std::string& configFile) const; 74 bool CheckResourcePersistMode(const char* persistMode, const std::string& configFile) const; 75 bool CheckResourceTag(int32_t persistMode, const char* def, const char* path, const std::string& configFile) const; 76 bool LoadResourceAvailable(std::shared_ptr<ResNode> resNode, const char* node); 77 bool CheckPairResIdValid() const; 78 bool CheckDefValid() const; 79 bool CheckGovResourceTag(const char* id, const char* name, const char* persistMode, 80 const std::string& configFile) const; 81 void ParseModeCmd(const char* mode, const std::string& configFile, std::shared_ptr<Actions> actions); 82 bool LoadGovResourceAvailable(std::shared_ptr<GovResNode> govResNode, const char* level, const char* node); 83 bool CheckCmdTag(const char* id, const char* name, const std::string& configFile) const; 84 bool CheckActionResIdAndValueValid(const std::string& configFile); 85 bool TraversalActions(std::shared_ptr<Action> action, int32_t actionId); 86 bool CheckTrace(const char* trace); 87 bool LoadSceneResource(xmlNode* rootNode, const std::string& configFile); 88 bool TraversalSceneResource(xmlNode* greatGrandson, const std::string& configFile, 89 std::shared_ptr<SceneResNode> sceneResNode); 90 bool CheckSceneResourceTag(const char* name, const char* persistMode, const std::string& configFile) const; 91 void LoadInterAction(xmlNode* child, const std::string& configFile); 92 bool LoadCmdInfo(const xmlNode* rootNode, const std::string& configFile, const std::string& configMode); 93 bool IsConfigTag(const xmlNode* rootNode); 94 bool LoadConfigInfo(const xmlNode* configNode, const std::string& configFile, const std::string& configMode); 95 bool HandleConfigNode(const xmlNode* configNode, const std::string& configFile); 96 bool CheckActionsValid(std::unordered_map<int32_t, std::shared_ptr<Actions>>& actionsInfo); 97 std::string GetConfigMode(const xmlNode* node); 98 }; 99 } // namespace SOCPERF 100 } // namespace OHOS 101 #endif // SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_H 102