diff --git a/include/hiperf_libreport.h b/include/hiperf_libreport.h index 7c1cca8..0e37895 100644 --- a/include/hiperf_libreport.h +++ b/include/hiperf_libreport.h @@ -15,7 +15,7 @@ #ifndef HIPERF_LIBREPORT_H #define HIPERF_LIBREPORT_H -#if is_mingw +#if defined(is_mingw) && is_mingw #define DLL_EXPORT __declspec(dllexport) #else #define DLL_EXPORT __attribute__((visibility("default"))) diff --git a/include/nonlinux/MingW64Fix.h b/include/nonlinux/MingW64Fix.h index bb2db77..e10d2a6 100644 --- a/include/nonlinux/MingW64Fix.h +++ b/include/nonlinux/MingW64Fix.h @@ -14,7 +14,7 @@ */ #ifndef NONLINUX_MINGW64FIX_H #define NONLINUX_MINGW64FIX_H -#if is_mingw +#if defined(is_mingw) && is_mingw // in mingw 64 _pid_t define to int64 // but in linux it always int diff --git a/include/subcommand_report.h b/include/subcommand_report.h index 7adc5cf..c3e167e 100644 --- a/include/subcommand_report.h +++ b/include/subcommand_report.h @@ -27,7 +27,7 @@ #include #include "perf_file_reader.h" -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF #include "report_protobuf_file.h" #endif #include "debug_logger.h" @@ -173,7 +173,7 @@ private: std::unique_ptr reportJsonFile_ = nullptr; bool protobufFormat_ = false; -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF std::unique_ptr protobufOutputFileWriter_ = nullptr; void UpdateReportInfo(); #endif diff --git a/include/unique_stack_table.h b/include/unique_stack_table.h index 464ffcf..4035b3e 100644 --- a/include/unique_stack_table.h +++ b/include/unique_stack_table.h @@ -125,14 +125,14 @@ private: uint32_t tableSize_ = INITIAL_TABLE_SIZE; std::unique_ptr tableBuf_ = nullptr; std::vector usedSlots_; - uint32_t totalNodes_; + uint32_t totalNodes_ = 0; // current available node count, include index 0 - uint32_t availableNodes_; - uint32_t hashModulus_; + uint32_t availableNodes_ = 0; + uint32_t hashModulus_ = 0; // 0 for reserved, start from 1 uint32_t availableIndex_ = 1; // for de-conflict - uint64_t hashStep_; + uint64_t hashStep_ = 0; uint8_t deconflictTimes_ = INIT_DECONFLICT_ALLOWED; }; diff --git a/include/utilities.h b/include/utilities.h index 3df6ed4..d1bb278 100644 --- a/include/utilities.h +++ b/include/utilities.h @@ -223,7 +223,7 @@ bool IsPath(const std::string &fileName); bool LittleMemory(); -#if is_mingw +#if defined(is_mingw) && is_mingw const char PATH_SEPARATOR = '\\'; #else const char PATH_SEPARATOR = '/'; @@ -348,7 +348,7 @@ bool NeedAdaptSandboxPath(char *filename, int pid, u16 &headerSize); } // namespace OHOS // this will also used for libunwind head (out of namespace) -#if is_mingw +#if defined(is_mingw) && is_mingw #if !is_double_framework #define HAVE_MMAP 1 #define MAP_PRIVATE 0x02 diff --git a/script/report.html b/script/report.html index adedead..9d6cefc 100644 --- a/script/report.html +++ b/script/report.html @@ -27,22 +27,22 @@
diff --git a/src/perf_file_format.cpp b/src/perf_file_format.cpp index 383dfd6..3dc2320 100644 --- a/src/perf_file_format.cpp +++ b/src/perf_file_format.cpp @@ -329,7 +329,7 @@ PerfFileSectionUniStackTable::PerfFileSectionUniStackTable(FEATURE id, const cha HLOGV("tableSize %" PRIu32 " ", stackTable.tableSize); Read(stackTable.numNodes); HLOGV("numNodes %" PRIu32 " ", stackTable.numNodes); - for (size_t i = 0; i < stackTable.numNodes; i++) { + for (size_t j = 0; j < stackTable.numNodes; j++) { UniStackNode& node = stackTable.nodes.emplace_back(); Read(node.index); Read(node.node.value); diff --git a/src/register.cpp b/src/register.cpp index c76b841..4ac4710 100644 --- a/src/register.cpp +++ b/src/register.cpp @@ -235,7 +235,7 @@ ArchType SetDeviceArch(ArchType arch) ArchType GetDeviceArch() { -#if is_mingw +#if defined(is_mingw) && is_mingw return deviceArchType; #else if (deviceArchType != ArchType::ARCH_UNKNOWN) { diff --git a/src/report.cpp b/src/report.cpp index 7057662..3bb37e7 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -20,7 +20,7 @@ #include #include -#if is_mingw +#if defined(is_mingw) && is_mingw #include #else #include @@ -428,7 +428,7 @@ bool Report::OutputStdCallFrame(int indent, const std::string_view &funcName, ui void Report::PrepareConsole() { -#if is_mingw +#if defined(is_mingw) && is_mingw CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); consoleWidth_ = static_cast(csbi.srWindow.Right - csbi.srWindow.Left + 1); diff --git a/src/report_json_file.cpp b/src/report_json_file.cpp index 47c3154..fc8ba11 100644 --- a/src/report_json_file.cpp +++ b/src/report_json_file.cpp @@ -17,7 +17,7 @@ #include #include "report_json_file.h" -#if is_mingw +#if defined(is_mingw) && is_mingw #include #else #include diff --git a/src/subcommand_dump.cpp b/src/subcommand_dump.cpp index f9324db..e1e2e6a 100644 --- a/src/subcommand_dump.cpp +++ b/src/subcommand_dump.cpp @@ -85,7 +85,7 @@ bool SubCommandDump::ParseOption(std::vector &args) if (!Option::GetOptionValue(args, "-i", dumpFileName_)) { return false; } -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF if (!Option::GetOptionValue(args, "--proto", protobufDumpFileName_)) { HLOGD("get option --proto failed"); return false; @@ -143,7 +143,7 @@ bool SubCommandDump::OnSubCommand(std::vector &args) return DumpElfFile(); } -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF if (!protobufDumpFileName_.empty()) { return DumpProtoFile(); } @@ -204,7 +204,7 @@ bool SubCommandDump::DumpElfFile() } return true; } -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF bool SubCommandDump::DumpProtoFile() { printf("dump protobuf file: '%s'\n", protobufDumpFileName_.c_str()); diff --git a/src/subcommand_report.cpp b/src/subcommand_report.cpp index ec4b2d0..63c4289 100644 --- a/src/subcommand_report.cpp +++ b/src/subcommand_report.cpp @@ -20,7 +20,7 @@ #include #include -#if is_mingw +#if defined(is_mingw) && is_mingw #include #else #include @@ -206,7 +206,7 @@ void SubCommandReport::ProcessSample(std::unique_ptr &sample) sample->data_.tid, sample->data_.period, sample->callFrames_); } else if (protobufFormat_) { -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF // make some cook // redesgin here protobufOutputFileWriter_->ProcessSampleRecord( @@ -261,7 +261,7 @@ bool SubCommandReport::RecordCallBack(std::unique_ptr record) ProcessSample(sample); } } else { -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF if (protobufFormat_) { protobufOutputFileWriter_->ProcessRecord(*record); } @@ -291,7 +291,7 @@ void SubCommandReport::ProcessSymbolsData() static_cast(featureSection); GetReport().virtualRuntime_.UpdateFromPerfData(sectionSymbolsFiles->symbolFileStructs_); } -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF // we have load the elf // write it to proto first if (protobufFormat_) { @@ -428,7 +428,7 @@ void SubCommandReport::ProcessFeaturesData() // update device arch from feature SetDeviceArch(GetArchTypeFromUname(recordFileReader_->GetFeatureString(FEATURE::ARCH))); -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF UpdateReportInfo(); #endif } @@ -542,7 +542,7 @@ bool SubCommandReport::OutputReport() bool SubCommandReport::PrepareOutput() { if (protobufFormat_) { -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF printf("save to protobuf file: '%s'\n", reportFile_.c_str()); protobufOutputFileWriter_ = std::make_unique(); protobufOutputFileWriter_->Create(reportFile_); @@ -568,7 +568,7 @@ bool SubCommandReport::PrepareOutput() SubCommandReport::~SubCommandReport() { -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF if (protobufOutputFileWriter_ != nullptr) { protobufOutputFileWriter_->Close(); } diff --git a/src/symbols_file.cpp b/src/symbols_file.cpp index 744a291..3a3ed3f 100644 --- a/src/symbols_file.cpp +++ b/src/symbols_file.cpp @@ -23,7 +23,7 @@ #include #include -#if is_mingw +#if defined(is_mingw) && is_mingw #include #else #include @@ -196,11 +196,9 @@ public: const std::unordered_map GetPtLoads() override { - std::unordered_map info; if (elfFile_ == nullptr) { - return info; + return info_; } - return elfFile_->GetPtLoads(); } @@ -280,6 +278,7 @@ private: uint64_t ehFrameHDRFdeTableItemSize_ {0}; uint64_t ehFrameHDRFdeTableElfOffset_ {0}; std::shared_ptr elfFile_; + std::unordered_map info_; bool GetSectionInfo(const std::string &name, uint64_t §ionVaddr, uint64_t §ionSize, uint64_t §ionFileOffset) const override diff --git a/src/unique_stack_table.cpp b/src/unique_stack_table.cpp index 70a950a..32c3925 100644 --- a/src/unique_stack_table.cpp +++ b/src/unique_stack_table.cpp @@ -89,7 +89,7 @@ uint64_t UniqueStackTable::PutIpInSlot(uint64_t thisIp, uint64_t prevIdx) node.section.prevIdx = prevIdx; node.section.inKernel = !!(thisIp & IP_IN_KERNEL); while (currentDeconflictTimes_--) { - Node* tableNode = (Node*)tableHead_ + curIpIdx; + Node* tableNode = reinterpret_cast(tableHead_) + curIpIdx; // empty case if (tableNode->value == 0) { @@ -177,13 +177,14 @@ bool UniqueStackTable::GetIpsByStackId(StackId stackId, std::vector& ips) uint64_t tailIdx = stackId.section.id; Node *node = GetFrame(tailIdx); - while (node != nullptr && nr--) { + while (node != nullptr && nr > 0) { ips.push_back( node->section.inKernel ? (node->section.ip | KERNEL_PREFIX) : node->section.ip); if (node->section.prevIdx == HEAD_NODE_INDEX) { break; } node = GetFrame(node->section.prevIdx); + nr--; } return true; } diff --git a/src/virtual_thread.cpp b/src/virtual_thread.cpp index 7d53d83..ba40c9a 100644 --- a/src/virtual_thread.cpp +++ b/src/virtual_thread.cpp @@ -225,7 +225,7 @@ bool VirtualThread::ReadRoMemory(uint64_t vaddr, uint8_t *data, size_t size) con return false; } -#if is_mingw +#if defined(is_mingw) && is_mingw void VirtualThread::ParseMap() { // only linux support read maps in runtime diff --git a/test/unittest/common/native/subcommand_dump_test.cpp b/test/unittest/common/native/subcommand_dump_test.cpp index 06de75b..bd83de5 100644 --- a/test/unittest/common/native/subcommand_dump_test.cpp +++ b/test/unittest/common/native/subcommand_dump_test.cpp @@ -182,7 +182,7 @@ HWTEST_F(SubCommandDumpTest, DumpInputElfConflict, TestSize.Level1) TestDumpCommand("perf.data --elf elffile ", false); } -#if HAVE_PROTOBUF +#if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF HWTEST_F(SubCommandDumpTest, DumpProtofile, TestSize.Level1) { TestDumpCommand("--proto /data/test/resource/testdata/proto_test "); diff --git a/test/unittest/common/native/subcommand_report_test.cpp b/test/unittest/common/native/subcommand_report_test.cpp index 8f6cced..de37dfd 100644 --- a/test/unittest/common/native/subcommand_report_test.cpp +++ b/test/unittest/common/native/subcommand_report_test.cpp @@ -25,9 +25,11 @@ using namespace OHOS::HiviewDFX; namespace OHOS { namespace Developtools { namespace HiPerf { + +constexpr int DEFAULT_RUN_TIMEOUT_MS = 10000; + class SubCommandReportTest : public testing::Test { public: - const int DEFAULT_RUN_TIMEOUT_MS = 10000; #if is_ohos const std::string RESOURCE_PATH = "/data/test/resource/testdata/"; #else