developtools_hiperf/include/subcommand_dump.h
wenlong12 e356db195a fix codecheck issues
Signed-off-by: wenlong12 <wenlong12@huawei.com>

Signed-off-by: wenlong12 <wwx1097114@DESKTOP-2021EGU.localdomain>
2022-03-25 11:49:41 +08:00

120 lines
3.9 KiB
C++

/*
* 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 <memory>
#if 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] <filename>\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 <symbols path>\n"
" use symbols path to find symbols.\n"
" --elf <elf file name>\n"
" dump elf not perf data.\n"
#if HAVE_PROTOBUF
" --proto <protobuf file name>\n"
" dump perf data from protobuf file.\n"
#endif
" --export <sample index>\n"
" also export the user stack data to some split file,\n"
" use this command to produce ut data."
" named with sample index(0 base):\n"
" hiperf_<pid>_<tid>_user_regs_<index>.dump\n"
" hiperf_<pid>_<tid>_user_data_<index>.dump\n"
" <file name>\n"
" perf data file to dump, default is perf.data\n\n"
)
// clang-format on
{
}
~SubCommandDump() override;
bool OnSubCommand(std::vector<std::string> &args) override;
bool ParseOption(std::vector<std::string> &args) override;
static bool RegisterSubCommandDump(void);
static void DumpPrintEventAttr(const perf_event_attr &attr, int indent = 0);
std::unique_ptr<PerfFileReader> 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 HAVE_PROTOBUF
std::unique_ptr<ReportProtobufFileReader> protobufInputFileReader_ = nullptr;
#endif
std::vector<AttrWithId> attrIds_;
bool dumpHeader_ = false;
bool dumpFeatures_ = false;
bool dumpData_ = false;
bool dumpAll_ = true;
std::vector<std::string> dumpSymbolsPaths_;
bool CheckInputFile();
bool DumpElfFile();
#if 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<PerfRecordSample> &sample);
void DumpFeaturePortion(int indent = 0);
void ExprotUserData(std::unique_ptr<PerfEventRecord> &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 &sectionEventdesc);
VirtualRuntime vr_;
};
} // namespace HiPerf
} // namespace Developtools
} // namespace OHOS
#endif // SUBCOMMAND_DUMP_H