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_DUMP_CFG_H 16 #define HIDUMPER_SERVICES_DUMP_CFG_H 17 #include <string> 18 #include "common/option_args.h" 19 namespace OHOS { 20 namespace HiviewDFX { 21 class HidumperExecutor; 22 struct DumpCfg { 23 std::string name_; 24 std::string desc_; 25 std::string target_; 26 std::string section_; 27 int class_ {DumperConstant::NONE}; 28 int level_ {DumperConstant::NONE}; 29 int loop_ {DumperConstant::NONE}; 30 std::string filterCfg_; 31 std::shared_ptr<OptionArgs> args_; 32 int type_ {DumperConstant::NONE}; // DumperConstant::NONE, GROUPTYPE_PID, GROUPTYPE_CPUID 33 bool expand_ {false}; // true: expand; false: non-expand 34 std::shared_ptr<DumpCfg> parent_; 35 std::vector<std::shared_ptr<DumpCfg>> childs_; // GROUP, must clear 36 std::shared_ptr<HidumperExecutor> executor_; // GROUP, must clear 37 public: 38 DumpCfg(); 39 ~DumpCfg(); 40 DumpCfg& operator=(const DumpCfg& dumpCfg); 41 bool IsGroup() const; 42 bool IsDumper() const; 43 bool IsFilter() const; 44 bool IsLevel() const; 45 bool CanLoop() const; 46 bool IsOutput() const; 47 bool HasPid() const; 48 bool HasCpuId() const; 49 void Dump(int deep = 0) const; 50 static std::shared_ptr<DumpCfg> Create(); 51 static bool IsDumper(int cls); 52 static bool IsFilter(int cls); 53 static bool IsLevel(int level); 54 static bool CanLoop(int loop); 55 static bool IsOutput(int cls); 56 static bool HasPid(const std::string &target); 57 static bool HasCpuId(const std::string &target); 58 static std::string ToStr(int type); 59 static void Dump(const DumpCfg& cfg, int nest = 0); 60 private: 61 static std::string ToDumperStr(int type); 62 static std::string ToFilterStr(int type); 63 static std::string ToOutputStr(int type); 64 static std::string ToLevelStr(int type); 65 static std::string ToTypeStr(int type); 66 }; 67 } // namespace HiviewDFX 68 } // namespace OHOS 69 #endif // HIDUMPER_SERVICES_DUMP_CFG_H 70