1 /* 2 * Copyright (C) 2021 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 #ifndef HIDUMPER_SERVICES_CONFIG_UTILS_H 16 #define HIDUMPER_SERVICES_CONFIG_UTILS_H 17 #include <string> 18 #include <vector> 19 #include "dump_common_utils.h" 20 #include "common/dump_cfg.h" 21 #include "common/dumper_parameter.h" 22 #include "util/config_data.h" 23 namespace OHOS { 24 namespace HiviewDFX { 25 class ConfigUtils : public ConfigData { 26 public: 27 explicit ConfigUtils(const std::shared_ptr<DumperParameter> ¶m); 28 ~ConfigUtils(); 29 public: 30 // Used for get dumper configs 31 static DumpStatus GetDumperConfigs(const std::shared_ptr<DumperParameter> ¶m); 32 // Used for get section names 33 static DumpStatus GetSectionNames(const std::string &name, std::vector<std::string> &nameList); 34 // Used for get dump level 35 static int GetDumpLevelByPid(int uid, const DumpCommonUtils::PidInfo &pidInfo); 36 #ifdef DUMP_TEST_MODE // for mock test 37 public: 38 #else // for mock test 39 private: 40 #endif // for mock test 41 DumpStatus GetDumperConfigs(); 42 bool MergePidInfos(std::vector<DumpCommonUtils::PidInfo> &outInfos, int pid); 43 bool HandleDumpLog(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 44 bool HandleDumpList(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 45 bool HandleDumpService(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 46 bool HandleDumpAbility(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 47 bool HandleDumpSystem(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 48 bool HandleDumpCpuFreq(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 49 bool HandleDumpCpuUsage(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 50 bool HandleDumpMem(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 51 bool HandleDumpJsHeapMem(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 52 bool HandleDumpCjHeapMem(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 53 bool HandleDumpMemShowMaps(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 54 void HandleDumpMemCommon(std::shared_ptr<DumperParameter> dumpParam, 55 std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 56 bool HandleDumpStorage(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 57 bool HandleDumpNet(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 58 bool HandleDumpProcesses(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 59 bool HandleDumpFaultLog(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 60 bool HandleDumpAppendix(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 61 bool HandleDumpIpcStat(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs); 62 bool CopySmaps(); 63 DumpStatus GetConfig(const std::string &name, std::vector<std::shared_ptr<DumpCfg>> &result, 64 std::shared_ptr<OptionArgs> args); 65 DumpStatus GetDumper(int index, std::vector<std::shared_ptr<DumpCfg>> &result, 66 std::shared_ptr<OptionArgs> args, int level = DumperConstant::NONE); 67 DumpStatus GetDumper(const std::string &name, std::vector<std::shared_ptr<DumpCfg>> &result, 68 std::shared_ptr<OptionArgs> args, int level = DumperConstant::NONE); 69 DumpStatus GetGroup(int index, std::vector<std::shared_ptr<DumpCfg>> &result, 70 std::shared_ptr<OptionArgs> args, int level = DumperConstant::NONE, int nest = 0); 71 DumpStatus GetGroup(const std::string &name, std::vector<std::shared_ptr<DumpCfg>> &result, 72 std::shared_ptr<OptionArgs> args, int level = DumperConstant::NONE, int nest = 0); 73 // Used for get section name from group name 74 static std::string GetSectionName(const std::string &name); 75 private: 76 DumpStatus GetGroupSimple(const GroupCfg& groupCfg, std::vector<std::shared_ptr<DumpCfg>> &result, 77 std::shared_ptr<OptionArgs> args, int level = DumperConstant::NONE, int nest = 0); 78 static DumpStatus GetGroupNames(const std::string &name, std::vector<std::string> &nameList); 79 static void ConvertTreeToList(std::vector<std::shared_ptr<DumpCfg>> &tree, 80 std::vector<std::shared_ptr<DumpCfg>> &list, int nest = 0); 81 static void SetSection(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs, const std::string §ion, int nest = 0); 82 bool MergeDebugPidInfos(std::vector<DumpCommonUtils::PidInfo> &pidInfos, int pid); 83 private: 84 const std::shared_ptr<DumperParameter> dumperParam_; 85 std::vector<DumpCommonUtils::PidInfo> pidInfos_; 86 std::vector<DumpCommonUtils::CpuInfo> cpuInfos_; 87 std::vector<DumpCommonUtils::PidInfo> currentPidInfos_; 88 DumpCommonUtils::PidInfo currentPidInfo_; 89 bool isDumpSystemSystem {false}; 90 }; 91 } // namespace HiviewDFX 92 } // namespace OHOS 93 #endif // HIDUMPER_SERVICES_CONFIG_UTILS_H 94