修改变量命名

Signed-off-by: yuanye <yuanye64@huawei.com>
This commit is contained in:
yuanye 2024-11-16 23:58:44 +08:00
parent b260a3a786
commit e0abef1784
6 changed files with 20 additions and 54 deletions

View File

@ -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 <typename DataType, const char* RECORD_TYPE_NAME>
// void PerfEventRecordTemplate<DataType, RECORD_TYPE_NAME>::Init(perf_event_type type, bool inKernel)
// {
// }
// template <typename DataType, const char* RECORD_TYPE_NAME>
// void PerfEventRecordTemplate<DataType, RECORD_TYPE_NAME>::Init(perf_event_hiperf_ext_type type)
// {
// }
// template <typename DataType, const char* RECORD_TYPE_NAME>
// void PerfEventRecordTemplate<DataType, RECORD_TYPE_NAME>::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<perf_event_header *>(p));
// size_t dataSize = GetSize();
// if (dataSize >= sizeof(header_)) {
// size_t copySize = dataSize - sizeof(header_);
// if (memcpy_s(reinterpret_cast<uint8_t *>(&data_), sizeof(data_), p + sizeof(header_), copySize) != 0) {
// HLOGE("init perf record memcpy_s failed!");
// }
// } else {
// HLOGE("init perf record failed!");
// }
// }
template <typename DataType, const char* NAME>
void PerfEventRecordTemplate<DataType, NAME>::GetHeaderBinary(std::vector<uint8_t>& buf) const
{
@ -241,7 +208,7 @@ void PerfEventRecordTemplate<DataType, NAME>::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<DataType, NAME>::Dump(int indent, std::string outpu
template <typename DataType, const char* NAME>
void PerfEventRecordTemplate<DataType, NAME>::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<typename T>
void PushToBinary(bool condition, uint8_t*& p, const T& v);
void PushToBinary(bool condition, uint8_t *&p, const T &v);
template<typename T1, typename T2>
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<typename T>
void PopFromBinary(bool condition, uint8_t*& p, T& v);
void PopFromBinary(bool condition, uint8_t *&p, T &v);
template<typename T1, typename T2>
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

View File

@ -20,8 +20,6 @@
#include "utilities.h"
// using namespace OHOS::HiviewDFX;
// using namespace std;
namespace OHOS {
namespace Developtools {
namespace HiPerf {

View File

@ -279,7 +279,7 @@ bool PerfFileReader::ReadRecord(ProcessRecordCB &callback)
PerfEventRecord& record = PerfEventRecordFactory::GetPerfEventRecord(
static_cast<perf_event_type>(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());

View File

@ -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<u8> buf(RECORD_SIZE_LIMIT_SPE);
@ -189,7 +189,7 @@ bool PerfFileWriter::ReadRecords(ProcessRecordCB &callback)
PerfEventRecord& record = PerfEventRecordFactory::GetPerfEventRecord(static_cast<perf_event_type>(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);

View File

@ -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) {

View File

@ -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<microseconds>(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<PerfRecordSample*>(&record);
#if USE_COLLECT_SYMBOLIC