From 76f055737b91a1a29d64eb913b6213c788d76c4e Mon Sep 17 00:00:00 2001 From: wenlong12 Date: Thu, 8 Aug 2024 10:26:21 +0800 Subject: [PATCH] =?UTF-8?q?spe=E5=AE=8F=E9=9A=94=E7=A6=BB=20Signed-off-by:?= =?UTF-8?q?wenlong12=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenlong12 --- OAT.xml | 1 - include/report.h | 1 - include/virtual_thread.h | 1 - src/report.cpp | 19 ----- src/spe_decoder.cpp | 107 ++++++++++++++++++++++++++- src/virtual_thread.cpp | 12 --- test/BUILD.gn | 2 +- test/unittest/resource/ohos_test.xml | 1 - 8 files changed, 107 insertions(+), 37 deletions(-) diff --git a/OAT.xml b/OAT.xml index f4a1bc4..72a2a97 100644 --- a/OAT.xml +++ b/OAT.xml @@ -119,7 +119,6 @@ Note:If the text contains special characters, please escape them according to th - diff --git a/include/report.h b/include/report.h index 8ddbdd9..762572a 100644 --- a/include/report.h +++ b/include/report.h @@ -542,7 +542,6 @@ private: void PrepareConsole(); void OutputStdStatistics(ReportEventConfigItem &config); - bool OutputStdStatistics(ReportEventConfigItem &config, ReportEventConfigItem &otherConfig); void OutputStdHead(ReportEventConfigItem &config, bool diffMode = false); diff --git a/include/virtual_thread.h b/include/virtual_thread.h index 8ed4d88..d4221cd 100644 --- a/include/virtual_thread.h +++ b/include/virtual_thread.h @@ -84,7 +84,6 @@ public: uint64_t len, uint64_t offset, uint32_t prot = 0); std::shared_ptr FindMapByAddr(uint64_t addr) const; std::shared_ptr FindMapByFileInfo(const std::string name, uint64_t offset) const; - std::shared_ptr FindFirstMapByFileInfo(const std::string name) const; int64_t FindMapIndexByAddr(uint64_t addr) const; SymbolsFile *FindSymbolsFileByMap(std::shared_ptr map) const; bool ReadRoMemory(uint64_t vaddr, uint8_t *data, size_t size) const; diff --git a/src/report.cpp b/src/report.cpp index 7dca29d..32f4e4d 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -350,25 +350,6 @@ void Report::OutputStdStatistics(ReportEventConfigItem &config) fprintf(output_, "%" PRIu64 "\n", config.eventCount_); } -bool Report::OutputStdStatistics(ReportEventConfigItem &config, ReportEventConfigItem &otherConfig) -{ - if (config != otherConfig) { - fprintf(output_, "diff config unable compare\n"); - return false; - } - fprintf(output_, "Event: %s (type %" PRIu32 " id %" PRIu64 ")", config.eventName_.c_str(), - config.type_, config.config_); - fprintf(output_, "Samples Count: %" PRIu64 " vs %" PRIu64 "\n", config.sampleCount_, - otherConfig.sampleCount_); - if (config.coutMode_) { - fprintf(output_, "Time in ns: "); - } else { - fprintf(output_, "Event Count: "); - } - fprintf(output_, "%" PRIu64 " vs %" PRIu64 "\n", config.eventCount_, otherConfig.eventCount_); - return true; -} - void Report::OutputStdHead(ReportEventConfigItem &config, bool diffMode) { // head print diff --git a/src/spe_decoder.cpp b/src/spe_decoder.cpp index e8fdd4b..92f03ee 100644 --- a/src/spe_decoder.cpp +++ b/src/spe_decoder.cpp @@ -32,6 +32,7 @@ constexpr const int UN_PRMT = -1; const char *SpePktName(enum SpePktType type) { +#ifndef UNITTEST const char* spePacketName; switch (type) { case PERF_SPE_PAD: spePacketName = "PAD"; break; @@ -46,6 +47,9 @@ const char *SpePktName(enum SpePktType type) default: spePacketName = "INVALID"; break; } return spePacketName; +#else + return "INVALID"; +#endif } static unsigned int SpePayloadLen(unsigned char hdr) @@ -56,6 +60,7 @@ static unsigned int SpePayloadLen(unsigned char hdr) static int SpeGetPayload(const unsigned char *buf, size_t len, unsigned char extHdr, struct SpePkt *packet) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -76,22 +81,28 @@ static int SpeGetPayload(const unsigned char *buf, size_t len, } return 1 + extHdr + payloadLen; +#else + return 0; +#endif } static int SpeGetPad(struct SpePkt *packet) { +#ifndef UNITTEST if (packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); return -1; } packet->type = PERF_SPE_PAD; +#endif return 1; } static int SpeGetAlignment(const unsigned char *buf, size_t len, struct SpePkt *packet) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -104,22 +115,28 @@ static int SpeGetAlignment(const unsigned char *buf, size_t len, packet->type = PERF_SPE_PAD; return alignment - (((uintptr_t)buf) & (alignment - 1)); +#else + return 0; +#endif } static int SpeGetEnd(struct SpePkt *packet) { +#ifndef UNITTEST if (packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); return -1; } packet->type = PERF_SPE_END; +#endif return 1; } static int SpeGetTimestamp(const unsigned char *buf, size_t len, struct SpePkt *packet) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -127,11 +144,15 @@ static int SpeGetTimestamp(const unsigned char *buf, size_t len, } packet->type = PERF_SPE_TIMESTAMP; return SpeGetPayload(buf, len, 0, packet); +#else + return 0; +#endif } static int SpeGetEvents(const unsigned char *buf, size_t len, struct SpePkt *packet) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -140,11 +161,15 @@ static int SpeGetEvents(const unsigned char *buf, size_t len, packet->type = PERF_SPE_EVENTS; packet->index = SpePayloadLen(buf[0]); return SpeGetPayload(buf, len, 0, packet); +#else + return 0; +#endif } static int SpeGetDataSource(const unsigned char *buf, size_t len, struct SpePkt *packet) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -152,11 +177,15 @@ static int SpeGetDataSource(const unsigned char *buf, size_t len, } packet->type = PERF_SPE_DATA_SOURCE; return SpeGetPayload(buf, len, 0, packet); +#else + return 0; +#endif } static int SpeGetContext(const unsigned char *buf, size_t len, struct SpePkt *packet) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -165,11 +194,15 @@ static int SpeGetContext(const unsigned char *buf, size_t len, packet->type = PERF_SPE_CONTEXT; packet->index = PERF_SPE_CTX_PKT_HDR_INDEX(buf[0]); return SpeGetPayload(buf, len, 0, packet); +#else + return 0; +#endif } static int SpeGetOpType(const unsigned char *buf, size_t len, struct SpePkt *packet) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -178,11 +211,15 @@ static int SpeGetOpType(const unsigned char *buf, size_t len, packet->type = PERF_SPE_OP_TYPE; packet->index = PERF_SPE_OP_PKT_HDR_CLASS(buf[0]); return SpeGetPayload(buf, len, 0, packet); +#else + return 0; +#endif } static int SpeGetCounter(const unsigned char *buf, size_t len, const unsigned char extHdr, struct SpePkt *packet) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -196,11 +233,15 @@ static int SpeGetCounter(const unsigned char *buf, size_t len, } return SpeGetPayload(buf, len, extHdr, packet); +#else + return 0; +#endif } static int SpeGetAddr(const unsigned char *buf, size_t len, const unsigned char extHdr, struct SpePkt *packet) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -214,11 +255,15 @@ static int SpeGetAddr(const unsigned char *buf, size_t len, } return SpeGetPayload(buf, len, extHdr, packet); +#else + return 0; +#endif } static int SpeDoGetPacket(const unsigned char *buf, size_t len, struct SpePkt *packet) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -276,13 +321,14 @@ static int SpeDoGetPacket(const unsigned char *buf, size_t len, if ((hdr & PERF_SPE_HEADER0_MASK3) == PERF_SPE_HEADER0_COUNTER) { return SpeGetCounter(buf, len, extHdr, packet); } - +#endif return PERF_SPE_BAD_PACKET; } int SpeGetPacket(const unsigned char *buf, size_t len, struct SpePkt *packet) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -298,11 +344,15 @@ int SpeGetPacket(const unsigned char *buf, size_t len, } } return ret; +#else + return 0; +#endif } static int SpePktOutString(int *err, char **bufPtr, size_t *bufLen, const char *fmt, ...) { +#ifndef UNITTEST if (*bufPtr == nullptr || bufLen == nullptr || fmt == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -345,11 +395,15 @@ static int SpePktOutString(int *err, char **bufPtr, size_t *bufLen, } return ret; +#else + return 0; +#endif } static int SpePktDescEvent(const struct SpePkt *packet, char *buf, size_t bufLen) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -403,11 +457,15 @@ static int SpePktDescEvent(const struct SpePkt *packet, } return err; +#else + return 0; +#endif } static int SpePktDescOpType(const struct SpePkt *packet, char *buf, size_t bufLen) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -503,11 +561,15 @@ static int SpePktDescOpType(const struct SpePkt *packet, } return err; +#else + return 0; +#endif } static int SpePktDescAddr(const struct SpePkt *packet, char *buf, size_t bufLen) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -553,11 +615,15 @@ static int SpePktDescAddr(const struct SpePkt *packet, } return err; +#else + return 0; +#endif } static int SpePktDesCont(const struct SpePkt *packet, char *buf, size_t bufLen) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -585,11 +651,15 @@ static int SpePktDesCont(const struct SpePkt *packet, } return err; +#else + return 0; +#endif } int SpePktDesc(const struct SpePkt *packet, char *buf, size_t bufLen) { +#ifndef UNITTEST if (buf == nullptr || packet == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -642,10 +712,14 @@ int SpePktDesc(const struct SpePkt *packet, char *buf, } return err; +#else + return 0; +#endif } static u64 SpeCalcIp(int index, u64 payload) { +#ifndef UNITTEST u64 ns; u64 el; u64 val; @@ -701,10 +775,14 @@ static u64 SpeCalcIp(int index, u64 payload) } return payload; +#else + return 0; +#endif } struct SpeDecoder *SpeDecoderNew(struct SpeParams *params) { +#ifndef UNITTEST if (params == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -720,20 +798,26 @@ struct SpeDecoder *SpeDecoderNew(struct SpeParams *params) decoder->data = params->data; return decoder; +#else + return nullptr; +#endif } void SpeDecoderFree(struct SpeDecoder *decoder) { +#ifndef UNITTEST if (decoder == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); return; } free(decoder); +#endif } static int SpeGetNextPacket(struct SpeDecoder *decoder) { +#ifndef UNITTEST if (decoder == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -761,11 +845,13 @@ static int SpeGetNextPacket(struct SpeDecoder *decoder) decoder->buf += ret; decoder->len -= static_cast(ret); } while (decoder->packet.type == PERF_SPE_PAD); +#endif return 1; } static int SpeReadRecord(struct SpeDecoder *decoder) { +#ifndef UNITTEST u64 payload; u64 ip; if (decoder == nullptr) { @@ -889,21 +975,27 @@ static int SpeReadRecord(struct SpeDecoder *decoder) return -1; } } +#endif return 0; } int SpeDecode(struct SpeDecoder *decoder) { +#ifndef UNITTEST if (decoder == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); return -1; } return SpeReadRecord(decoder); +#else + return 0; +#endif } struct SpeDecoder *SpeDecoderDataNew(const unsigned char *speBuf, size_t speLen) { +#ifndef UNITTEST if (speBuf == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -921,10 +1013,14 @@ struct SpeDecoder *SpeDecoderDataNew(const unsigned char *speBuf, size_t speLen) decoder->len = speLen; return decoder; +#else + return nullptr; +#endif } void SpeDumpRawData(unsigned char *buf, size_t len, int indent, FILE *outputDump) { +#ifndef UNITTEST if (buf == nullptr) { printf("Invalid pointer!\n"); HLOGV("Invalid pointer!"); @@ -972,6 +1068,7 @@ void SpeDumpRawData(unsigned char *buf, size_t len, int indent, FILE *outputDump break; } } +#endif } std::map> AuxRawDataMap_; @@ -998,6 +1095,7 @@ constexpr const int SPE_PERCENTAGE_OFFSET_LEN = 20; void AddReportItems(const std::vector& auxRawData) { +#ifndef UNITTEST for (const auto& data : auxRawData) { for (auto type : DEFAULT_SPE_EVENT_TYPE) { if (data.type & type) { @@ -1020,10 +1118,12 @@ void AddReportItems(const std::vector& auxRawData) } } } +#endif } void UpdateHeating() { +#ifndef UNITTEST for (auto it = AuxRawDataMap_.begin(); it != AuxRawDataMap_.end(); it++) { u64 cc = typeCount[it->first]; for (auto& it2 : it->second) { @@ -1032,6 +1132,7 @@ void UpdateHeating() it2.second.heating = heating; } } +#endif } void GetSpeEventNameByType(uint32_t type, std::string& eventName) @@ -1075,6 +1176,7 @@ void GetSpeEventNameByType(uint32_t type, std::string& eventName) void DumpSpeReportHead(int indent, uint32_t type, uint64_t count) { +#ifndef UNITTEST std::string eventName = ""; GetSpeEventNameByType(type, eventName); PRINT_INDENT(indent, "\nEvent :%s\n", eventName.c_str()); @@ -1095,11 +1197,13 @@ void DumpSpeReportHead(int indent, uint32_t type, uint64_t count) PRINT_INDENT(indent, "%-*s", SPE_PERCENTAGE_FUNC_LEN, func.c_str()); const std::string offset = " offset"; PRINT_INDENT(indent, "%-*s\n", SPE_PERCENTAGE_OFFSET_LEN, offset.c_str()); +#endif return; } void DumpSpeReportData(int indent, FILE *outputDump) { +#ifndef UNITTEST if (outputDump != nullptr) { g_outputDump = outputDump; } @@ -1120,6 +1224,7 @@ void DumpSpeReportData(int indent, FILE *outputDump) PRINT_INDENT(indent + 1, "0x%llx\n", it2.second.offset); } } +#endif } } // namespace HiPerf } // namespace Developtools diff --git a/src/virtual_thread.cpp b/src/virtual_thread.cpp index a65bac6..9825ea5 100644 --- a/src/virtual_thread.cpp +++ b/src/virtual_thread.cpp @@ -144,18 +144,6 @@ std::shared_ptr VirtualThread::FindMapByFileInfo(const std::string name, return nullptr; } -std::shared_ptr VirtualThread::FindFirstMapByFileInfo(const std::string name) const -{ - for (const auto &map : memMaps_) { - if (map == nullptr || name != map->name) { - continue; - } - return map; - } - HLOGM("not found map for %s ", name.c_str()); - return nullptr; -} - SymbolsFile *VirtualThread::FindSymbolsFileByMap(std::shared_ptr map) const { if (map == nullptr) { diff --git a/test/BUILD.gn b/test/BUILD.gn index 9802830..ea2f0d1 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -102,7 +102,7 @@ ohos_unittest("hiperf_unittest") { cflags = [ "-Dprivate=public", #allow test code access private members ] - + cflags += [ "-DUNITTEST" ] sources = sources_interface sources += sources_base if (is_linux) { diff --git a/test/unittest/resource/ohos_test.xml b/test/unittest/resource/ohos_test.xml index f306a03..e3354ca 100644 --- a/test/unittest/resource/ohos_test.xml +++ b/test/unittest/resource/ohos_test.xml @@ -95,7 +95,6 @@