From e0abef1784e99be0f89cbbb926b1cb822af610d7 Mon Sep 17 00:00:00 2001 From: yuanye Date: Sat, 16 Nov 2024 23:58:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=98=E9=87=8F=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yuanye --- include/perf_event_record.h | 50 +++++++------------------------------ src/perf_event_record.cpp | 2 -- src/perf_file_reader.cpp | 2 +- src/perf_file_writer.cpp | 6 ++--- src/subcommand_dump.cpp | 2 +- src/subcommand_record.cpp | 12 ++++----- 6 files changed, 20 insertions(+), 54 deletions(-) diff --git a/include/perf_event_record.h b/include/perf_event_record.h index 938a2ce..4939e23 100644 --- a/include/perf_event_record.h +++ b/include/perf_event_record.h @@ -73,7 +73,7 @@ struct AttrWithId { class PerfEventRecord { public: - virtual const char* GetNameP() const = 0; + virtual const char* GetName() const = 0; virtual void Init(uint8_t* data, const perf_event_attr& attr) = 0; virtual ~PerfEventRecord() = default; @@ -104,7 +104,7 @@ public: struct perf_event_header header_ = {}; DataType data_ = {}; - const char* GetNameP() const override final + const char* GetName() const override final { return RECORD_TYPE_NAME; } @@ -184,39 +184,6 @@ protected: } }; -// PerfEventRecord -// template -// void PerfEventRecordTemplate::Init(perf_event_type type, bool inKernel) -// { -// } - -// template -// void PerfEventRecordTemplate::Init(perf_event_hiperf_ext_type type) -// { -// } - -// template -// void PerfEventRecordTemplate::Init(uint8_t *p, const perf_event_attr&) -// { -// if (p == nullptr) { -// header_.type = PERF_RECORD_MMAP; -// header_.misc = PERF_RECORD_MISC_USER; -// header_.size = 0; -// return; -// } -// header_ = *(reinterpret_cast(p)); - -// size_t dataSize = GetSize(); -// if (dataSize >= sizeof(header_)) { -// size_t copySize = dataSize - sizeof(header_); -// if (memcpy_s(reinterpret_cast(&data_), sizeof(data_), p + sizeof(header_), copySize) != 0) { -// HLOGE("init perf record memcpy_s failed!"); -// } -// } else { -// HLOGE("init perf record failed!"); -// } -// } - template void PerfEventRecordTemplate::GetHeaderBinary(std::vector& buf) const { @@ -241,7 +208,7 @@ void PerfEventRecordTemplate::Dump(int indent, std::string outpu } } PRINT_INDENT(indent, "\n"); - PRINT_INDENT(indent, "record %s: type %u, misc %u, size %zu\n", GetNameP(), GetType(), + PRINT_INDENT(indent, "record %s: type %u, misc %u, size %zu\n", GetName(), GetType(), GetMisc(), GetSize()); DumpData(indent + 1); } @@ -249,12 +216,13 @@ void PerfEventRecordTemplate::Dump(int indent, std::string outpu template void PerfEventRecordTemplate::DumpLog(const std::string& prefix) const { - HLOGV("%s: record %s: type %u, misc %u, size %zu\n", prefix.c_str(), GetNameP(), + HLOGV("%s: record %s: type %u, misc %u, size %zu\n", prefix.c_str(), GetName(), GetType(), GetMisc(), GetSize()); } // define convert from linux/perf_event.h // description from https://man7.org/linux/man-pages/man2/perf_event_open.2.html + constexpr __u64 SAMPLE_ID = PERF_SAMPLE_TID | PERF_SAMPLE_TIME | PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_IDENTIFIER; @@ -528,16 +496,16 @@ private: }; template -void PushToBinary(bool condition, uint8_t*& p, const T& v); +void PushToBinary(bool condition, uint8_t *&p, const T &v); template -void PushToBinary2(bool condition, uint8_t*& p, const T1& v1, const T2& v2); +void PushToBinary2(bool condition, uint8_t *&p, const T1 &v1, const T2 &v2); template -void PopFromBinary(bool condition, uint8_t*& p, T& v); +void PopFromBinary(bool condition, uint8_t *&p, T &v); template -void PopFromBinary2(bool condition, uint8_t*& p, T1& v1, T2& v2); +void PopFromBinary2(bool condition, uint8_t *&p, T1 &v1, T2 &v2); } // namespace HiPerf } // namespace Developtools } // namespace OHOS diff --git a/src/perf_event_record.cpp b/src/perf_event_record.cpp index 68e01d9..10a2928 100644 --- a/src/perf_event_record.cpp +++ b/src/perf_event_record.cpp @@ -20,8 +20,6 @@ #include "utilities.h" -// using namespace OHOS::HiviewDFX; -// using namespace std; namespace OHOS { namespace Developtools { namespace HiPerf { diff --git a/src/perf_file_reader.cpp b/src/perf_file_reader.cpp index 180c282..9900880 100644 --- a/src/perf_file_reader.cpp +++ b/src/perf_file_reader.cpp @@ -279,7 +279,7 @@ bool PerfFileReader::ReadRecord(ProcessRecordCB &callback) PerfEventRecord& record = PerfEventRecordFactory::GetPerfEventRecord( static_cast(header->type), data, *attr); // unknown record , break the process - if (record.GetNameP() == nullptr) { + if (record.GetName() == nullptr) { return false; } else { HLOGV("record type %u", record.GetType()); diff --git a/src/perf_file_writer.cpp b/src/perf_file_writer.cpp index a586b1e..69e8532 100644 --- a/src/perf_file_writer.cpp +++ b/src/perf_file_writer.cpp @@ -125,10 +125,10 @@ bool PerfFileWriter::WriteRecord(const PerfEventRecord &record) return false; } - HLOGV("write '%s', size %zu", record.GetNameP(), record.GetSize()); + HLOGV("write '%s', size %zu", record.GetName(), record.GetSize()); CHECK_TRUE(record.GetSize() > RECORD_SIZE_LIMIT_SPE, false, 1, - "%s record size exceed limit", record.GetNameP()); + "%s record size exceed limit", record.GetName()); // signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0xb64eb195 static std::vector buf(RECORD_SIZE_LIMIT_SPE); @@ -189,7 +189,7 @@ bool PerfFileWriter::ReadRecords(ProcessRecordCB &callback) PerfEventRecord& record = PerfEventRecordFactory::GetPerfEventRecord(static_cast(header->type), data, defaultEventAttr_); // skip unknown record - CHECK_TRUE(record.GetNameP() == nullptr, true, 0, ""); + CHECK_TRUE(record.GetName() == nullptr, true, 0, ""); remainingSize = remainingSize - header->size - speSize; // call callback to process, do not destroy the record callback(record); diff --git a/src/subcommand_dump.cpp b/src/subcommand_dump.cpp index f2b0a31..302c301 100644 --- a/src/subcommand_dump.cpp +++ b/src/subcommand_dump.cpp @@ -440,7 +440,7 @@ void SubCommandDump::DumpDataPortion(int indent) { int recordCount = 0; auto recordcCallback = [&](PerfEventRecord& record) { - CHECK_TRUE(record.GetNameP() == nullptr, false, 0, ""); // return false in callback can stop the read process + CHECK_TRUE(record.GetName() == nullptr, false, 0, ""); // return false in callback can stop the read process // for UT if (exportSampleIndex_ > 0) { diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index 41f265e..e9d844b 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -1325,7 +1325,7 @@ void SubCommandRecord::RemoveVdsoTmpFile() bool SubCommandRecord::ProcessRecord(PerfEventRecord& record) { - CHECK_TRUE(record.GetNameP() == nullptr, false, 1, "record is null"); + CHECK_TRUE(record.GetName() == nullptr, false, 1, "record is null"); #if HIDEBUG_RECORD_NOT_PROCESS // some times we want to check performance // but we still want to see the record number @@ -1375,14 +1375,14 @@ bool SubCommandRecord::SaveRecord(PerfEventRecord& record, bool ptrReleaseFlag) } } - if (record.GetNameP() == nullptr) { + if (record.GetName() == nullptr) { #ifdef HIPERF_DEBUG_TIME const auto saveTime = steady_clock::now(); #endif if (!fileWriter_->WriteRecord(record)) { // write file failed, need stop record perfEvents_.StopTracking(); - HLOGV("fail to write record %s", record.GetNameP()); + HLOGV("fail to write record %s", record.GetName()); return false; } if (record.GetType() == PERF_RECORD_SAMPLE) { @@ -1390,7 +1390,7 @@ bool SubCommandRecord::SaveRecord(PerfEventRecord& record, bool ptrReleaseFlag) } else { recordNoSamples_++; } - HLOGV(" write done. size=%zu name=%s", record.GetSize(), record.GetNameP()); + HLOGV(" write done. size=%zu name=%s", record.GetSize(), record.GetName()); #ifdef HIPERF_DEBUG_TIME saveRecordTimes_ += duration_cast(steady_clock::now() - saveTime); #endif @@ -1607,7 +1607,7 @@ bool SubCommandRecord::PostProcessRecordFile() // 2. read out the file and unwind auto record_callback = [&](PerfEventRecord& record) { - if (record.GetNameP() == nullptr) { + if (record.GetName() == nullptr) { // return false in callback can stop the read process return false; } else if (record.GetType() == PERF_RECORD_SAMPLE) { @@ -1657,7 +1657,7 @@ void SubCommandRecord::SymbolicHits() bool SubCommandRecord::CollectionSymbol(PerfEventRecord& record) { - CHECK_TRUE(record.GetNameP() == nullptr, false, 0, ""); + CHECK_TRUE(record.GetName() == nullptr, false, 0, ""); if (record.GetType() == PERF_RECORD_SAMPLE) { PerfRecordSample* sample = static_cast(&record); #if USE_COLLECT_SYMBOLIC