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<int32_t, std::shared_ptr<Actions>> perfActionsInfo_; 45 std::vector<std::shared_ptr<InterAction>> interAction_; 46 47 private: 48 SocPerfConfig(); 49 ~SocPerfConfig(); 50 std::string GetRealConfigPath(const std::string& configFile); 51 std::vector<std::string> GetAllRealConfigPath(const std::string& configFile); 52 bool LoadAllConfigXmlFile(const std::string& configFile); 53 bool LoadConfigXmlFile(const std::string& realConfigFile); 54 void InitPerfFunc(const char* perfSoPath, const char* perfReportFunc, const char* perfScenarioFunc); 55 void InitPerfScenarioFunc(const char* perfSoPath, const char* perfScenarioFunc); 56 bool ParseBoostXmlFile(const xmlNode* rootNode, const std::string& realConfigFile, xmlDoc* file); 57 bool ParseResourceXmlFile(const xmlNode* rootNode, const std::string& realConfigFile, xmlDoc* file); 58 bool LoadResource(xmlNode* rootNode, const std::string& configFile); 59 bool TraversalFreqResource(xmlNode* grandson, const std::string& configFile); 60 bool LoadFreqResourceContent(int32_t persistMode, xmlNode* greatGrandson, const std::string& configFile, 61 std::shared_ptr<ResNode> resNode); 62 int32_t GetXmlIntProp(const xmlNode* xmlNode, const char* propName) const; 63 bool LoadGovResource(xmlNode* rootNode, const std::string& configFile); 64 bool TraversalGovResource(int32_t persistMode, xmlNode* greatGrandson, const std::string& configFile, 65 std::shared_ptr<GovResNode> govResNode); 66 void LoadInfo(xmlNode* child, const std::string& configFile); 67 bool LoadCmd(const xmlNode* rootNode, const std::string& configFile); 68 bool TraversalBoostResource(xmlNode* grandson, const std::string& configFile, std::shared_ptr<Actions> actions); 69 bool ParseDuration(xmlNode* greatGrandson, const std::string& configFile, std::shared_ptr<Action> action) const; 70 bool ParseResValue(xmlNode* greatGrandson, const std::string& configFile, std::shared_ptr<Action> action); 71 bool CheckResourceTag(const char* id, const char* name, const char* pair, const char* mode, 72 const char* persistMode, const std::string& configFile) const; 73 bool CheckResourcePersistMode(const char* persistMode, const std::string& configFile) const; 74 bool CheckResourceTag(int32_t persistMode, const char* def, const char* path, const std::string& configFile) const; 75 bool LoadResourceAvailable(std::shared_ptr<ResNode> resNode, const char* node); 76 bool CheckPairResIdValid() const; 77 bool CheckDefValid() const; 78 bool CheckGovResourceTag(const char* id, const char* name, const char* persistMode, 79 const std::string& configFile) const; 80 void ParseModeCmd(const char* mode, const std::string& configFile, std::shared_ptr<Actions> actions); 81 bool LoadGovResourceAvailable(std::shared_ptr<GovResNode> govResNode, const char* level, const char* node); 82 bool CheckCmdTag(const char* id, const char* name, const std::string& configFile) const; 83 bool CheckActionResIdAndValueValid(const std::string& configFile); 84 bool TraversalActions(std::shared_ptr<Action> action, int32_t actionId); 85 bool CheckTrace(const char* trace); 86 bool LoadSceneResource(xmlNode* rootNode, const std::string& configFile); 87 bool TraversalSceneResource(xmlNode* greatGrandson, const std::string& configFile, 88 std::shared_ptr<SceneResNode> sceneResNode); 89 bool CheckSceneResourceTag(const char* name, const char* persistMode, const std::string& configFile) const; 90 void LoadInterAction(xmlNode* child, const std::string& configFile); 91 bool LoadCmdInfo(const xmlNode* rootNode, const std::string& configFile); 92 }; 93 } // namespace SOCPERF 94 } // namespace OHOS 95 #endif // SOC_PERF_SERVICES_CORE_INCLUDE_SOCPERF_H 96