diff --git a/include/hiperf_hilog.h b/include/hiperf_hilog.h index b2a64c73595db73127952abafee28c96d22c9d85..2121f870695acacce627fb067c17178cd4664647 100644 --- a/include/hiperf_hilog.h +++ b/include/hiperf_hilog.h @@ -124,7 +124,7 @@ static inline std::string StringFormat(const char* fmt, ...) #define LOG_TYPE_WITH_HILOG 3 #define CHECK_TRUE(expr, retval, log, fmt, ...) \ do { \ - if (expr) { \ + if (!(expr)) { \ if (log == 1) { \ std::string str = StringFormat(fmt, ##__VA_ARGS__); \ HLOGE("%s", str.c_str()); \ diff --git a/src/callstack.cpp b/src/callstack.cpp index 7be78a696c8d8a2153ae61bcd5e423e82664b0eb..aa30e5e9b38d1629d4ed20740529ad860db47712 100644 --- a/src/callstack.cpp +++ b/src/callstack.cpp @@ -62,8 +62,8 @@ bool CallStack::ReadVirtualThreadMemory(UnwindInfo &unwindInfoPtr, ADDR_TYPE vad bool CallStack::GetIpSP(uint64_t &ip, uint64_t &sp, const u64 *regs, size_t regNum) const { if (regNum > 0) { - CHECK_TRUE(!RegisterGetSPValue(sp, arch_, regs, regNum), false, 1, "unable get sp"); - CHECK_TRUE(!RegisterGetIPValue(ip, arch_, regs, regNum), false, 1, "unable get ip"); + CHECK_TRUE(RegisterGetSPValue(sp, arch_, regs, regNum), false, 1, "unable get sp"); + CHECK_TRUE(RegisterGetIPValue(ip, arch_, regs, regNum), false, 1, "unable get ip"); if (ip != 0) { return true; } @@ -283,7 +283,7 @@ bool CallStack::DoUnwind2(const VirtualThread &thread, std::vector &ca static std::shared_ptr regs = std::make_shared(); regs->SetRegsData(reinterpret_cast(regs_), regsNum_); #endif - CHECK_TRUE(unwinder == nullptr, false, 0, ""); + CHECK_TRUE(unwinder != nullptr, false, 0, ""); unwinder->SetRegs(regs); unwinder->Unwind(&unwindInfo); callStack = unwinder->GetFrames(); @@ -316,7 +316,7 @@ int CallStack::FillUnwindTable(SymbolsFile *symbolsFile, std::shared_ptr uintptr_t pc, UnwindTableInfo& outTableInfo) { HLOGM("try search debug info at %s", symbolsFile->filePath_.c_str()); - CHECK_TRUE(unwindInfoPtr == nullptr, -1, 0, ""); + CHECK_TRUE(unwindInfoPtr != nullptr, -1, 0, ""); auto &tableInfoMap = unwindInfoPtr->callStack.unwindTableInfoMap_; // all the thread in same process have same mmap and symbols if (tableInfoMap.find(unwindInfoPtr->thread.pid_) == tableInfoMap.end()) { @@ -331,7 +331,7 @@ int CallStack::FillUnwindTable(SymbolsFile *symbolsFile, std::shared_ptr return -1; } if (elf->FindUnwindTableInfo(pc, map, uti) == 0) { - CHECK_TRUE(uti.format == -1, -1, 1, "parse unwind table failed."); + CHECK_TRUE(uti.format != -1, -1, 1, "parse unwind table failed."); unwTabMap[symbolsFile->filePath_] = uti; outTableInfo = unwTabMap[symbolsFile->filePath_]; DumpTableInfo(uti); @@ -350,7 +350,7 @@ int CallStack::FillUnwindTable(SymbolsFile *symbolsFile, std::shared_ptr int CallStack::FindUnwindTable(uintptr_t pc, UnwindTableInfo& outTableInfo, void *arg) { UnwindInfo *unwindInfoPtr = static_cast(arg); - CHECK_TRUE(unwindInfoPtr == nullptr, -1, 0, ""); + CHECK_TRUE(unwindInfoPtr != nullptr, -1, 0, ""); int64_t mapIndex = unwindInfoPtr->thread.FindMapIndexByAddr(pc); if (mapIndex >= 0) { auto map = unwindInfoPtr->thread.GetMaps()[mapIndex]; @@ -378,7 +378,7 @@ int CallStack::AccessMem2(uintptr_t addr, uintptr_t *val, void *arg) *val = 0; /* Check overflow. */ - CHECK_TRUE(unwindInfoPtr == nullptr || (addr + sizeof(uintptr_t) < addr), -1, 1, + CHECK_TRUE(unwindInfoPtr != nullptr && (addr + sizeof(uintptr_t) >= addr), -1, 1, "unwindInfoPtr is null or address overflow at 0x%" UNW_WORD_PFLAG " increase 0x%zu", addr, sizeof(uintptr_t)); diff --git a/src/ipc_utilities.cpp b/src/ipc_utilities.cpp index d0e3c9e82c70536b88bebda2bb58ac8d44fec899..924ba682f066f553be70d7c4ec967e8bf78dc885 100644 --- a/src/ipc_utilities.cpp +++ b/src/ipc_utilities.cpp @@ -91,24 +91,24 @@ bool IsApplicationEncryped(const int pid) { #if defined(is_ohos) && is_ohos && defined(BUNDLE_FRAMEWORK_ENABLE) g_haveIpc.store(true); - CHECK_TRUE(pid <= 0, true, LOG_TYPE_PRINTF, "Invalid -p value '%d', the pid should be larger than 0\n", pid); + CHECK_TRUE(pid > 0, true, LOG_TYPE_PRINTF, "Invalid -p value '%d', the pid should be larger than 0\n", pid); std::string bundleName = GetProcessName(pid); - CHECK_TRUE(bundleName.empty(), true, 1, "bundleName is empty,pid is %d", pid); + CHECK_TRUE(!bundleName.empty(), true, 1, "bundleName is empty,pid is %d", pid); auto pos = bundleName.find(":"); if (pos != std::string::npos) { bundleName = bundleName.substr(0, pos); } sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - CHECK_TRUE(sam == nullptr, true, LOG_TYPE_PRINTF, "GetSystemAbilityManager failed!\n"); + CHECK_TRUE(sam != nullptr, true, LOG_TYPE_PRINTF, "GetSystemAbilityManager failed!\n"); sptr remoteObject = sam->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - CHECK_TRUE(remoteObject == nullptr, true, LOG_TYPE_PRINTF, "Get BundleMgr SA failed!\n"); + CHECK_TRUE(remoteObject != nullptr, true, LOG_TYPE_PRINTF, "Get BundleMgr SA failed!\n"); sptr proxy = iface_cast(remoteObject); - CHECK_TRUE(proxy == nullptr, true, LOG_TYPE_PRINTF, "iface_cast failed!\n"); + CHECK_TRUE(proxy != nullptr, true, LOG_TYPE_PRINTF, "iface_cast failed!\n"); AppExecFwk::ApplicationInfo appInfo; bool ret = proxy->GetApplicationInfo(bundleName, AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, AppExecFwk::Constants::ANY_USERID, appInfo); - CHECK_TRUE(!ret, true, 1, "%s:%s GetApplicationInfo failed!", __func__, bundleName.c_str()); + CHECK_TRUE(ret, true, 1, "%s:%s GetApplicationInfo failed!", __func__, bundleName.c_str()); bool isEncrypted = (appInfo.applicationReservedFlag & static_cast(AppExecFwk::ApplicationReservedFlag::ENCRYPTED_APPLICATION)) != 0; HLOGD("check application encryped.%d : %s, pid:%d", isEncrypted, bundleName.c_str(), pid); diff --git a/src/perf_events.cpp b/src/perf_events.cpp index 7580005a4a13c8e915772e2c765db37ee97040ab..dca64b69b86896775f11784e32b82acb28fb80db 100644 --- a/src/perf_events.cpp +++ b/src/perf_events.cpp @@ -68,7 +68,7 @@ void PerfEvents::SpeReadData(void *dataPage, u64 *dataTail, uint8_t *buf, u32 si u32 offset = static_cast(*dataTail); u32 copySize; u32 traceSize = size; - CHECK_TRUE(size > (auxMmapPages_ * pageSize_ + sizeof(struct PerfRecordAuxtraceData)), + CHECK_TRUE(size <= (auxMmapPages_ * pageSize_ + sizeof(struct PerfRecordAuxtraceData)), NO_RETVAL, 1, "buf size invalid"); while (traceSize > 0) { offset = CALC_OFFSET(offset, auxMmapPages_ * pageSize_); @@ -204,7 +204,7 @@ PerfEvents::~PerfEvents() bool PerfEvents::IsEventSupport(perf_type_id type, __u64 config) { std::unique_ptr attr = PerfEvents::CreateDefaultAttr(type, config); - CHECK_TRUE(attr == nullptr, false, 1, "attr is nullptr"); + CHECK_TRUE(attr != nullptr, false, 1, "attr is nullptr"); UniqueFd fd = Open(*attr.get()); if (fd < 0) { printf("event not support %s\n", GetStaticConfigName(type, config).c_str()); @@ -227,7 +227,7 @@ bool PerfEvents::SetBranchSampleType(uint64_t value) // cpu-clcles event must be supported std::unique_ptr attr = PerfEvents::CreateDefaultAttr(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); - CHECK_TRUE(attr == nullptr, false, 0, ""); + CHECK_TRUE(attr != nullptr, false, 0, ""); attr->sample_type |= PERF_SAMPLE_BRANCH_STACK; attr->branch_sample_type = value; if (!IsEventAttrSupport(*attr.get())) { @@ -442,9 +442,9 @@ bool PerfEvents::AddEvent(perf_type_id type, __u64 config, bool excludeUser, boo bool followGroup) { HLOG_ASSERT(!excludeUser || !excludeKernel); - CHECK_TRUE(followGroup && eventGroupItem_.empty(), false, 1, "no group leader create before"); + CHECK_TRUE(!followGroup || !eventGroupItem_.empty(), false, 1, "no group leader create before"); // found the event name - CHECK_TRUE(!IsEventSupport(type, config), false, 0, ""); + CHECK_TRUE(IsEventSupport(type, config), false, 0, ""); HLOGV("type %d config %llu excludeUser %d excludeKernel %d followGroup %d", type, config, excludeUser, excludeKernel, followGroup); @@ -593,10 +593,10 @@ static void RecoverCaptureSig() bool PerfEvents::PrepareTracking(void) { // 1. prepare cpu pid - CHECK_TRUE(!PrepareFdEvents(), false, 1, "PrepareFdEvents() failed"); + CHECK_TRUE(PrepareFdEvents(), false, 1, "PrepareFdEvents() failed"); // 2. create events - CHECK_TRUE(!CreateFdEvents(), false, 1, "CreateFdEvents() failed"); + CHECK_TRUE(CreateFdEvents(), false, 1, "CreateFdEvents() failed"); HLOGV("success"); prepared_ = true; @@ -750,21 +750,21 @@ bool PerfEvents::StopTracking(void) trackedCommand_->Stop(); } } - CHECK_TRUE(!PerfEventsEnable(false), false, 1, "StopTracking : PerfEventsEnable(false) failed"); + CHECK_TRUE(PerfEventsEnable(false), false, 1, "StopTracking : PerfEventsEnable(false) failed"); } return true; } bool PerfEvents::PauseTracking(void) { - CHECK_TRUE(!startedTracking_, false, 0, ""); + CHECK_TRUE(startedTracking_, false, 0, ""); HIPERF_HILOGI(MODULE_DEFAULT, "some one called PauseTracking"); return PerfEventsEnable(false); } bool PerfEvents::ResumeTracking(void) { - CHECK_TRUE(!startedTracking_, false, 0, ""); + CHECK_TRUE(startedTracking_, false, 0, ""); HIPERF_HILOGI(MODULE_DEFAULT, "some one called ResumeTracking"); return PerfEventsEnable(true); } @@ -788,8 +788,8 @@ bool PerfEvents::OutputTracking() bool PerfEvents::EnableTracking() { - CHECK_TRUE(startedTracking_, true, 0, ""); - CHECK_TRUE(!PerfEventsEnable(true), false, 1, "PerfEvents::PerfEventsEnable() failed"); + CHECK_TRUE(!startedTracking_, true, 0, ""); + CHECK_TRUE(PerfEventsEnable(true), false, 1, "PerfEvents::PerfEventsEnable() failed"); if (trackedCommand_) { // start tracked Command @@ -944,7 +944,7 @@ void PerfEvents::SetSampleFrequency(unsigned int frequency) sampleFreq_ = frequency; } int maxRate = 0; - CHECK_TRUE(!ReadIntFromProcFile("/proc/sys/kernel/perf_event_max_sample_rate", maxRate), + CHECK_TRUE(ReadIntFromProcFile("/proc/sys/kernel/perf_event_max_sample_rate", maxRate), NO_RETVAL, LOG_TYPE_PRINTF, "read perf_event_max_sample_rate fail.\n"); if (sampleFreq_ > static_cast(maxRate)) { @@ -1104,7 +1104,7 @@ bool PerfEvents::PrepareFdEvents(void) bool PerfEvents::CreateFdEvents(void) { // must be some events , or will failed - CHECK_TRUE(eventGroupItem_.empty(), false, LOG_TYPE_PRINTF, "no event select.\n"); + CHECK_TRUE(!eventGroupItem_.empty(), false, LOG_TYPE_PRINTF, "no event select.\n"); // create each fd by cpu and process user select /* @@ -1220,7 +1220,7 @@ bool PerfEvents::CreateFdEvents(void) } } - CHECK_TRUE(fdNumber == 0, false, 1, "open %d fd for %d events", fdNumber, eventNumber); + CHECK_TRUE(fdNumber != 0, false, 1, "open %d fd for %d events", fdNumber, eventNumber); HLOGD("will try read %u events from %u fd (%zu groups):", eventNumber, fdNumber, eventGroupItem_.size()); @@ -1294,7 +1294,7 @@ bool PerfEvents::CreateSpeMmap(const FdItem &item, const perf_event_attr &attr) if (it == cpuMmap_.end()) { void *rbuf = mmap(nullptr, (1 + auxMmapPages_) * pageSize_, (PROT_READ | PROT_WRITE), MAP_SHARED, item.fd.Get(), 0); - CHECK_TRUE(rbuf == MMAP_FAILED, false, 1, ""); + CHECK_TRUE(rbuf != MMAP_FAILED, false, 1, ""); void *auxRbuf = mmap(nullptr, auxMmapPages_ * pageSize_, (PROT_READ | PROT_WRITE), MAP_SHARED, item.fd.Get(), 0); MmapFd mmapItem; @@ -1554,7 +1554,7 @@ bool PerfEvents::GetRecordFromMmap(MmapFd &mmap) void PerfEvents::GetRecordFieldFromMmap(MmapFd &mmap, void *dest, size_t pos, size_t size) { - CHECK_TRUE(mmap.bufSize == 0, NO_RETVAL, 0, ""); + CHECK_TRUE(mmap.bufSize != 0, NO_RETVAL, 0, ""); pos = pos % mmap.bufSize; size_t tailSize = mmap.bufSize - pos; size_t copySize = std::min(size, tailSize); @@ -1648,7 +1648,7 @@ bool PerfEvents::CutStackAndMove(MmapFd &mmap) mmap.header.size -= stackSize - newStackSize; // reduce the stack size uint8_t *buf = recordBuf_->AllocForWrite(mmap.header.size); // copy1: new_header - CHECK_TRUE(buf == nullptr, false, 0, ""); + CHECK_TRUE(buf != nullptr, false, 0, ""); if (memcpy_s(buf, sizeof(perf_event_header), &(mmap.header), sizeof(perf_event_header)) != 0) { HLOGEP("memcpy_s %p to %p failed. size %zd", &(mmap.header), buf, sizeof(perf_event_header)); diff --git a/src/perf_file_format.cpp b/src/perf_file_format.cpp index 410eb07d4d0b9d4d0b8dd70a61cc1cc741a6f7d5..7ef6865be91cf06e94a777b3480f9ad0e0f87e99 100644 --- a/src/perf_file_format.cpp +++ b/src/perf_file_format.cpp @@ -102,11 +102,11 @@ bool PerfFileSection::Write(const char *buf, size_t size) bool PerfFileSection::Write(const char *buf, size_t size, size_t max) { - CHECK_TRUE(offset_ + size > maxSize_, false, 1, + CHECK_TRUE(offset_ + size <= maxSize_, false, 1, "write out of size!!! offset_ %zu size %zu max %zu", offset_, size, maxSize_); - CHECK_TRUE(offset_ + max > maxSize_, false, 1, + CHECK_TRUE(offset_ + max <= maxSize_, false, 1, "write out of size!!! offset_ %zu size %zu max %zu", offset_, size, maxSize_); - CHECK_TRUE(wBuffer_ == nullptr, false, 0, ""); + CHECK_TRUE(wBuffer_ != nullptr, false, 0, ""); std::copy(buf, buf + size, wBuffer_ + offset_); if (size >= max) { offset_ += size; @@ -132,10 +132,10 @@ bool PerfFileSection::Read(uint64_t &value) bool PerfFileSection::Read(std::string &value) { uint32_t size = 0; - CHECK_TRUE(!Read(size), false, 0, ""); + CHECK_TRUE(Read(size), false, 0, ""); // if size large than buf size or 0 size ? // don't assert for fuzz test - CHECK_TRUE(size == 0 || size > maxSize_, false, 0, ""); + CHECK_TRUE(size != 0 && size <= maxSize_, false, 0, ""); char *buf = new(std::nothrow) char[size]; if (buf == nullptr) { HLOGE("buf is nullptr."); @@ -191,7 +191,7 @@ PerfFileSectionString::PerfFileSectionString(FEATURE id, const char *buf, size_t : PerfFileSection(id) { Init(buf, size); - CHECK_TRUE(!Read(stdString_), NO_RETVAL, 0, ""); // or throw ... + CHECK_TRUE(Read(stdString_), NO_RETVAL, 0, ""); // or throw ... } PerfFileSectionString::PerfFileSectionString(FEATURE id, const std::string &charString) @@ -202,7 +202,7 @@ PerfFileSectionString::PerfFileSectionString(FEATURE id, const std::string &char bool PerfFileSectionString::GetBinary(char *buf, size_t size) { - CHECK_TRUE(size < GetSize(), false, 0, ""); + CHECK_TRUE(size >= GetSize(), false, 0, ""); Init(buf, size); Write(stdString_); @@ -303,7 +303,7 @@ bool PerfFileSectionSymbolsFiles::GetBinary(char *buf, size_t size) HLOG_ASSERT(size >= GetSize()); Init(buf, size); - CHECK_TRUE(!Write((uint32_t)symbolFileStructs_.size()), false, 1, + CHECK_TRUE(Write((uint32_t)symbolFileStructs_.size()), false, 1, "PerfFileSectionSymbolsFiles write failed with %zu.", symbolFileStructs_.size()); for (auto &symbolFileStruct : symbolFileStructs_) { Write(symbolFileStruct.filePath_); @@ -385,7 +385,7 @@ bool PerfFileSectionUniStackTable::GetBinary(char *buf, size_t size) size_t PerfFileSectionUniStackTable::GetSize() { - CHECK_TRUE(processStackTable_ == nullptr, 0, 1, "processStackTable_ is nullptr"); + CHECK_TRUE(processStackTable_ != nullptr, 0, 1, "processStackTable_ is nullptr"); size_t size = 0; // section header info size size += sizeof(uint32_t); // how many tables/process @@ -399,7 +399,7 @@ PerfFileSectionNrCpus::PerfFileSectionNrCpus(FEATURE id, const char *buf, size_t : PerfFileSection(id) { Init(buf, size); - CHECK_TRUE(!Read(nrCpusAvailable_) || !Read(nrCpusOnline_), NO_RETVAL, 0, ""); + CHECK_TRUE(Read(nrCpusAvailable_) && !Read(nrCpusOnline_), NO_RETVAL, 0, ""); } PerfFileSectionNrCpus::PerfFileSectionNrCpus(FEATURE id, uint32_t nrCpusAvailable, @@ -410,7 +410,7 @@ PerfFileSectionNrCpus::PerfFileSectionNrCpus(FEATURE id, uint32_t nrCpusAvailabl bool PerfFileSectionNrCpus::GetBinary(char *buf, size_t size) { - CHECK_TRUE(size < GetSize(), false, 0, ""); + CHECK_TRUE(size >= GetSize(), false, 0, ""); Init(buf, size); Write(nrCpusAvailable_); @@ -433,7 +433,7 @@ PerfFileSectionU64::PerfFileSectionU64(FEATURE id, const char *buf, size_t size) : PerfFileSection(id) { Init(buf, size); - CHECK_TRUE(!Read(value_), NO_RETVAL, 0, ""); + CHECK_TRUE(Read(value_), NO_RETVAL, 0, ""); } PerfFileSectionU64::PerfFileSectionU64(FEATURE id, uint64_t v) : PerfFileSection(id) @@ -443,7 +443,7 @@ PerfFileSectionU64::PerfFileSectionU64(FEATURE id, uint64_t v) : PerfFileSection bool PerfFileSectionU64::GetBinary(char *buf, size_t size) { - CHECK_TRUE(size < GetSize(), false, 0, ""); + CHECK_TRUE(size >= GetSize(), false, 0, ""); Init(buf, size); Write(value_); @@ -473,9 +473,9 @@ PerfFileSectionEventDesc::PerfFileSectionEventDesc(FEATURE id, const char *buf, constexpr uint32_t maxIds = 600; Init(buf, size); uint32_t nr = 0; - CHECK_TRUE(!Read(nr), NO_RETVAL, 0, ""); + CHECK_TRUE(Read(nr), NO_RETVAL, 0, ""); uint32_t attrSize = 0; - CHECK_TRUE(!Read(attrSize), NO_RETVAL, 0, ""); + CHECK_TRUE(Read(attrSize), NO_RETVAL, 0, ""); if (attrSize != sizeof(perf_event_attr)) { // only for log or debug HLOGW("perf_event_attr version is different, attrSize %d vs %zu", attrSize, sizeof(perf_event_attr)); @@ -504,10 +504,10 @@ PerfFileSectionEventDesc::PerfFileSectionEventDesc(FEATURE id, const char *buf, } else if (nrIds > maxIds) { HLOGW("nrIds is too large ! %u", nrIds); } - CHECK_TRUE(!Read(eventDesc.name), NO_RETVAL, 0, ""); + CHECK_TRUE(Read(eventDesc.name), NO_RETVAL, 0, ""); HIPERF_ASSERT(nrIds <= MAX_VECTOR_RESIZE_COUNT, "nrIds exceeds 100000\n"); eventDesc.ids.resize(nrIds, 0); - CHECK_TRUE(!Read(reinterpret_cast(eventDesc.ids.data()), sizeof(uint64_t) * nrIds), NO_RETVAL, 0, ""); + CHECK_TRUE(Read(reinterpret_cast(eventDesc.ids.data()), sizeof(uint64_t) * nrIds), NO_RETVAL, 0, ""); eventDesces_.emplace_back(std::move(eventDesc)); } HLOGV("read complete. %zu events", eventDesces_.size()); @@ -515,17 +515,17 @@ PerfFileSectionEventDesc::PerfFileSectionEventDesc(FEATURE id, const char *buf, bool PerfFileSectionEventDesc::GetBinary(char *buf, size_t size) { - CHECK_TRUE(size < GetSize(), false, 0, ""); + CHECK_TRUE(size >= GetSize(), false, 0, ""); Init(buf, size); - CHECK_TRUE(!Write(static_cast(eventDesces_.size())), false, 0, ""); - CHECK_TRUE(!Write(static_cast(sizeof(perf_event_attr))), false, 0, ""); + CHECK_TRUE(Write(static_cast(eventDesces_.size())), false, 0, ""); + CHECK_TRUE(Write(static_cast(sizeof(perf_event_attr))), false, 0, ""); for (auto &eventDesc : eventDesces_) { - CHECK_TRUE(!Write(reinterpret_cast(&(eventDesc.attr)), sizeof(perf_event_attr)), false, 0, ""); - CHECK_TRUE(!Write(static_cast(eventDesc.ids.size())), false, 0, ""); - CHECK_TRUE(!Write(eventDesc.name), false, 0, ""); + CHECK_TRUE(Write(reinterpret_cast(&(eventDesc.attr)), sizeof(perf_event_attr)), false, 0, ""); + CHECK_TRUE(Write(static_cast(eventDesc.ids.size())), false, 0, ""); + CHECK_TRUE(Write(eventDesc.name), false, 0, ""); // clang-format off - CHECK_TRUE(!Write(reinterpret_cast(eventDesc.ids.data()), sizeof(uint64_t) * eventDesc.ids.size()), + CHECK_TRUE(Write(reinterpret_cast(eventDesc.ids.data()), sizeof(uint64_t) * eventDesc.ids.size()), false, 0, ""); // clang-format on } return true; diff --git a/src/perf_file_reader.cpp b/src/perf_file_reader.cpp index b182a611e9ef1d3c1cc920b5a3ebd2afbff823fa..e2e66010c5c4e9ab49323f02218070be9569a826 100644 --- a/src/perf_file_reader.cpp +++ b/src/perf_file_reader.cpp @@ -52,7 +52,7 @@ std::unique_ptr PerfFileReader::Instance(const std::string &file } reader->fp_ = nullptr; - CHECK_TRUE(!UncompressFile(fileName, UNCOMPRESS_TMP_FILE), nullptr, 1, + CHECK_TRUE(UncompressFile(fileName, UNCOMPRESS_TMP_FILE), nullptr, 1, "Fail to UncompressFile(%s)", fileName.c_str()); // open the uncompressed hidden file .perf.data @@ -74,7 +74,7 @@ std::unique_ptr PerfFileReader::Instance(const std::string &file return nullptr; } end: - CHECK_TRUE(!reader->ReadAttrSection(), nullptr, 0, ""); + CHECK_TRUE(reader->ReadAttrSection(), nullptr, 0, ""); return reader; } @@ -143,17 +143,17 @@ bool PerfFileReader::ReadAttrSection() HLOGW("attr size %" PRId64 " doesn't match expected size %zu", header_.attrSize, sizeof(perf_file_attr)); } - CHECK_TRUE(header_.attrSize == 0, false, 0, ""); - CHECK_TRUE(header_.attrSize > THOUSANDS, false, 1, "attr size exceeds 1000"); + CHECK_TRUE(header_.attrSize != 0, false, 0, ""); + CHECK_TRUE(header_.attrSize <= THOUSANDS, false, 1, "attr size exceeds 1000"); int attrCount = header_.attrs.size / header_.attrSize; - CHECK_TRUE(attrCount == 0, false, 1, "no attr in file"); + CHECK_TRUE(attrCount != 0, false, 1, "no attr in file"); if (fseek(fp_, header_.attrs.offset, SEEK_SET) != 0) { HLOGE("fseek() failed"); return false; } for (int i = 0; i < attrCount; ++i) { std::vector buf(header_.attrSize); - CHECK_TRUE(!Read(buf.data(), buf.size()), false, 0, ""); + CHECK_TRUE(Read(buf.data(), buf.size()), false, 0, ""); // size of perf_event_attr change between different linux kernel versions. // can not memcpy to perf_file_attr as a whole perf_file_attr attr {}; @@ -174,7 +174,7 @@ bool PerfFileReader::ReadAttrSection() // read ids for attr for (size_t i = 0; i < vecAttr_.size(); ++i) { std::vector ids; - CHECK_TRUE(!ReadIdsForAttr(vecAttr_[i], &ids), false, 0, ""); + CHECK_TRUE(ReadIdsForAttr(vecAttr_[i], &ids), false, 0, ""); vecAttrIds_.push_back(ids); // map ids to attr index @@ -198,9 +198,9 @@ bool PerfFileReader::ReadIdsForAttr(const perf_file_attr &attr, std::vectorresize(count); - CHECK_TRUE(!Read(ids->data(), attr.ids.size), false, 0, ""); + CHECK_TRUE(Read(ids->data(), attr.ids.size), false, 0, ""); } return true; } @@ -226,7 +226,7 @@ bool PerfFileReader::ReadDataSection(ProcessRecordCB &callback) HLOGD("dataSection_ at offset %" PRId64 " + %" PRId64 "", header_.data.offset, header_.data.size); - CHECK_TRUE(!ReadRecord(callback), false, LOG_TYPE_PRINTF, "some record format is error!\n"); + CHECK_TRUE(ReadRecord(callback), false, LOG_TYPE_PRINTF, "some record format is error!\n"); #ifdef HIPERF_DEBUG_TIME printf("readRecordTime: %" PRId64 " ms\n", @@ -239,7 +239,7 @@ bool PerfFileReader::ReadDataSection(ProcessRecordCB &callback) const perf_event_attr *PerfFileReader::GetDefaultAttr() { - CHECK_TRUE(vecAttr_.empty(), nullptr, 0, ""); + CHECK_TRUE(!vecAttr_.empty(), nullptr, 0, ""); return &(vecAttr_[0].attr); } @@ -254,7 +254,7 @@ bool PerfFileReader::ReadRecord(ProcessRecordCB &callback) uint64_t remainingSize = header_.data.size; size_t recordNumber = 0; const perf_event_attr *attr = GetDefaultAttr(); - CHECK_TRUE(attr == nullptr, false, 1, "attr is null"); + CHECK_TRUE(attr != nullptr, false, 1, "attr is null"); while (remainingSize > 0) { if (remainingSize < sizeof(perf_event_header)) { HLOGW("not enough sizeof perf_event_header"); @@ -349,7 +349,7 @@ bool PerfFileReader::Read(char *buf, uint64_t offset, size_t len) return false; } - CHECK_TRUE(fread(buf, len, 1, fp_) != 1, false, LOG_TYPE_PRINTF, "failed to read file: %d", errno); + CHECK_TRUE(fread(buf, len, 1, fp_) == 1, false, LOG_TYPE_PRINTF, "failed to read file: %d", errno); HLOGM("offset %" PRIx64 " len %zu buf %x %x %x %x", offset, len, buf[0], buf[1], buf[2], buf[3]); return true; @@ -402,19 +402,19 @@ bool PerfFileReader::ReadFeatureSection() for (FEATURE feature : features_) { perf_file_section sectionHeader; // read failed ?? - CHECK_TRUE(!Read((char *)§ionHeader, featureSectionOffsetRead, sizeof(sectionHeader)), + CHECK_TRUE(Read((char *)§ionHeader, featureSectionOffsetRead, sizeof(sectionHeader)), false, LOG_TYPE_PRINTF, "file format not correct. featureSectionOffsetRead '0x%" PRIx64 "\n", featureSectionOffsetRead); HLOGV("process feature %d:%s", feature, PerfFileSection::GetFeatureName(feature).c_str()); HLOGV(" sectionHeader -> read offset '0x%" PRIx64 " size '0x%" PRIx64 "'", sectionHeader.offset, sectionHeader.size); - CHECK_TRUE(sectionHeader.size == 0 || sectionHeader.size > fileSize_, false, 1, + CHECK_TRUE(sectionHeader.size != 0 && sectionHeader.size <= fileSize_, false, 1, "sectionHeader.size %" PRIu64 " is not correct", sectionHeader.size); std::vector buf(sectionHeader.size); // read failed ?? - CHECK_TRUE(!Read(&buf[0], sectionHeader.offset, buf.size()), false, LOG_TYPE_PRINTF, + CHECK_TRUE(Read(&buf[0], sectionHeader.offset, buf.size()), false, LOG_TYPE_PRINTF, "file format not correct. featureSectionDataOffset '0x%" PRIx64 "\n", sectionHeader.offset); if (IsFeatrureStringSection(feature)) { perfFileSections_.emplace_back( diff --git a/src/perf_file_writer.cpp b/src/perf_file_writer.cpp index 44e9bc4867870ad4f2472e536bb1ae2131346a24..8356729c68813f5e59053822e67aaff4e10c3865 100644 --- a/src/perf_file_writer.cpp +++ b/src/perf_file_writer.cpp @@ -127,14 +127,14 @@ bool PerfFileWriter::WriteRecord(const PerfEventRecord &record) HLOGV("write '%s', size %zu", record.GetName(), record.GetSize()); - CHECK_TRUE(record.GetSize() > RECORD_SIZE_LIMIT_SPE, false, 1, + CHECK_TRUE(record.GetSize() <= RECORD_SIZE_LIMIT_SPE, false, 1, "%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); - CHECK_TRUE(!record.GetBinary(buf), false, 0, ""); + CHECK_TRUE(record.GetBinary(buf), false, 0, ""); - CHECK_TRUE(!Write(buf.data(), record.GetSize()), false, 0, ""); + CHECK_TRUE(Write(buf.data(), record.GetSize()), false, 0, ""); dataSection_.size += record.GetSize(); ++recordCount_; @@ -192,7 +192,7 @@ bool PerfFileWriter::ReadRecords(ProcessRecordCB &callback) PerfEventRecord& record = PerfEventRecordFactory::GetPerfEventRecord( static_cast(header->type), data, defaultEventAttr_); // skip unknown record - CHECK_TRUE(record.GetName() == 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); @@ -213,7 +213,7 @@ bool PerfFileWriter::Read(void *buf, size_t len) HLOG_ASSERT(fp_ != nullptr); HLOG_ASSERT(len > 0); - CHECK_TRUE(fread(buf, len, 1, fp_) != 1, false, 1, "failed to read file"); + CHECK_TRUE(fread(buf, len, 1, fp_) == 1, false, 1, "failed to read file"); return true; } @@ -248,7 +248,7 @@ bool PerfFileWriter::Write(const void *buf, size_t len) #ifdef HIPERF_DEBUG_TIME const auto startTime = steady_clock::now(); #endif - CHECK_TRUE(len != 0u && fwrite(buf, len, 1, fp_) != 1, false, 1, "PerfFileWriter fwrite fail "); + CHECK_TRUE(len == 0u || fwrite(buf, len, 1, fp_) == 1, false, 1, "PerfFileWriter fwrite fail "); #ifdef HIPERF_DEBUG_TIME writeTimes_ += duration_cast(steady_clock::now() - startTime); #endif @@ -257,7 +257,7 @@ bool PerfFileWriter::Write(const void *buf, size_t len) bool PerfFileWriter::WriteAttrAndId(const std::vector &attrIds, bool isSpe) { - CHECK_TRUE(attrIds.empty(), false, 0, ""); + CHECK_TRUE(!attrIds.empty(), false, 0, ""); // Skip file header part. if (fp_ == nullptr) { @@ -268,17 +268,17 @@ bool PerfFileWriter::WriteAttrAndId(const std::vector &attrIds, bool // Write id section. uint64_t idSectionOffset; - CHECK_TRUE(!GetFilePos(idSectionOffset), false, 0, ""); + CHECK_TRUE(GetFilePos(idSectionOffset), false, 0, ""); HLOGD("attrIds %zu", attrIds.size()); for (auto &attrId : attrIds) { HLOGD(" attrIds ids %zu", attrId.ids.size()); - CHECK_TRUE(!Write(attrId.ids.data(), attrId.ids.size() * sizeof(uint64_t)), false, 0, ""); + CHECK_TRUE(Write(attrId.ids.data(), attrId.ids.size() * sizeof(uint64_t)), false, 0, ""); } // Write attr section. uint64_t attrSectionOffset; - CHECK_TRUE(!GetFilePos(attrSectionOffset), false, 0, ""); + CHECK_TRUE(GetFilePos(attrSectionOffset), false, 0, ""); for (auto &attrId : attrIds) { perf_file_attr fileAttr; fileAttr.attr = attrId.attr; @@ -402,7 +402,7 @@ bool PerfFileWriter::WriteAuxTraceEvent(bool isSpe) static bool LeftLessRight(const std::unique_ptr &l, const std::unique_ptr &r) { - CHECK_TRUE(l == nullptr || r == nullptr, false, 0, ""); + CHECK_TRUE(l != nullptr && r != nullptr, false, 0, ""); return l->featureId_ < r->featureId_; } // to write perf_file_header to file @@ -422,7 +422,7 @@ bool PerfFileWriter::WriteHeader() HLOGD("fseek return error "); return false; } - CHECK_TRUE(!Write(&header_, sizeof(header_)), false, 0, ""); + CHECK_TRUE(Write(&header_, sizeof(header_)), false, 0, ""); return true; } @@ -433,7 +433,7 @@ bool PerfFileWriter::WriteFeatureData() HLOGD("fseek SEEK_END return error "); return false; } - CHECK_TRUE((featureOffset = ftell(fp_)) == -1, false, 1, "ftell return error "); + CHECK_TRUE((featureOffset = ftell(fp_)) != -1, false, 1, "ftell return error "); for (size_t i = 0; i < sizeof(header_.features); i++) { if (header_.features[i] != 0) { @@ -457,10 +457,10 @@ bool PerfFileWriter::WriteFeatureData() i++; // write features heads - CHECK_TRUE(!Write(&featureSection->header, sizeof(featureSection->header)), false, 0, ""); + CHECK_TRUE(Write(&featureSection->header, sizeof(featureSection->header)), false, 0, ""); } long offset = ftell(fp_); - CHECK_TRUE(offset < 0, false, 0, ""); + CHECK_TRUE(offset >= 0, false, 0, ""); HLOGV("features data at file '0x%lx'", offset); i = 0; diff --git a/src/report.cpp b/src/report.cpp index 5c4f758d102357e3d0b6932d412a37a1b861fa74..e6f69482785046e28afdcaec0c073c6f1f156be2 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -397,7 +397,7 @@ bool Report::OutputStdCallFrame(int indent, const std::string_view &funcName, ui float num = 100.0; HLOGV("frame %f indent %d at %s", heat, indent, funcName.data()); - CHECK_TRUE(heat < option_.callStackHeatLimit_, false, 0, ""); // don't print this three anymore + CHECK_TRUE(heat >= option_.callStackHeatLimit_, false, 0, ""); // don't print this three anymore if (abs(heat - num) < ALMOST_ZERO) { fprintf(output_, "%*s", indent, " "); @@ -450,7 +450,7 @@ void Report::OutputStdCallFrames(int indent, const ReportItemCallFrame &callFram */ // this is the first call frame // this tree will skipped. - CHECK_TRUE(!OutputStdCallFrame(indent, callFrame.func_, callFrame.eventCount_, totalEventCount), + CHECK_TRUE(OutputStdCallFrame(indent, callFrame.func_, callFrame.eventCount_, totalEventCount), NO_RETVAL, 0, ""); // print it self diff --git a/src/report_json_file.cpp b/src/report_json_file.cpp index ba9b31320baeb095f4ed90838308069ca181412e..11f47e9756f4dfedc563559450bc34b77116f3fd 100644 --- a/src/report_json_file.cpp +++ b/src/report_json_file.cpp @@ -219,7 +219,7 @@ void ReportJsonFile::UpdateReportCallStack(uint64_t id, pid_t pid, pid_t tid, ui { auto &config = GetConfig(id); std::set RepeatFunctionId; - CHECK_TRUE(frames.size() == 0, NO_RETVAL, 0, ""); // do nothing with no frame + CHECK_TRUE(frames.size() != 0, NO_RETVAL, 0, ""); // do nothing with no frame auto &process = GetOrCreateMapItem(config.processes_, pid); auto &thread = GetOrCreateMapItem(process.threads_, tid); auto it = frames.begin(); @@ -330,7 +330,7 @@ void ReportJsonFile::OutputJsonRuntimeInfo() bool ReportJsonFile::OutputJson(FILE *output) { - CHECK_TRUE(output == nullptr, false, 0, ""); + CHECK_TRUE(output != nullptr, false, 0, ""); output_ = output; if (fprintf(output, "{") < 0) { return false; diff --git a/src/ring_buffer.cpp b/src/ring_buffer.cpp index 67878e6d47ceaa00d0e93918808c718de692417a..c30cb001361e448d88791c314a28e572c102066d 100644 --- a/src/ring_buffer.cpp +++ b/src/ring_buffer.cpp @@ -91,7 +91,7 @@ void RingBuffer::EndWrite() uint8_t *RingBuffer::GetReadData() { - CHECK_TRUE(buf_ == nullptr || buf_.get() == nullptr, nullptr, 0, ""); + CHECK_TRUE(buf_ != nullptr && buf_.get() != nullptr, nullptr, 0, ""); size_t writeHead = head_.load(std::memory_order_acquire); size_t readHead = tail_.load(std::memory_order_relaxed); if (writeHead == readHead) { @@ -107,14 +107,14 @@ uint8_t *RingBuffer::GetReadData() if (writePos <= readPos) { // |<---data2--->writePos---readPos<---data1--->| if (buf_.get()[readPos] == MARGIN_BYTE) { - CHECK_TRUE(writePos == 0, nullptr, 0, ""); + CHECK_TRUE(writePos != 0, nullptr, 0, ""); readSize_ = (size_ - readPos); readPos = 0; } } // else |---readPos<---data--->writePos---| perf_event_header *header = reinterpret_cast(buf_.get() + readPos); - CHECK_TRUE(header == nullptr, nullptr, 0, ""); + CHECK_TRUE(header != nullptr, nullptr, 0, ""); if (header->type == PERF_RECORD_AUXTRACE) { struct PerfRecordAuxtraceData *auxtrace = reinterpret_cast(header + 1); diff --git a/src/spe_decoder.cpp b/src/spe_decoder.cpp index e650de5e70d119fc8663e0cddac3ad33010b1f8c..992709ac42fe353fe6f33b042dbb9699bc9515e7 100644 --- a/src/spe_decoder.cpp +++ b/src/spe_decoder.cpp @@ -57,7 +57,7 @@ static unsigned int SpePayloadLen(unsigned char hdr) static int SpeGetPayload(const unsigned char *buf, size_t len, unsigned char extHdr, struct SpePkt *packet) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); size_t payloadLen = SpePayloadLen(buf[extHdr]); if (len < 1 + extHdr + payloadLen) { return PERF_SPE_NEED_MORE_BYTES; @@ -77,7 +77,7 @@ static int SpeGetPayload(const unsigned char *buf, size_t len, static int SpeGetPad(struct SpePkt *packet) { - CHECK_TRUE(packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(packet != nullptr, -1, 1, "Invalid pointer!"); packet->type = PERF_SPE_PAD; return 1; } @@ -85,7 +85,7 @@ static int SpeGetPad(struct SpePkt *packet) static int SpeGetAlignment(const unsigned char *buf, size_t len, struct SpePkt *packet) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); unsigned int alignment = 1 << ((buf[0] & 0xf) + 1); if (len < alignment) @@ -97,7 +97,7 @@ static int SpeGetAlignment(const unsigned char *buf, size_t len, static int SpeGetEnd(struct SpePkt *packet) { - CHECK_TRUE(packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(packet != nullptr, -1, 1, "Invalid pointer!"); packet->type = PERF_SPE_END; return 1; } @@ -105,7 +105,7 @@ static int SpeGetEnd(struct SpePkt *packet) static int SpeGetTimestamp(const unsigned char *buf, size_t len, struct SpePkt *packet) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); packet->type = PERF_SPE_TIMESTAMP; return SpeGetPayload(buf, len, 0, packet); } @@ -113,7 +113,7 @@ static int SpeGetTimestamp(const unsigned char *buf, size_t len, static int SpeGetEvents(const unsigned char *buf, size_t len, struct SpePkt *packet) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); packet->type = PERF_SPE_EVENTS; packet->index = SpePayloadLen(buf[0]); return SpeGetPayload(buf, len, 0, packet); @@ -122,7 +122,7 @@ static int SpeGetEvents(const unsigned char *buf, size_t len, static int SpeGetDataSource(const unsigned char *buf, size_t len, struct SpePkt *packet) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); packet->type = PERF_SPE_DATA_SOURCE; return SpeGetPayload(buf, len, 0, packet); } @@ -130,7 +130,7 @@ static int SpeGetDataSource(const unsigned char *buf, size_t len, static int SpeGetContext(const unsigned char *buf, size_t len, struct SpePkt *packet) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); packet->type = PERF_SPE_CONTEXT; packet->index = PERF_SPE_CTX_PKT_HDR_INDEX(buf[0]); return SpeGetPayload(buf, len, 0, packet); @@ -139,7 +139,7 @@ static int SpeGetContext(const unsigned char *buf, size_t len, static int SpeGetOpType(const unsigned char *buf, size_t len, struct SpePkt *packet) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); packet->type = PERF_SPE_OP_TYPE; packet->index = PERF_SPE_OP_PKT_HDR_CLASS(buf[0]); return SpeGetPayload(buf, len, 0, packet); @@ -148,7 +148,7 @@ static int SpeGetOpType(const unsigned char *buf, size_t len, static int SpeGetCounter(const unsigned char *buf, size_t len, const unsigned char extHdr, struct SpePkt *packet) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); packet->type = PERF_SPE_COUNTER; if (extHdr) { packet->index = PERF_SPE_HDR_EXTENDED_INDEX(buf[0], buf[1]); @@ -162,7 +162,7 @@ static int SpeGetCounter(const unsigned char *buf, size_t len, static int SpeGetAddr(const unsigned char *buf, size_t len, const unsigned char extHdr, struct SpePkt *packet) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); packet->type = PERF_SPE_ADDRESS; if (extHdr) { packet->index = PERF_SPE_HDR_EXTENDED_INDEX(buf[0], buf[1]); @@ -176,7 +176,7 @@ static int SpeGetAddr(const unsigned char *buf, size_t len, static int SpeDoGetPacket(const unsigned char *buf, size_t len, struct SpePkt *packet) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); unsigned int hdr; unsigned char extHdr = 0; @@ -238,7 +238,7 @@ static int SpeDoGetPacket(const unsigned char *buf, size_t len, int SpeGetPacket(const unsigned char *buf, size_t len, struct SpePkt *packet) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); int ret = SpeDoGetPacket(buf, len, packet); /* put multiple consecutive PADs on the same line, up to * the fixed-width output format of 16 bytes per line. @@ -254,7 +254,7 @@ int SpeGetPacket(const unsigned char *buf, size_t len, static int SpePktOutString(int *err, char **bufPtr, size_t *bufLen, const char *fmt, ...) { - CHECK_TRUE(*bufPtr == nullptr || bufLen == nullptr || fmt == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(*bufPtr != nullptr && bufLen != nullptr && fmt != nullptr, -1, 1, "Invalid pointer!"); va_list args; int ret = 0; @@ -300,7 +300,7 @@ static int SpePktOutString(int *err, char **bufPtr, size_t *bufLen, static int SpePktDescEvent(const struct SpePkt *packet, char *buf, size_t bufLen) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); u64 payload = packet->payload; int err = 0; @@ -354,7 +354,7 @@ static int SpePktDescEvent(const struct SpePkt *packet, static int SpePktDescOpType(const struct SpePkt *packet, char *buf, size_t bufLen) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); u64 payload = packet->payload; int err = 0; @@ -450,7 +450,7 @@ static int SpePktDescOpType(const struct SpePkt *packet, static int SpePktDescAddr(const struct SpePkt *packet, char *buf, size_t bufLen) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); int ns; int el; int idx = packet->index; @@ -496,7 +496,7 @@ static int SpePktDescAddr(const struct SpePkt *packet, static int SpePktDesCont(const struct SpePkt *packet, char *buf, size_t bufLen) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); u64 payload = packet->payload; const std::string name = SpePktName(packet->type); int err = 0; @@ -524,7 +524,7 @@ static int SpePktDesCont(const struct SpePkt *packet, int SpePktDesc(const struct SpePkt *packet, char *buf, size_t bufLen) { - CHECK_TRUE(buf == nullptr || packet == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr && packet != nullptr, -1, 1, "Invalid pointer!"); int idx = packet->index; unsigned long long payload = packet->payload; const std::string name = SpePktName(packet->type); @@ -635,13 +635,13 @@ static u64 SpeCalcIp(int index, u64 payload) void SpeDecoderFree(struct SpeDecoder *decoder) { - CHECK_TRUE(decoder == nullptr, NO_RETVAL, 1, "Invalid pointer!"); + CHECK_TRUE(decoder != nullptr, NO_RETVAL, 1, "Invalid pointer!"); free(decoder); } static int SpeGetNextPacket(struct SpeDecoder *decoder) { - CHECK_TRUE(decoder == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(decoder != nullptr, -1, 1, "Invalid pointer!"); int ret = 1; do { @@ -671,7 +671,7 @@ static int SpeReadRecord(struct SpeDecoder *decoder) { u64 payload; u64 ip; - CHECK_TRUE(decoder == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(decoder != nullptr, -1, 1, "Invalid pointer!"); if (memset_s(&decoder->record, sizeof(decoder->record), 0, sizeof(decoder->record)) != EOK) { HLOGE("memset_s failed in SpeReadRecord."); return -1; @@ -798,13 +798,13 @@ static int SpeReadRecord(struct SpeDecoder *decoder) int SpeDecode(struct SpeDecoder *decoder) { - CHECK_TRUE(decoder == nullptr, -1, 1, "Invalid pointer!"); + CHECK_TRUE(decoder != nullptr, -1, 1, "Invalid pointer!"); return SpeReadRecord(decoder); } struct SpeDecoder *SpeDecoderDataNew(const unsigned char *speBuf, size_t speLen) { - CHECK_TRUE(speBuf == nullptr, nullptr, 1, "Invalid pointer!"); + CHECK_TRUE(speBuf != nullptr, nullptr, 1, "Invalid pointer!"); struct SpeDecoder *decoder; decoder = reinterpret_cast(malloc(sizeof(struct SpeDecoder))); @@ -825,7 +825,7 @@ struct SpeDecoder *SpeDecoderDataNew(const unsigned char *speBuf, size_t speLen) bool SpeDumpRawData(unsigned char *buf, size_t len, int indent, FILE *outputDump) { - CHECK_TRUE(buf == nullptr, false, 1, "Invalid pointer!"); + CHECK_TRUE(buf != nullptr, false, 1, "Invalid pointer!"); if (outputDump != nullptr) { g_outputDump = outputDump; } diff --git a/src/subcommand_dump.cpp b/src/subcommand_dump.cpp index f86fdc876ca4a19c2aa00113031746b3446a45e5..0dc0ce911a2fb36cd15e248fae232af738e2339b 100644 --- a/src/subcommand_dump.cpp +++ b/src/subcommand_dump.cpp @@ -405,7 +405,7 @@ void SubCommandDump::ExportUserStack(const PerfRecordSample &recordSample) recordSample.data_.tid, exportSampleIndex_); std::string resolvedPath = CanonicalizeSpecPath(userRegs.c_str()); FILE *userRegsFp = fopen(resolvedPath.c_str(), "wb"); - CHECK_TRUE(userRegsFp == nullptr, NO_RETVAL, 1, "open userRegs failed"); + CHECK_TRUE(userRegsFp != nullptr, NO_RETVAL, 1, "open userRegs failed"); std::unique_ptr fpUserRegs(userRegsFp, fclose); fwrite(recordSample.data_.user_regs, sizeof(u64), recordSample.data_.reg_nr, fpUserRegs.get()); @@ -415,7 +415,7 @@ void SubCommandDump::ExportUserStack(const PerfRecordSample &recordSample) recordSample.data_.tid, exportSampleIndex_); std::string resolvePath = CanonicalizeSpecPath(userData.c_str()); FILE *UserDataFp = fopen(resolvePath.c_str(), "wb"); - CHECK_TRUE(UserDataFp == nullptr, NO_RETVAL, 1, "open UserData failed"); + CHECK_TRUE(UserDataFp != nullptr, NO_RETVAL, 1, "open UserData failed"); std::unique_ptr fpUserData(UserDataFp, fclose); fwrite(recordSample.data_.stack_data, sizeof(u8), recordSample.data_.dyn_size, fpUserData.get()); @@ -437,7 +437,7 @@ void SubCommandDump::ExportUserData(PerfEventRecord& record) std::string resolvedPath = CanonicalizeSpecPath(userData.c_str()); std::unique_ptr fpUserData(fopen(resolvedPath.c_str(), "wb"), fclose); static std::vector buf(RECORD_SIZE_LIMIT); - CHECK_TRUE(!recordSample->GetBinary(buf), NO_RETVAL, 1, "export user sample data failed"); + CHECK_TRUE(recordSample->GetBinary(buf), NO_RETVAL, 1, "export user sample data failed"); fwrite(buf.data(), sizeof(u8), recordSample->GetSize(), fpUserData.get()); HLOGD("export user data index %d time %llu", exportSampleIndex_, recordSample->data_.time); @@ -461,7 +461,7 @@ void SubCommandDump::DumpDataPortion(int indent) { int recordCount = 0; auto recordcCallback = [&](PerfEventRecord& record) { - CHECK_TRUE(record.GetName() == 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 367d1acc80419e8d29353f1f2de0ba5b5954289c..dba94cfef127dce204da47c64f63adad32fa2b56 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -371,8 +371,8 @@ bool SubCommandRecord::GetOptions(std::vector &args) printf("-a option is conflict with --dedup_stack.\n"); return false; } - CHECK_TRUE(!Option::GetOptionTrackedCommand(args, trackedCommand_), false, 0, ""); - CHECK_TRUE(!args.empty(), false, LOG_TYPE_PRINTF, + CHECK_TRUE(Option::GetOptionTrackedCommand(args, trackedCommand_), false, 0, ""); + CHECK_TRUE(args.empty(), false, LOG_TYPE_PRINTF, "'%s' option usage error, please check usage.\n", VectorToString(args).c_str()); return true; } @@ -585,7 +585,7 @@ bool SubCommandRecord::ParseOption(std::vector &args) if (!GetOptions(args)) { return false; } - CHECK_TRUE(!args.empty(), false, LOG_TYPE_PRINTF, "unknown option %s\n", args.begin()->c_str()); + CHECK_TRUE(args.empty(), false, LOG_TYPE_PRINTF, "unknown option %s\n", args.begin()->c_str()); if (controlCmd_.empty()) { if (!CheckRestartOption(appPackage_, targetSystemWide_, restart_, selectPids_)) { return false; @@ -601,7 +601,7 @@ bool SubCommandRecord::CheckTargetProcessOptions() hasTarget = true; } if (!selectPids_.empty() || !selectTids_.empty()) { - CHECK_TRUE(hasTarget, false, LOG_TYPE_PRINTF, + CHECK_TRUE(!hasTarget, false, LOG_TYPE_PRINTF, "-p/-t %s options conflict, please check usage\n", VectorToString(selectPids_).c_str()); hasTarget = true; } @@ -630,7 +630,7 @@ bool SubCommandRecord::CheckTargetProcessOptions() return false; } if (controlCmd_ == CONTROL_CMD_PREPARE) { - CHECK_TRUE(!CheckRestartOption(appPackage_, targetSystemWide_, restart_, selectPids_), false, 0, ""); + CHECK_TRUE(CheckRestartOption(appPackage_, targetSystemWide_, restart_, selectPids_), false, 0, ""); } return CheckTargetPids(); } @@ -682,12 +682,12 @@ bool SubCommandRecord::CheckReportOption() bool SubCommandRecord::CheckBacktrackOption() { - CHECK_TRUE(!backtrack_, true, 0, ""); + CHECK_TRUE(backtrack_, true, 0, ""); if (controlCmd_.empty() && (clientPipeInput_ == -1)) { printf("--backtrack must be used with --control\n"); return false; } - CHECK_TRUE(clockId_.empty(), true, 0, ""); + CHECK_TRUE(!clockId_.empty(), true, 0, ""); if (GetClockId(clockId_) != CLOCK_BOOTTIME && GetClockId(clockId_) != CLOCK_MONOTONIC && GetClockId(clockId_) != CLOCK_MONOTONIC_RAW) { printf("--backtrack not support the clockid\n"); @@ -830,7 +830,7 @@ bool SubCommandRecord::SetPerfLimit(const std::string& file, int value, std::fun const std::string& param) { int oldValue = 0; - CHECK_TRUE(!ReadIntFromProcFile(file, oldValue), false, LOG_TYPE_PRINTF, "read %s fail.\n", file.c_str()); + CHECK_TRUE(ReadIntFromProcFile(file, oldValue), false, LOG_TYPE_PRINTF, "read %s fail.\n", file.c_str()); if (cmp(oldValue, value)) { HLOGI("cmp return true."); @@ -844,7 +844,7 @@ bool SubCommandRecord::SetPerfLimit(const std::string& file, int value, std::fun } } - CHECK_TRUE(!OHOS::system::SetParameter(param, std::to_string(value)), false, LOG_TYPE_PRINTF, + CHECK_TRUE(OHOS::system::SetParameter(param, std::to_string(value)), false, LOG_TYPE_PRINTF, "set parameter %s fail.\n", param.c_str()); isNeedSetPerfHarden_ = true; return true; @@ -861,7 +861,7 @@ bool SubCommandRecord::SetPerfMaxSampleRate() auto cmp = [](int oldValue, int newValue) { return oldValue == newValue; }; int frequency = frequency_ != 0 ? frequency_ : PerfEvents::DEFAULT_SAMPLE_FREQUNCY; int maxRate = 0; - CHECK_TRUE(!ReadIntFromProcFile(PERF_EVENT_MAX_SAMPLE_RATE, maxRate), false, LOG_TYPE_PRINTF, + CHECK_TRUE(ReadIntFromProcFile(PERF_EVENT_MAX_SAMPLE_RATE, maxRate), false, LOG_TYPE_PRINTF, "read %s fail.\n", PERF_EVENT_MAX_SAMPLE_RATE.c_str()); if (maxRate > frequency) { return true; @@ -887,11 +887,11 @@ bool SubCommandRecord::SetPerfHarden() std::string perfHarden = OHOS::system::GetParameter(PERF_DISABLE_PARAM, "1"); if (perfHarden == "1") { - CHECK_TRUE(!OHOS::system::SetParameter(PERF_DISABLE_PARAM, "0"), false, LOG_TYPE_PRINTF, + CHECK_TRUE(OHOS::system::SetParameter(PERF_DISABLE_PARAM, "0"), false, LOG_TYPE_PRINTF, "set parameter security.perf_harden to 0 fail."); } - CHECK_TRUE(!OHOS::system::SetParameter(PERF_DISABLE_PARAM, "1"), false, LOG_TYPE_PRINTF, + CHECK_TRUE(OHOS::system::SetParameter(PERF_DISABLE_PARAM, "1"), false, LOG_TYPE_PRINTF, "set parameter security.perf_harden to 1 fail."); return true; } @@ -902,7 +902,7 @@ bool SubCommandRecord::TraceOffCpu() int enable = -1; std::string node = SCHED_SWITCH; const std::string nodeDebug = SCHED_SWITCH_DEBUG; - CHECK_TRUE(!ReadIntFromProcFile(node.c_str(), enable) && !ReadIntFromProcFile(nodeDebug.c_str(), enable), + CHECK_TRUE(ReadIntFromProcFile(node.c_str(), enable) || ReadIntFromProcFile(nodeDebug.c_str(), enable), false, LOG_TYPE_PRINTF, "Cannot trace off CPU, event sched:sched_switch is not available (%s or %s)\n", node.c_str(), nodeDebug.c_str()); @@ -911,7 +911,7 @@ bool SubCommandRecord::TraceOffCpu() void SubCommandRecord::SetSavedCmdlinesSize() { - if (!ReadIntFromProcFile(SAVED_CMDLINES_SIZE, oldCmdlinesSize_)) { + if (ReadIntFromProcFile(SAVED_CMDLINES_SIZE, oldCmdlinesSize_)) { printf("Failed to read from %s.\n", SAVED_CMDLINES_SIZE.c_str()); } if (!WriteIntToProcFile(SAVED_CMDLINES_SIZE, cmdlinesSize_)) { @@ -921,7 +921,7 @@ void SubCommandRecord::SetSavedCmdlinesSize() void SubCommandRecord::RecoverSavedCmdlinesSize() { - CHECK_TRUE(oldCmdlinesSize_ == 0, NO_RETVAL, 0, ""); + CHECK_TRUE(oldCmdlinesSize_ != 0, NO_RETVAL, 0, ""); if (!WriteIntToProcFile(SAVED_CMDLINES_SIZE, oldCmdlinesSize_)) { printf("Failed to recover value of %s.\n", SAVED_CMDLINES_SIZE.c_str()); } @@ -985,16 +985,16 @@ bool SubCommandRecord::PreparePerfEvent() selectEvents_.push_back("hw-cpu-cycles"); } - CHECK_TRUE(!perfEvents_.AddEvents(selectEvents_), false, 1, "Fail to AddEvents events"); + CHECK_TRUE(perfEvents_.AddEvents(selectEvents_), false, 1, "Fail to AddEvents events"); for (auto &group : selectGroups_) { - CHECK_TRUE(!perfEvents_.AddEvents(group, true), false, 1, "Fail to AddEvents groups"); + CHECK_TRUE(perfEvents_.AddEvents(group, true), false, 1, "Fail to AddEvents groups"); } // cpu off add after default event (we need both sched_switch and user selected events) if (offCPU_) { - CHECK_TRUE(std::find(selectEvents_.begin(), selectEvents_.end(), "sched_switch") != selectEvents_.end(), + CHECK_TRUE(std::find(selectEvents_.begin(), selectEvents_.end(), "sched_switch") == selectEvents_.end(), false, LOG_TYPE_PRINTF, "--offcpu is not supported event sched_switch\n"); // insert a sched_switch event to trace offcpu event - CHECK_TRUE(!perfEvents_.AddOffCpuEvent(), false, 1, "Fail to AddEOffCpuvent"); + CHECK_TRUE(perfEvents_.AddOffCpuEvent(), false, 1, "Fail to AddEOffCpuvent"); } return true; @@ -1004,15 +1004,15 @@ bool SubCommandRecord::PrepareSysKernel() { SetHM(); SetSavedCmdlinesSize(); - CHECK_TRUE(!SetPerfMaxSampleRate(), false, 1, "Fail to call SetPerfMaxSampleRate(%d)", frequency_); + CHECK_TRUE(SetPerfMaxSampleRate(), false, 1, "Fail to call SetPerfMaxSampleRate(%d)", frequency_); - CHECK_TRUE(!SetPerfCpuMaxPercent(), false, 1, "Fail to set perf event cpu limit to %d\n", cpuPercent_); + CHECK_TRUE(SetPerfCpuMaxPercent(), false, 1, "Fail to set perf event cpu limit to %d\n", cpuPercent_); - CHECK_TRUE(!SetPerfEventMlock(), false, 1, "Fail to set perf event mlock limit\n"); + CHECK_TRUE(SetPerfEventMlock(), false, 1, "Fail to set perf event mlock limit\n"); - CHECK_TRUE(!SetPerfHarden(), false, 1, "Fail to set perf event harden\n"); + CHECK_TRUE(SetPerfHarden(), false, 1, "Fail to set perf event harden\n"); - CHECK_TRUE(offCPU_ && !TraceOffCpu(), false, 1, "Fail to TraceOffCpu"); + CHECK_TRUE(!offCPU_ || TraceOffCpu(), false, 1, "Fail to TraceOffCpu"); return true; } @@ -1069,8 +1069,8 @@ bool SubCommandRecord::PrepareVirtualRuntime() void SubCommandRecord::WriteCommEventBeforeSampling() { - CHECK_TRUE(restart_, NO_RETVAL, 0, ""); - CHECK_TRUE(backtrack_, NO_RETVAL, 0, ""); + CHECK_TRUE(!restart_, NO_RETVAL, 0, ""); + CHECK_TRUE(!backtrack_, NO_RETVAL, 0, ""); for (auto it = mapPids_.begin(); it != mapPids_.end(); ++it) { virtualRuntime_.GetThread(it->first, it->first); for (auto tid : it->second) { @@ -1213,7 +1213,7 @@ inline void SubCommandRecord::CreateClientThread() void SubCommandRecord::ClientCommandHandle() { using namespace HiperfClient; - CHECK_TRUE(!IsSamplingRunning(), NO_RETVAL, 0, ""); + CHECK_TRUE(IsSamplingRunning(), NO_RETVAL, 0, ""); // tell the caller if Exist ClientCommandResponse(true); InitControlCommandHandlerMap(); @@ -1275,7 +1275,7 @@ bool SubCommandRecord::ProcessControl() } HIPERF_HILOGI(MODULE_DEFAULT, "control cmd : %{public}s", controlCmd_.c_str()); if (controlCmd_ == CONTROL_CMD_PREPARE) { - CHECK_TRUE(!CreateFifoServer(), false, 0, ""); + CHECK_TRUE(CreateFifoServer(), false, 0, ""); return true; } @@ -1500,7 +1500,7 @@ HiperfError SubCommandRecord::OnSubCommand(std::vector& args) RETURN_IF(!PreparePerfEvent(), HiperfError::PREPARE_PERF_EVENT_FAIL); // prepar some attr before CreateInitRecordFile - CHECK_TRUE(!perfEvents_.PrepareTracking(), HiperfError::PREPARE_TACKING_FAIL, + CHECK_TRUE(perfEvents_.PrepareTracking(), HiperfError::PREPARE_TACKING_FAIL, LOG_TYPE_WITH_HILOG, "Fail to prepare tracking "); HIPERF_HILOGI(MODULE_DEFAULT, "SubCommandRecord perfEvents prepared"); @@ -1594,7 +1594,7 @@ void SubCommandRecord::RemoveVdsoTmpFile() bool SubCommandRecord::ProcessRecord(PerfEventRecord& record) { - CHECK_TRUE(record.GetName() == 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 @@ -1654,7 +1654,7 @@ bool SubCommandRecord::SaveRecord(const PerfEventRecord& record) #endif if (dataSizeLimit_ > 0u) { if (dataSizeLimit_ <= fileWriter_->GetDataSize()) { - CHECK_TRUE(isDataSizeLimitStop_, false, 0, ""); + CHECK_TRUE(!isDataSizeLimitStop_, false, 0, ""); printf("record size %" PRIu64 " is large than limit %" PRIu64 ". stop sampling.\n", fileWriter_->GetDataSize(), dataSizeLimit_); perfEvents_.StopTracking(); @@ -1843,7 +1843,7 @@ void SubCommandRecord::AddDevhostFeature() bool SubCommandRecord::AddFeatureRecordFile() { // VERSION - CHECK_TRUE(!AddCpuFeature(), false, 0, ""); + CHECK_TRUE(AddCpuFeature(), false, 0, ""); AddMemTotalFeature(); AddCommandLineFeature(); @@ -1871,9 +1871,9 @@ bool SubCommandRecord::CreateInitRecordFile(bool compressData) return false; } - CHECK_TRUE(!fileWriter_->WriteAttrAndId(perfEvents_.GetAttrWithId(), isSpe_), false, 0, ""); + CHECK_TRUE(fileWriter_->WriteAttrAndId(perfEvents_.GetAttrWithId(), isSpe_), false, 0, ""); - CHECK_TRUE(!AddFeatureRecordFile(), false, 0, ""); + CHECK_TRUE(AddFeatureRecordFile(), false, 0, ""); HLOGD("create new record file %s", outputFilename_.c_str()); return true; @@ -1926,7 +1926,7 @@ bool SubCommandRecord::PostProcessRecordFile() // lte FinishWriteRecordFile write matched only symbols delayUnwind_ = false; - CHECK_TRUE(!FinishWriteRecordFile(), false, 1, "Fail to finish record file %s", outputFilename_.c_str()); + CHECK_TRUE(FinishWriteRecordFile(), false, 1, "Fail to finish record file %s", outputFilename_.c_str()); remove(tempFileName.c_str()); } @@ -1960,7 +1960,7 @@ void SubCommandRecord::SymbolicHits() bool SubCommandRecord::CollectionSymbol(PerfEventRecord& record) { - CHECK_TRUE(record.GetName() == 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 @@ -1980,7 +1980,7 @@ bool SubCommandRecord::CollectionSymbol(PerfEventRecord& record) void SubCommandRecord::CollectSymbol(PerfRecordSample *sample) { - CHECK_TRUE(sample == nullptr, NO_RETVAL, 0, ""); + CHECK_TRUE(sample != nullptr, NO_RETVAL, 0, ""); perf_callchain_context context = sample->InKernel() ? PERF_CONTEXT_KERNEL : PERF_CONTEXT_USER; pid_t serverPid; @@ -2052,12 +2052,12 @@ bool SubCommandRecord::FinishWriteRecordFile() disableUnwind_ = true; #endif #if !HIDEBUG_SKIP_SAVE_SYMBOLS - CHECK_TRUE(!fileWriter_->AddSymbolsFeature(virtualRuntime_.GetSymbolsFiles()), + CHECK_TRUE(fileWriter_->AddSymbolsFeature(virtualRuntime_.GetSymbolsFiles()), false, 1, "Fail to AddSymbolsFeature"); #endif } #endif - CHECK_TRUE(dedupStack_ && !fileWriter_->AddUniStackTableFeature(virtualRuntime_.GetUniStackTable()), false, 0, ""); + CHECK_TRUE(!dedupStack_ || fileWriter_->AddUniStackTableFeature(virtualRuntime_.GetUniStackTable()), false, 0, ""); if (backtrack_) { virtualRuntime_.ClearSymbolCache(); @@ -2068,7 +2068,7 @@ bool SubCommandRecord::FinishWriteRecordFile() #endif } - CHECK_TRUE(!fileWriter_->Close(), false, 1, "Fail to close record file %s", outputFilename_.c_str()); + CHECK_TRUE(fileWriter_->Close(), false, 1, "Fail to close record file %s", outputFilename_.c_str()); #ifdef HIPERF_DEBUG_TIME saveFeatureTimes_ += duration_cast(steady_clock::now() - startTime); #endif diff --git a/src/subcommand_report.cpp b/src/subcommand_report.cpp index 325c872cb5d198e0dc8e59061890839bac3c3eed..4f29e253227c1370e02c7484804919d6421ebce4 100644 --- a/src/subcommand_report.cpp +++ b/src/subcommand_report.cpp @@ -364,7 +364,7 @@ void SubCommandReport::LoadEventDesc() { const PerfFileSection *featureSection = recordFileReader_->GetFeatureSection(FEATURE::EVENT_DESC); - CHECK_TRUE(featureSection == nullptr, NO_RETVAL, 1, "featureSection invalid"); + CHECK_TRUE(featureSection != nullptr, NO_RETVAL, 1, "featureSection invalid"); const PerfFileSectionEventDesc §ionEventdesc = *static_cast(featureSection); HLOGV("Event descriptions: %zu", sectionEventdesc.eventDesces_.size()); @@ -469,7 +469,7 @@ bool SubCommandReport::LoadPerfData() return false; } - CHECK_TRUE(!recordFileReader_->ReadFeatureSection(), false, LOG_TYPE_PRINTF, "record format error.\n"); + CHECK_TRUE(recordFileReader_->ReadFeatureSection(), false, LOG_TYPE_PRINTF, "record format error.\n"); if (jsonFormat_) { reportJsonFile_ = std::make_unique(recordFileReader_, GetReport().virtualRuntime_); @@ -606,12 +606,12 @@ HiperfError SubCommandReport::OnSubCommand(std::vector& args) // we are in diff mode index_ = SECOND; // load again with second file - CHECK_TRUE(!LoadPerfData(), HiperfError::LOAD_SECOND_PERF_DATA_FAIL, 0, ""); + CHECK_TRUE(LoadPerfData(), HiperfError::LOAD_SECOND_PERF_DATA_FAIL, 0, ""); // back to first index_ = FIRST; } printf("prepare report\n"); - CHECK_TRUE(!OutputReport(), HiperfError::OUTPUT_REPORT_FAIL, 1, "OutputReport failed"); + CHECK_TRUE(OutputReport(), HiperfError::OUTPUT_REPORT_FAIL, 1, "OutputReport failed"); #ifdef HIPERF_DEBUG_TIME printf("SymbolicRecordTimes: %0.3f ms\n", GetReport(FIRST).virtualRuntime_.symbolicRecordTimes_.count() / MS_DURATION); diff --git a/src/subcommand_stat.cpp b/src/subcommand_stat.cpp index 055e695d99a3b884fc022dcf1052d90c22c7117c..0e404bc5fbd07a456e6c368d486d94d8b1b4f244 100644 --- a/src/subcommand_stat.cpp +++ b/src/subcommand_stat.cpp @@ -294,7 +294,7 @@ void SubCommandStat::PrintPerValue(const std::unique_ptr void SubCommandStat::InitPerMap(const std::unique_ptr &newPerMap, const PerfEvents::Summary &summary, VirtualRuntime& virtualInstance) { - CHECK_TRUE(newPerMap == nullptr, NO_RETVAL, 0, ""); + CHECK_TRUE(newPerMap != nullptr, NO_RETVAL, 0, ""); newPerMap->cpu = summary.cpu; if (g_reportCpuFlag && !g_reportThreadFlag) { return; @@ -423,7 +423,7 @@ std::string SubCommandStat::GetCommentConfigName( const std::unique_ptr &countEvent, std::string eventName) { std::string commentConfigName = ""; - CHECK_TRUE(countEvent == nullptr || eventName.length() == 0, commentConfigName, 1, "countEvent is nullptr"); + CHECK_TRUE(countEvent != nullptr && eventName.length() != 0, commentConfigName, 1, "countEvent is nullptr"); if (countEvent->userOnly) { commentConfigName = eventName + ":u"; } else if (countEvent->kernelOnly) { @@ -436,7 +436,7 @@ std::string SubCommandStat::GetCommentConfigName( void SubCommandStat::MakeComments(const std::unique_ptr &reportSum, std::string &commentStr) { - CHECK_TRUE(reportSum == nullptr || reportSum->commentSum == 0, NO_RETVAL, 0, ""); + CHECK_TRUE(reportSum != nullptr && reportSum->commentSum != 0, NO_RETVAL, 0, ""); if (reportSum->configName == "sw-task-clock") { commentStr = StringPrintf("%lf cpus used", reportSum->commentSum); return; @@ -653,7 +653,7 @@ bool SubCommandStat::FindRunningTime( bool SubCommandStat::FindPercoreRunningTime(PerfEvents::Summary &summary, double &running_time_int_sec, double &main_scale) { - CHECK_TRUE(summary.eventCount == 0, false, 0, ""); + CHECK_TRUE(summary.eventCount != 0, false, 0, ""); running_time_int_sec = summary.eventCount / 1e9; if (summary.timeRunning < summary.timeEnabled && summary.timeRunning != 0) { main_scale = static_cast(summary.timeEnabled) / summary.timeRunning; diff --git a/src/symbols_file.cpp b/src/symbols_file.cpp index 5afa02a04f8d4a02625f2149a849e18acd6ff05c..b9b3e6a8fae81c66032e0c5617d3d2a3fffc53d9 100644 --- a/src/symbols_file.cpp +++ b/src/symbols_file.cpp @@ -210,7 +210,7 @@ public: const std::unordered_map GetPtLoads() override { - CHECK_TRUE(elfFile_ == nullptr, info_, 0, ""); + CHECK_TRUE(elfFile_ != nullptr, info_, 0, ""); return elfFile_->GetPtLoads(); } @@ -250,9 +250,9 @@ protected: } } - CHECK_TRUE(elfFile_ == nullptr, false, 1, "Failed to create elf file for %s.", elfPath.c_str()); + CHECK_TRUE(elfFile_ != nullptr, false, 1, "Failed to create elf file for %s.", elfPath.c_str()); - CHECK_TRUE(!elfFile_->IsValid(), false, 1, "parser elf file failed."); + CHECK_TRUE(elfFile_->IsValid(), false, 1, "parser elf file failed."); HLOGD("loaded elf %s", elfPath.c_str()); // update path for so in hap @@ -279,7 +279,7 @@ protected: ShdrInfo shinfo; if (elfFile_->GetSectionInfo(shinfo, ".eh_frame_hdr")) { auto mmapPtr = elfFile_->GetMmapPtr(); - CHECK_TRUE(mmapPtr == nullptr, false, 1, "mmapPtr should not be nullptr."); + CHECK_TRUE(mmapPtr != nullptr, false, 1, "mmapPtr should not be nullptr."); LoadEhFrameHDR(mmapPtr + shinfo.offset, shinfo.size, shinfo.offset); } #endif @@ -318,7 +318,7 @@ private: bool GetHDRSectionInfo(uint64_t &ehFrameHdrElfOffset, uint64_t &fdeTableElfOffset, uint64_t &fdeTableSize) override { - CHECK_TRUE(elfFile_ == nullptr, false, 1, "elfFile_ is nullptr"); + CHECK_TRUE(elfFile_ != nullptr, false, 1, "elfFile_ is nullptr"); ShdrInfo shinfo; if (!elfFile_->GetSectionInfo(shinfo, ".eh_frame_hdr")) { return false; @@ -359,7 +359,7 @@ private: bool LoadEhFrameHDR(const unsigned char *buffer, size_t bufferSize, uint64_t shdrOffset) { const eh_frame_hdr *ehFrameHdr = reinterpret_cast(buffer); - CHECK_TRUE(ehFrameHdr == nullptr, false, 0, ""); + CHECK_TRUE(ehFrameHdr != nullptr, false, 0, ""); const uint8_t *dataPtr = ehFrameHdr->encode_data; DwarfEncoding dwEhFramePtr(ehFrameHdr->eh_frame_ptr_enc, dataPtr); DwarfEncoding dwFdeCount(ehFrameHdr->fde_count_enc, dataPtr); @@ -379,7 +379,7 @@ private: HLOGD(" table_item_size: %zd", dwTable.GetSize() + dwTableValue.GetSize()); HLOGD(" table_offset_in_hdr: %zu", dwTable.GetData() - buffer); - CHECK_TRUE(version != 1, false, 1, "eh_frame_hdr version is invalid"); + CHECK_TRUE(version == 1, false, 1, "eh_frame_hdr version is invalid"); EhFrameHDRValid_ = true; ehFrameHDRElfOffset_ = shdrOffset; ehFrameHDRFdeCount_ = dwFdeCount.GetAppliedValue(); @@ -456,7 +456,7 @@ private: elfFile_ = elfFactory.Create(); } } - CHECK_TRUE(elfFile_ == nullptr, false, 1, "Failed to create elf file for %s.", elfPath.c_str()); + CHECK_TRUE(elfFile_ != nullptr, false, 1, "Failed to create elf file for %s.", elfPath.c_str()); HLOGD("loaded elf %s", elfPath.c_str()); if (!elfFile_->IsValid()) { HLOGD("parser elf file failed."); @@ -547,7 +547,7 @@ public: const auto eachFileStartTime = steady_clock::now(); #endif std::string kallsym; - CHECK_TRUE(!ReadFileToString(kallsymsPath, kallsym, KSYM_DEFAULT_SIZE) || kallsym.empty(), false, 1, + CHECK_TRUE(ReadFileToString(kallsymsPath, kallsym, KSYM_DEFAULT_SIZE) && !kallsym.empty(), false, 1, "%s load failed.", kallsymsPath.c_str()); #ifdef HIPERF_DEBUG_SYMBOLS_TIME // any way we finish the line scan @@ -659,7 +659,7 @@ public: } // getline end - CHECK_TRUE(!ParseKallsymsLine("/proc/kallsyms"), false, 0, ""); + CHECK_TRUE(ParseKallsymsLine("/proc/kallsyms"), false, 0, ""); if (hasChangeKptr) { if (!WriteStringToFile(KPTR_RESTRICT, oldKptrRestrict)) { @@ -752,7 +752,7 @@ public: procPath = "/proc/devhost/root/kallsyms"; } HLOGD("try read kernel thread symbol file %s in %s", filePath_.c_str(), procPath.c_str()); - CHECK_TRUE(access(procPath.c_str(), R_OK) != 0, false, LOG_TYPE_PRINTF, + CHECK_TRUE(access(procPath.c_str(), R_OK) == 0, false, LOG_TYPE_PRINTF, "kernel thread symbol file %s cannot be opened\n", filePath_.c_str()); bool hasChangeKptr = false; std::string oldKptrRestrict = ReadFileToString(KPTR_RESTRICT); @@ -765,7 +765,7 @@ public: } // getline end - CHECK_TRUE(!ParseKallsymsLine(procPath), false, 0, ""); + CHECK_TRUE(ParseKallsymsLine(procPath), false, 0, ""); if (hasChangeKptr) { if (!WriteStringToFile(KPTR_RESTRICT, oldKptrRestrict)) { @@ -952,13 +952,13 @@ public: } } - CHECK_TRUE(StringEndsWith(filePath_, ".hap") && map_->IsMapExec(), false, 1, + CHECK_TRUE(!StringEndsWith(filePath_, ".hap") || !map_->IsMapExec(), false, 1, "map is exec not abc file , the symbol file is:%s", map_->name.c_str()); if (StringEndsWith(filePath_, ".hap") || StringEndsWith(filePath_, ".hsp") || StringEndsWith(filePath_, ".hqf")) { dfxExtractor_ = std::make_unique(filePath_); - CHECK_TRUE(!dfxExtractor_->GetHapAbcInfo(loadOffSet_, abcDataPtr_, abcDataSize_), false, 1, + CHECK_TRUE(dfxExtractor_->GetHapAbcInfo(loadOffSet_, abcDataPtr_, abcDataSize_), false, 1, "failed to call GetHapAbcInfo, the symbol file is:%s", filePath_.c_str()); HLOGD("loadOffSet %u", (uint32_t)loadOffSet_); if (abcDataPtr_ != nullptr) { @@ -1007,7 +1007,7 @@ public: if (debugInfoLoaded_) { return true; } - CHECK_TRUE(!onRecording_, true, 0, ""); + CHECK_TRUE(onRecording_, true, 0, ""); if (!IsHapAbc() && map_->IsMapExec()) { ElfFileSymbols::LoadDebugInfo(map, ""); @@ -1024,7 +1024,7 @@ public: return false; } HLOGD("map ptr:%p, map name:%s", map.get(), map->name.c_str()); - CHECK_TRUE(symbolsLoaded_ || !onRecording_, true, 0, ""); + CHECK_TRUE(!symbolsLoaded_ && onRecording_, true, 0, ""); symbolsLoaded_ = true; if (!IsHapAbc() && map_->IsMapExec()) { ElfFileSymbols::LoadSymbols(map, ""); diff --git a/src/unique_stack_table.cpp b/src/unique_stack_table.cpp index 6a63768941407718fe1170515340f64882ab9832..0af247cb4ec8cc231c8490333ba3c3f26d6f17f5 100644 --- a/src/unique_stack_table.cpp +++ b/src/unique_stack_table.cpp @@ -42,7 +42,7 @@ bool UniqueStackTable::Init() bool UniqueStackTable::Resize() { - CHECK_TRUE(tableBuf_ == nullptr, 0, 1, "Hashtable not exist, fatal error!"); + CHECK_TRUE(tableBuf_ != nullptr, 0, 1, "Hashtable not exist, fatal error!"); uint32_t oldNumNodes = totalNodes_; HLOGI("Before resize, totalNodes_: %u, availableNodes_: %u, availableIndex_: %u hashStep_: %" PRIu64 "", @@ -131,9 +131,9 @@ uint64_t UniqueStackTable::PutIpsInTable(StackId *stackId, u64 *ips, u64 nr) continue; } prev = PutIpInSlot(pc, prev); - CHECK_TRUE(prev == 0, 0, 0, ""); + CHECK_TRUE(prev != 0, 0, 0, ""); } - CHECK_TRUE(stackId == nullptr, 0, 0, ""); + CHECK_TRUE(stackId != nullptr, 0, 0, ""); stackId->section.id = prev; stackId->section.nr = nr; return prev; @@ -141,7 +141,7 @@ uint64_t UniqueStackTable::PutIpsInTable(StackId *stackId, u64 *ips, u64 nr) size_t UniqueStackTable::GetWriteSize() { - CHECK_TRUE(tableBuf_ == nullptr, 0, 1, "Hashtable not exist, fatal error!"); + CHECK_TRUE(tableBuf_ != nullptr, 0, 1, "Hashtable not exist, fatal error!"); size_t size = 0; size += sizeof(pid_); size += sizeof(tableSize_); @@ -156,14 +156,14 @@ Node* UniqueStackTable::GetFrame(uint64_t stackId) { Node *tableHead = reinterpret_cast(tableBuf_.get()); // should not occur - CHECK_TRUE(stackId >= totalNodes_, nullptr, 1, "Failed to find frame by index: %" PRIu64 "", stackId); + CHECK_TRUE(stackId < totalNodes_, nullptr, 1, "Failed to find frame by index: %" PRIu64 "", stackId); return reinterpret_cast(&tableHead[stackId]); } bool UniqueStackTable::GetIpsByStackId(StackId stackId, std::vector& ips) { - CHECK_TRUE(tableBuf_ == nullptr, false, 1, "Hashtable not exist, failed to find frame!"); + CHECK_TRUE(tableBuf_ != nullptr, false, 1, "Hashtable not exist, failed to find frame!"); uint64_t nr = stackId.section.nr; uint64_t tailIdx = stackId.section.id; @@ -182,7 +182,7 @@ bool UniqueStackTable::GetIpsByStackId(StackId stackId, std::vector& ips) bool UniqueStackTable::ImportNode(uint32_t index, const Node& node) { - CHECK_TRUE(index >= tableSize_, false, 0, ""); + CHECK_TRUE(index < tableSize_, false, 0, ""); Node *tableHead = reinterpret_cast(tableBuf_.get()); tableHead[index].value = node.value; return true; diff --git a/src/utilities.cpp b/src/utilities.cpp index a08fd3de69d4393c392105fd47c2baf153a2f871..57cf3b870872c50f2e28f70ae9dd0fb349410a81 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -175,7 +175,7 @@ bool StdoutRecord::Start() // we save the stdout stdoutFile_ = OHOS::UniqueFd(dup(STDOUT_FILENO)); - CHECK_TRUE(stdoutFile_ == -1, false, 1, "std dup failed"); + CHECK_TRUE(stdoutFile_ != -1, false, 1, "std dup failed"); // setup temp file as stdout if (dup2(fileno(recordFile_), STDOUT_FILENO) != -1) { @@ -235,7 +235,7 @@ bool IsHexDigits(const std::string &str) if (prefix.compare(0, prefix.size(), effectStr.substr(0, prefix.size())) == 0) { effectStr = effectStr.substr(prefix.size(), effectStr.size() - prefix.size()); } - CHECK_TRUE(effectStr.empty(), false, 0, ""); + CHECK_TRUE(!effectStr.empty(), false, 0, ""); std::size_t start {0}; for (; start < effectStr.size(); ++start) { if (effectStr[start] == '0') { @@ -385,7 +385,7 @@ bool StringToUint64(const std::string &str, uint64_t &val) bool ReadIntFromProcFile(const std::string &path, int &value) { std::string s = ReadFileToString(path); - CHECK_TRUE(s.empty(), false, 0, ""); + CHECK_TRUE(!s.empty(), false, 0, ""); if (!IscontainDigits(s)) { return false; } @@ -499,9 +499,9 @@ std::vector GetEntriesInDir(const std::string &basePath) { std::vector result; std::string resolvedPath = CanonicalizeSpecPath(basePath.c_str()); - CHECK_TRUE(resolvedPath.empty(), result, 0, ""); + CHECK_TRUE(!resolvedPath.empty(), result, 0, ""); DIR *dir = opendir(resolvedPath.c_str()); - CHECK_TRUE(dir == nullptr, result, 0, ""); + CHECK_TRUE(dir != nullptr, result, 0, ""); dirent *entry; while ((entry = readdir(dir)) != nullptr) { if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { @@ -616,7 +616,7 @@ bool StringEndsWith(const std::string &string, const std::string &with) bool HexDump(const void *buf, size_t size, size_t maxSize) { - CHECK_TRUE(buf == nullptr, false, 0, ""); + CHECK_TRUE(buf != nullptr, false, 0, ""); const unsigned char *byteBuf = static_cast(buf); const size_t dumpByteEachLine = 8; size_t outputBytes = 0; @@ -663,7 +663,7 @@ bool IsRestarted(const std::string &appPackage) std::set_intersection(oldPids.begin(), oldPids.end(), newPids.begin(), newPids.end(), std::back_insert_iterator(intersection)); // app names are same, no intersection, means app restarted - CHECK_TRUE(intersection.empty(), true, 0, ""); + CHECK_TRUE(!intersection.empty(), true, 0, ""); intersection.clear(); newPids.clear(); std::this_thread::sleep_for(milliseconds(CHECK_FREQUENCY)); @@ -731,7 +731,7 @@ bool IsExistDebugByApp(const std::string& bundleName, std::string& err) bool IsExistDebugByPid(const std::vector &pids, std::string& err) { - CHECK_TRUE(pids.empty(), true, 1, "IsExistDebugByPid: pids is empty."); + CHECK_TRUE(!pids.empty(), true, 1, "IsExistDebugByPid: pids is empty."); for (auto pid : pids) { if (pid <= 0) { err = "Invalid -p value '" + std::to_string(pid) + "', the pid should be larger than 0"; @@ -800,7 +800,7 @@ bool LittleMemory() while (getline(file, line)) { if (line.find("MemTotal:") != std::string::npos) { int memSize = stoi(line.substr(line.find(":") + 1)); - CHECK_TRUE(memSize < (LITTLE_MEMORY_SIZE * MULTIPLE_SIZE * MULTIPLE_SIZE), true, 0, ""); + CHECK_TRUE(memSize >= (LITTLE_MEMORY_SIZE * MULTIPLE_SIZE * MULTIPLE_SIZE), true, 0, ""); } } return false; @@ -814,7 +814,7 @@ bool IsBeta() return true; } // default release when usertype param is invalid - CHECK_TRUE(userTypeRsp.empty(), true, 1, "GetUserType is empty [%s]", userTypeRsp.c_str()); + CHECK_TRUE(!userTypeRsp.empty(), true, 1, "GetUserType is empty [%s]", userTypeRsp.c_str()); return false; } @@ -823,7 +823,7 @@ bool IsAllowProfilingUid() #if (defined(is_linux) && is_linux) || (defined(is_ohos) && is_ohos) static unsigned int curUid = getuid(); HLOGD("curUid is %d\n", curUid); - CHECK_TRUE(ALLOW_UIDS.find(curUid) != ALLOW_UIDS.end(), true, 0, ""); + CHECK_TRUE(ALLOW_UIDS.find(curUid) == ALLOW_UIDS.end(), true, 0, ""); return false; #else return false; diff --git a/src/virtual_runtime.cpp b/src/virtual_runtime.cpp index e2be7139785d1cc7697687599d11ff79c50b9c34..055438c4dd05a0a69571cd4a28bf5801d75f360c 100644 --- a/src/virtual_runtime.cpp +++ b/src/virtual_runtime.cpp @@ -193,11 +193,11 @@ bool VirtualRuntime::UpdateHapSymbols(std::shared_ptr map) HLOGV("hap name:%s", map->name.c_str()); // found it by name auto symbolsFile = SymbolsFile::CreateSymbolsFile(map->name); - CHECK_TRUE(symbolsFile == nullptr, false, 1, + CHECK_TRUE(symbolsFile != nullptr, false, 1, "Failed to load CreateSymbolsFile for exec section in hap(%s)", map->name.c_str()); symbolsFile->SetMapsInfo(map); // update maps name if load debuginfo successfully - CHECK_TRUE(!symbolsFile->LoadDebugInfo(map), false, 1, + CHECK_TRUE(symbolsFile->LoadDebugInfo(map), false, 1, "Failed to load debuginfo for exec section in hap(%s)", map->name.c_str()); if (!loadSymboleWhenNeeded_) { // todo misspelling @@ -366,7 +366,7 @@ void VirtualRuntime::UpdatekernelMap(uint64_t begin, uint64_t end, uint64_t offs void VirtualRuntime::DedupFromRecord(PerfRecordSample *recordSample) { - CHECK_TRUE(recordSample == nullptr, NO_RETVAL, 0, ""); + CHECK_TRUE(recordSample != nullptr, NO_RETVAL, 0, ""); u64 nr = recordSample->data_.nr; if (nr == 0) { collectSymbolCallBack_(recordSample); @@ -384,7 +384,7 @@ void VirtualRuntime::DedupFromRecord(PerfRecordSample *recordSample) table = std::make_shared(pid); processStackMap_[pid] = table; } - CHECK_TRUE(table == nullptr, NO_RETVAL, 0, ""); + CHECK_TRUE(table != nullptr, NO_RETVAL, 0, ""); while (table->PutIpsInTable(&stackId, ips, nr) == 0) { // try expand hashtable if collison can not resolved if (!table->Resize()) { @@ -510,7 +510,7 @@ void VirtualRuntime::SymbolicCallFrame(PerfRecordSample &recordSample, uint64_t bool VirtualRuntime::RecoverCallStack(PerfRecordSample &recordSample) { auto StackTable = processStackMap_.find(recordSample.data_.pid); - CHECK_TRUE(StackTable == processStackMap_.end(), false, 1, "not found %" PRIu32 " pid", recordSample.data_.pid); + CHECK_TRUE(StackTable != processStackMap_.end(), false, 1, "not found %" PRIu32 " pid", recordSample.data_.pid); recordSample.ips_.clear(); if (StackTable->second != nullptr) { StackTable->second->GetIpsByStackId(recordSample.stackId_, recordSample.ips_); @@ -733,7 +733,7 @@ bool VirtualRuntime::CheckValidSandBoxMmap(PerfRecordMmap2 &recordMmap2) if ((recordMmap2.data_.prot & PROT_EXEC) != 0) { // fake first segment, when second segment come. auto symFile = SymbolsFile::CreateSymbolsFile(SYMBOL_ELF_FILE, recordMmap2.data_.filename); - CHECK_TRUE(symFile == nullptr, false, 1, "CheckValidSandBoxMmap Failed to create symbolFile!"); + CHECK_TRUE(symFile != nullptr, false, 1, "CheckValidSandBoxMmap Failed to create symbolFile!"); std::shared_ptr curMap; if (strstr(recordMmap2.data_.filename, ".hap") != nullptr) { @@ -747,7 +747,7 @@ bool VirtualRuntime::CheckValidSandBoxMmap(PerfRecordMmap2 &recordMmap2) curMap->prevMap = prevMap; } - CHECK_TRUE(!symFile->LoadDebugInfo(curMap), false, 1, "CheckValidSandBoxMmap Failed to load debuginfo!"); + CHECK_TRUE(symFile->LoadDebugInfo(curMap), false, 1, "CheckValidSandBoxMmap Failed to load debuginfo!"); if (!loadSymboleWhenNeeded_) { symFile->LoadSymbols(curMap); @@ -822,7 +822,7 @@ void VirtualRuntime::UpdateFromRecord(PerfRecordMmap2 &recordMmap2) if (recordCallBack_) { if (NeedAdaptSandboxPath(recordMmap2.data_.filename, recordMmap2.data_.pid, recordMmap2.header_.size)) { FixHMBundleMmap(recordMmap2.data_.filename, recordMmap2.data_.pid, recordMmap2.header_.size); - CHECK_TRUE(!CheckValidSandBoxMmap(recordMmap2), NO_RETVAL, 0, ""); + CHECK_TRUE(CheckValidSandBoxMmap(recordMmap2), NO_RETVAL, 0, ""); } } auto map = UpdateThreadMaps(recordMmap2.data_.pid, recordMmap2.data_.tid, recordMmap2.data_.filename, @@ -843,7 +843,7 @@ void VirtualRuntime::UpdateFromRecord(PerfRecordAuxtrace &recordAuxTrace) #if defined(is_ohos) && is_ohos recordAuxTrace.DumpLog(__FUNCTION__); SpeDecoder *decoder = SpeDecoderDataNew(recordAuxTrace.rawData_, recordAuxTrace.data_.size); - CHECK_TRUE(decoder == nullptr, NO_RETVAL, 0, ""); + CHECK_TRUE(decoder != nullptr, NO_RETVAL, 0, ""); std::vector records; while (true) { int ret = SpeDecode(decoder); @@ -883,7 +883,7 @@ void VirtualRuntime::SymbolSpeRecord(PerfRecordAuxtrace &recordAuxTrace) #if defined(is_ohos) && is_ohos recordAuxTrace.DumpLog(__FUNCTION__); SpeDecoder *decoder = SpeDecoderDataNew(recordAuxTrace.rawData_, recordAuxTrace.data_.size); - CHECK_TRUE(decoder == nullptr, NO_RETVAL, 0, ""); + CHECK_TRUE(decoder != nullptr, NO_RETVAL, 0, ""); while (true) { int ret = SpeDecode(decoder); if (ret <= 0) { @@ -913,7 +913,7 @@ void VirtualRuntime::SetRecordMode(RecordCallBack recordCallBack) void VirtualRuntime::UpdateSymbols(std::shared_ptr map, pid_t pid) { - CHECK_TRUE(map == nullptr || map->symbolFileIndex != -1, NO_RETVAL, 0, ""); + CHECK_TRUE(map != nullptr && map->symbolFileIndex == -1, NO_RETVAL, 0, ""); HLOGD("try to find symbols for file: %s", map->name.c_str()); for (size_t i = 0; i < symbolsFiles_.size(); ++i) { if (symbolsFiles_[i]->filePath_ == map->name) { @@ -1024,7 +1024,7 @@ const DfxSymbol VirtualRuntime::GetKernelThreadSymbol(uint64_t ip, const Virtual } auto map = thread.GetMaps()[mapIndex]; - CHECK_TRUE(map == nullptr, vaddrSymbol, 0, ""); + CHECK_TRUE(map != nullptr, vaddrSymbol, 0, ""); HLOGM("found addr 0x%" PRIx64 " in kthread map 0x%" PRIx64 " - 0x%" PRIx64 " from %s", ip, map->begin, map->end, map->name.c_str()); // found symbols by file name @@ -1112,13 +1112,13 @@ bool VirtualRuntime::GetSymbolCache(uint64_t fileVaddr, DfxSymbol &symbol, const perf_callchain_context &context) { if (context == PERF_CONTEXT_MAX && kThreadSymbolCache_.count(fileVaddr)) { - CHECK_TRUE(kThreadSymbolCache_.find(symbol.fileVaddr_) == kThreadSymbolCache_.end(), false, 0, ""); + CHECK_TRUE(!(kThreadSymbolCache_.find(symbol.fileVaddr_) == kThreadSymbolCache_.end()), false, 0, ""); symbol = kThreadSymbolCache_[symbol.fileVaddr_]; symbol.hit_++; HLOGV("hit kernel thread cache 0x%" PRIx64 " %d", fileVaddr, symbol.hit_); return true; } else if (context != PERF_CONTEXT_USER && kernelSymbolCache_.count(fileVaddr)) { - CHECK_TRUE(kernelSymbolCache_.find(symbol.fileVaddr_) == kernelSymbolCache_.end(), false, 0, ""); + CHECK_TRUE(!(kernelSymbolCache_.find(symbol.fileVaddr_) == kernelSymbolCache_.end()), false, 0, ""); symbol = kernelSymbolCache_[symbol.fileVaddr_]; symbol.hit_++; HLOGV("hit kernel cache 0x%" PRIx64 " %d", fileVaddr, symbol.hit_); @@ -1184,7 +1184,7 @@ DfxSymbol VirtualRuntime::GetSymbol(uint64_t ip, pid_t pid, pid_t tid, const per bool VirtualRuntime::SetSymbolsPaths(const std::vector &symbolsPaths) { std::unique_ptr symbolsFile = SymbolsFile::CreateSymbolsFile(SYMBOL_UNKNOW_FILE); - CHECK_TRUE(symbolsFile == nullptr, false, 0, ""); + CHECK_TRUE(symbolsFile != nullptr, false, 0, ""); // we need check if the path is accessible bool accessible = symbolsFile->setSymbolsFilePath(symbolsPaths); if (accessible) { @@ -1278,7 +1278,7 @@ void VirtualRuntime::LoadVdso() std::string tempPath("/data/log/hiperflog/"); if (!IsDirectoryExists(tempPath)) { HIPERF_HILOGI(MODULE_DEFAULT, "%{public}s not exist.", tempPath.c_str()); - CHECK_TRUE(!CreateDirectory(tempPath, HIPERF_FILE_PERM_770), NO_RETVAL, + CHECK_TRUE(CreateDirectory(tempPath, HIPERF_FILE_PERM_770), NO_RETVAL, LOG_TYPE_WITH_HILOG, "Create hiperflog path failed"); } std::string tempFileName = tempPath + map->name;