• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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> &param);
28     ~ConfigUtils();
29 public:
30     // Used for get dumper configs
31     static DumpStatus GetDumperConfigs(const std::shared_ptr<DumperParameter> &param);
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 HandleDumpStorage(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs);
52     bool HandleDumpNet(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs);
53     bool HandleDumpProcesses(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs);
54     bool HandleDumpFaultLog(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs);
55     bool HandleDumpAppendix(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs);
56     bool HandleDumpTest(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs);
57     bool CopySmaps();
58     DumpStatus GetConfig(const std::string &name, std::vector<std::shared_ptr<DumpCfg>> &result,
59         std::shared_ptr<OptionArgs> args);
60     DumpStatus GetDumper(int index, std::vector<std::shared_ptr<DumpCfg>> &result,
61         std::shared_ptr<OptionArgs> args, int level = DumperConstant::NONE);
62     DumpStatus GetDumper(const std::string &name, std::vector<std::shared_ptr<DumpCfg>> &result,
63         std::shared_ptr<OptionArgs> args, int level = DumperConstant::NONE);
64     DumpStatus GetGroup(int index, std::vector<std::shared_ptr<DumpCfg>> &result,
65         std::shared_ptr<OptionArgs> args, int level = DumperConstant::NONE, int nest = 0);
66     DumpStatus GetGroup(const std::string &name, std::vector<std::shared_ptr<DumpCfg>> &result,
67         std::shared_ptr<OptionArgs> args, int level = DumperConstant::NONE, int nest = 0);
68     // Used for get section name from group name
69     static std::string GetSectionName(const std::string &name);
70 private:
71     DumpStatus GetGroupSimple(const GroupCfg& groupCfg, std::vector<std::shared_ptr<DumpCfg>> &result,
72         std::shared_ptr<OptionArgs> args, int level = DumperConstant::NONE, int nest = 0);
73     static DumpStatus GetGroupNames(const std::string &name, std::vector<std::string> &nameList);
74     static void ConvertTreeToList(std::vector<std::shared_ptr<DumpCfg>> &tree,
75         std::vector<std::shared_ptr<DumpCfg>> &list, int nest = 0);
76     static void SetSection(std::vector<std::shared_ptr<DumpCfg>> &dumpCfgs, const std::string &section, int nest = 0);
77 private:
78     const std::shared_ptr<DumperParameter> dumperParam_;
79     std::vector<DumpCommonUtils::PidInfo> pidInfos_;
80     std::vector<DumpCommonUtils::CpuInfo> cpuInfos_;
81     std::vector<DumpCommonUtils::PidInfo> currentPidInfos_;
82     DumpCommonUtils::PidInfo currentPidInfo_;
83     bool isDumpSystemSystem {false};
84 };
85 } // namespace HiviewDFX
86 } // namespace OHOS
87 #endif // HIDUMPER_SERVICES_CONFIG_UTILS_H
88