148f512ceSopenharmony_ci/* 248f512ceSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 348f512ceSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 448f512ceSopenharmony_ci * you may not use this file except in compliance with the License. 548f512ceSopenharmony_ci * You may obtain a copy of the License at 648f512ceSopenharmony_ci * 748f512ceSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 848f512ceSopenharmony_ci * 948f512ceSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1048f512ceSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1148f512ceSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1248f512ceSopenharmony_ci * See the License for the specific language governing permissions and 1348f512ceSopenharmony_ci * limitations under the License. 1448f512ceSopenharmony_ci */ 1548f512ceSopenharmony_ci#ifndef SUBCOMMAND_DUMP_H 1648f512ceSopenharmony_ci#define SUBCOMMAND_DUMP_H 1748f512ceSopenharmony_ci 1848f512ceSopenharmony_ci#include "perf_file_reader.h" 1948f512ceSopenharmony_ci 2048f512ceSopenharmony_ci#include <memory> 2148f512ceSopenharmony_ci 2248f512ceSopenharmony_ci#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF 2348f512ceSopenharmony_ci#include "report_protobuf_file.h" 2448f512ceSopenharmony_ci#endif 2548f512ceSopenharmony_ci#include "subcommand.h" 2648f512ceSopenharmony_ci#include "symbols_file.h" 2748f512ceSopenharmony_ci#include "virtual_runtime.h" 2848f512ceSopenharmony_ci 2948f512ceSopenharmony_cinamespace OHOS { 3048f512ceSopenharmony_cinamespace Developtools { 3148f512ceSopenharmony_cinamespace HiPerf { 3248f512ceSopenharmony_ci 3348f512ceSopenharmony_ciclass SubCommandDump : public SubCommand { 3448f512ceSopenharmony_cipublic: 3548f512ceSopenharmony_ci SubCommandDump() 3648f512ceSopenharmony_ci // clang-format off 3748f512ceSopenharmony_ci : SubCommand("dump", "Dump content of a perf data file, like perf.data", 3848f512ceSopenharmony_ci 3948f512ceSopenharmony_ci "Usage: hiperf dump [option] <filename>\n" 4048f512ceSopenharmony_ci " Dump specific parts of specified file .\n" 4148f512ceSopenharmony_ci " --head\n" 4248f512ceSopenharmony_ci " Dump header and attrs only.\n" 4348f512ceSopenharmony_ci " -d\n" 4448f512ceSopenharmony_ci " Dump data section only.\n" 4548f512ceSopenharmony_ci " -f\n" 4648f512ceSopenharmony_ci " Dump addtional features only.\n" 4748f512ceSopenharmony_ci " --sympath <symbols path>\n" 4848f512ceSopenharmony_ci " use symbols path to find symbols.\n" 4948f512ceSopenharmony_ci " -i <file name>\n" 5048f512ceSopenharmony_ci " perf data file to dump, default is perf.data\n" 5148f512ceSopenharmony_ci " --elf <elf file name>\n" 5248f512ceSopenharmony_ci " dump elf not perf data.\n" 5348f512ceSopenharmony_ci#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF 5448f512ceSopenharmony_ci " --proto <protobuf file name>\n" 5548f512ceSopenharmony_ci " dump perf data from protobuf file.\n" 5648f512ceSopenharmony_ci#endif 5748f512ceSopenharmony_ci " --export <sample index>\n" 5848f512ceSopenharmony_ci " also export the user stack data to some split file,\n" 5948f512ceSopenharmony_ci " use this command to produce ut data.\n" 6048f512ceSopenharmony_ci " named with sample index(0 base):\n" 6148f512ceSopenharmony_ci " hiperf_<pid>_<tid>_user_regs_<index>.dump\n" 6248f512ceSopenharmony_ci " hiperf_<pid>_<tid>_user_data_<index>.dump\n" 6348f512ceSopenharmony_ci " -o <filename>\n" 6448f512ceSopenharmony_ci " dump file name. if empty will use stdout print\n" 6548f512ceSopenharmony_ci ) 6648f512ceSopenharmony_ci // clang-format on 6748f512ceSopenharmony_ci { 6848f512ceSopenharmony_ci } 6948f512ceSopenharmony_ci ~SubCommandDump() override; 7048f512ceSopenharmony_ci 7148f512ceSopenharmony_ci bool OnSubCommand(std::vector<std::string> &args) override; 7248f512ceSopenharmony_ci bool ParseOption(std::vector<std::string> &args) override; 7348f512ceSopenharmony_ci 7448f512ceSopenharmony_ci static bool RegisterSubCommandDump(void); 7548f512ceSopenharmony_ci 7648f512ceSopenharmony_ci static void DumpPrintEventAttr(const perf_event_attr &attr, int indent = 0); 7748f512ceSopenharmony_ci std::unique_ptr<PerfFileReader> reader_; 7848f512ceSopenharmony_ci 7948f512ceSopenharmony_ciprivate: 8048f512ceSopenharmony_ci static void DumpSampleType(uint64_t sampleType, int indent); 8148f512ceSopenharmony_ci bool PrepareDumpOutput(); 8248f512ceSopenharmony_ci int exportSampleIndex_ = -1; 8348f512ceSopenharmony_ci int currectSampleIndex_ = 0; 8448f512ceSopenharmony_ci std::string dumpFileName_; 8548f512ceSopenharmony_ci std::string elfFileName_; 8648f512ceSopenharmony_ci std::string outputFilename_ = ""; 8748f512ceSopenharmony_ci std::string protobufDumpFileName_; 8848f512ceSopenharmony_ci int indent_ = 0; 8948f512ceSopenharmony_ci#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF 9048f512ceSopenharmony_ci std::unique_ptr<ReportProtobufFileReader> protobufInputFileReader_ = nullptr; 9148f512ceSopenharmony_ci#endif 9248f512ceSopenharmony_ci 9348f512ceSopenharmony_ci std::vector<AttrWithId> attrIds_; 9448f512ceSopenharmony_ci 9548f512ceSopenharmony_ci bool dumpHeader_ = false; 9648f512ceSopenharmony_ci bool dumpFeatures_ = false; 9748f512ceSopenharmony_ci bool dumpData_ = false; 9848f512ceSopenharmony_ci bool dumpAll_ = true; 9948f512ceSopenharmony_ci 10048f512ceSopenharmony_ci std::vector<std::string> dumpSymbolsPaths_; 10148f512ceSopenharmony_ci 10248f512ceSopenharmony_ci bool CheckInputFile(); 10348f512ceSopenharmony_ci bool DumpElfFile(); 10448f512ceSopenharmony_ci#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF 10548f512ceSopenharmony_ci bool DumpProtoFile(); 10648f512ceSopenharmony_ci#endif 10748f512ceSopenharmony_ci void DumpPrintFileHeader(int indent = 0); 10848f512ceSopenharmony_ci void DumpAttrPortion(int indent = 0); 10948f512ceSopenharmony_ci void DumpDataPortion(int indent = 0); 11048f512ceSopenharmony_ci void DumpCallChain(int indent, std::unique_ptr<PerfRecordSample> &sample); 11148f512ceSopenharmony_ci void DumpFeaturePortion(int indent = 0); 11248f512ceSopenharmony_ci void DumpUniqueStackTableNode(int indent, const PerfFileSectionUniStackTable &uniStackTable); 11348f512ceSopenharmony_ci void ExprotUserData(std::unique_ptr<PerfEventRecord> &record); 11448f512ceSopenharmony_ci void ExprotUserStack(const PerfRecordSample &recordSample); 11548f512ceSopenharmony_ci void PrintHeaderInfo(const int &indent); 11648f512ceSopenharmony_ci void PrintSymbolFile(const int &indent, const SymbolFileStruct &symbolFileStruct); 11748f512ceSopenharmony_ci void PrintFeatureEventdesc(int indent, const PerfFileSectionEventDesc §ionEventdesc); 11848f512ceSopenharmony_ci void DumpSpeReport(); 11948f512ceSopenharmony_ci VirtualRuntime vr_; 12048f512ceSopenharmony_ci 12148f512ceSopenharmony_ci void SetHM(); 12248f512ceSopenharmony_ci}; 12348f512ceSopenharmony_ci} // namespace HiPerf 12448f512ceSopenharmony_ci} // namespace Developtools 12548f512ceSopenharmony_ci} // namespace OHOS 12648f512ceSopenharmony_ci#endif // SUBCOMMAND_DUMP_H 127