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 class SocPerfConfig { 29 public: 30 bool Init(); 31 bool IsGovResId(int32_t resId) const; 32 bool IsValidResId(int32_t resId) const; 33 static SocPerfConfig& GetInstance(); 34 35 public: 36 ReportDataFunc reportFunc_ = nullptr; 37 std::mutex resourceNodeMutex_; 38 std::unordered_map<int32_t, std::shared_ptr<ResourceNode>> resourceNodeInfo_; 39 std::mutex perfActionsMutex_; 40 std::unordered_map<int32_t, std::shared_ptr<Actions>> perfActionsInfo_; 41 42 private: 43 SocPerfConfig(); 44 ~SocPerfConfig(); 45 std::string GetRealConfigPath(const std::string& configFile); 46 bool LoadConfigXmlFile(const std::string& configFile); 47 void InitPerfFunc(const char* perfSoPath, const char* perfSoFunc); 48 bool ParseBoostXmlFile(const xmlNode* rootNode, const std::string& realConfigFile, xmlDoc* file); 49 bool ParseResourceXmlFile(const xmlNode* rootNode, const std::string& realConfigFile, xmlDoc* file); 50 bool LoadResource(xmlNode* rootNode, const std::string& configFile); 51 bool TraversalFreqResource(xmlNode* grandson, const std::string& configFile); 52 bool LoadFreqResourceContent(int32_t persistMode, xmlNode* greatGrandson, const std::string& configFile, 53 std::shared_ptr<ResNode> resNode); 54 int32_t GetXmlIntProp(const xmlNode* xmlNode, const char* propName) const; 55 bool LoadGovResource(xmlNode* rootNode, const std::string& configFile); 56 bool TraversalGovResource(int32_t persistMode, xmlNode* greatGrandson, const std::string& configFile, 57 std::shared_ptr<GovResNode> govResNode); 58 void LoadInfo(xmlNode* child, const std::string& configFile); 59 bool LoadCmd(const xmlNode* rootNode, const std::string& configFile); 60 bool TraversalBoostResource(xmlNode* grandson, const std::string& configFile, std::shared_ptr<Actions> actions); 61 bool ParseDuration(xmlNode* greatGrandson, const std::string& configFile, std::shared_ptr<Action> action) const; 62 bool ParseResValue(xmlNode* greatGrandson, const std::string& configFile, std::shared_ptr<Action> action); 63 bool CheckResourceTag(const char* id, const char* name, const char* pair, const char* mode, 64 const char* persistMode, const std::string& configFile) const; 65 bool CheckResourcePersistMode(const char* persistMode, const std::string& configFile) const; 66 bool CheckResourceTag(int32_t persistMode, const char* def, const char* path, const std::string& configFile) const; 67 bool LoadResourceAvailable(std::shared_ptr<ResNode> resNode, const char* node); 68 bool CheckPairResIdValid() const; 69 bool CheckDefValid() const; 70 bool CheckGovResourceTag(const char* id, const char* name, const char* persistMode, 71 const std::string& configFile) const; 72 void ParseModeCmd(const char* mode, const std::string& configFile, std::shared_ptr<Actions> actions); 73 bool LoadGovResourceAvailable(std::shared_ptr<GovResNode> govResNode, const char* level, const char* node); 74 bool CheckCmdTag(const char* id, const char* name, const std::string& configFile) const; 75 bool CheckActionResIdAndValueValid(const std::string& configFile); 76 bool TraversalActions(std::shared_ptr<Action> action, int32_t actionId); 77 }; 78 } // namespace SOCPERF 79 } // namespace OHOS 80 #endif // SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_H 81