/* * Copyright (c) 2022 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 SUBCOMMAND_DUMP_H #define SUBCOMMAND_DUMP_H #include "perf_file_reader.h" #include #if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF #include "report_protobuf_file.h" #endif #include "subcommand.h" #include "symbols_file.h" #include "virtual_runtime.h" namespace OHOS { namespace Developtools { namespace HiPerf { static const std::string DEFAULT_DUMP_FILENAME = "perf.data"; class SubCommandDump : public SubCommand { public: SubCommandDump() // clang-format off : SubCommand("dump", "Dump content of a perf data file, like perf.data", "Usage: hiperf dump [option] \n" " Dump specific parts of specified file .\n" " --head\n" " Dump header and attrs only.\n" " -d\n" " Dump data section only.\n" " -f\n" " Dump addtional features only.\n" " --sympath \n" " use symbols path to find symbols.\n" " --elf \n" " dump elf not perf data.\n" #if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF " --proto \n" " dump perf data from protobuf file.\n" #endif " --export \n" " also export the user stack data to some split file,\n" " use this command to produce ut data.\n" " named with sample index(0 base):\n" " hiperf___user_regs_.dump\n" " hiperf___user_data_.dump\n" " \n" " perf data file to dump, default is perf.data\n\n" ) // clang-format on { } ~SubCommandDump() override; bool OnSubCommand(std::vector &args) override; bool ParseOption(std::vector &args) override; static bool RegisterSubCommandDump(void); static void DumpPrintEventAttr(const perf_event_attr &attr, int indent = 0); std::unique_ptr reader_; private: static void DumpSampleType(uint64_t sampleType, int indent); int exportSampleIndex_ = -1; int currectSampleIndex_ = 0; std::string dumpFileName_; std::string elfFileName_; std::string protobufDumpFileName_; int indent_ = 0; #if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF std::unique_ptr protobufInputFileReader_ = nullptr; #endif std::vector attrIds_; bool dumpHeader_ = false; bool dumpFeatures_ = false; bool dumpData_ = false; bool dumpAll_ = true; std::vector dumpSymbolsPaths_; bool CheckInputFile(); bool DumpElfFile(); #if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF bool DumpProtoFile(); #endif void DumpPrintFileHeader(int indent = 0); void DumpAttrPortion(int indent = 0); void DumpDataPortion(int indent = 0); void DumpCallChain(int indent, std::unique_ptr &sample); void DumpFeaturePortion(int indent = 0); void ExprotUserData(std::unique_ptr &record); void ExprotUserStack(const PerfRecordSample &recordSample); void PrintHeaderInfo(const int &indent); void PrintSymbolFile(const int &indent, const SymbolFileStruct &symbolFileStruct); void PrintFeatureEventdesc(int indent, const PerfFileSectionEventDesc §ionEventdesc); VirtualRuntime vr_; }; } // namespace HiPerf } // namespace Developtools } // namespace OHOS #endif // SUBCOMMAND_DUMP_H