/* * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HIDUMPER_SERVICES_CONFIG_UTILS_H #define HIDUMPER_SERVICES_CONFIG_UTILS_H #include #include #include "dump_common_utils.h" #include "common/dump_cfg.h" #include "common/dumper_parameter.h" #include "util/config_data.h" namespace OHOS { namespace HiviewDFX { class ConfigUtils : public ConfigData { public: explicit ConfigUtils(const std::shared_ptr ¶m); ~ConfigUtils(); public: // Used for get dumper configs static DumpStatus GetDumperConfigs(const std::shared_ptr ¶m); // Used for get section names static DumpStatus GetSectionNames(const std::string &name, std::vector &nameList); // Used for get dump level static int GetDumpLevelByPid(int uid, const DumpCommonUtils::PidInfo &pidInfo); #ifdef DUMP_TEST_MODE // for mock test public: #else // for mock test private: #endif // for mock test DumpStatus GetDumperConfigs(); bool MergePidInfos(std::vector &outInfos, int pid); bool HandleDumpLog(std::vector> &dumpCfgs); bool HandleDumpList(std::vector> &dumpCfgs); bool HandleDumpService(std::vector> &dumpCfgs); bool HandleDumpAbility(std::vector> &dumpCfgs); bool HandleDumpSystem(std::vector> &dumpCfgs); bool HandleDumpCpuFreq(std::vector> &dumpCfgs); bool HandleDumpCpuUsage(std::vector> &dumpCfgs); bool HandleDumpMem(std::vector> &dumpCfgs); bool HandleDumpJsHeapMem(std::vector> &dumpCfgs); bool HandleDumpMemShowMaps(std::vector> &dumpCfgs); void HandleDumpMemCommon(std::shared_ptr dumpParam, std::vector> &dumpCfgs); bool HandleDumpStorage(std::vector> &dumpCfgs); bool HandleDumpNet(std::vector> &dumpCfgs); bool HandleDumpProcesses(std::vector> &dumpCfgs); bool HandleDumpFaultLog(std::vector> &dumpCfgs); bool HandleDumpAppendix(std::vector> &dumpCfgs); bool HandleDumpIpcStat(std::vector> &dumpCfgs); bool CopySmaps(); DumpStatus GetConfig(const std::string &name, std::vector> &result, std::shared_ptr args); DumpStatus GetDumper(int index, std::vector> &result, std::shared_ptr args, int level = DumperConstant::NONE); DumpStatus GetDumper(const std::string &name, std::vector> &result, std::shared_ptr args, int level = DumperConstant::NONE); DumpStatus GetGroup(int index, std::vector> &result, std::shared_ptr args, int level = DumperConstant::NONE, int nest = 0); DumpStatus GetGroup(const std::string &name, std::vector> &result, std::shared_ptr args, int level = DumperConstant::NONE, int nest = 0); // Used for get section name from group name static std::string GetSectionName(const std::string &name); private: DumpStatus GetGroupSimple(const GroupCfg& groupCfg, std::vector> &result, std::shared_ptr args, int level = DumperConstant::NONE, int nest = 0); static DumpStatus GetGroupNames(const std::string &name, std::vector &nameList); static void ConvertTreeToList(std::vector> &tree, std::vector> &list, int nest = 0); static void SetSection(std::vector> &dumpCfgs, const std::string §ion, int nest = 0); bool MergeDebugPidInfos(std::vector &pidInfos, int pid); private: const std::shared_ptr dumperParam_; std::vector pidInfos_; std::vector cpuInfos_; std::vector currentPidInfos_; DumpCommonUtils::PidInfo currentPidInfo_; bool isDumpSystemSystem {false}; }; } // namespace HiviewDFX } // namespace OHOS #endif // HIDUMPER_SERVICES_CONFIG_UTILS_H