From dbf1a8e89f2588aadf3e171493564cc982351ddb Mon Sep 17 00:00:00 2001 From: jiangwei Date: Mon, 9 Jun 2025 11:13:52 +0800 Subject: [PATCH] fix: clean code Signed-off-by: jiangwei --- src/perf_events.cpp | 17 ++++++++++------- src/perf_pipe.cpp | 4 ++-- src/subcommand_record.cpp | 10 +++++----- src/subcommand_stat.cpp | 4 ++-- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/perf_events.cpp b/src/perf_events.cpp index dca64b6..26eb70d 100644 --- a/src/perf_events.cpp +++ b/src/perf_events.cpp @@ -1880,11 +1880,13 @@ void PerfEvents::StatLoop() durationInSec = usedTimeMsTick.count(); auto lefTimeMsTick = duration_cast(endTime - thisTime); if (reportPtr_ == nullptr) { - printf("\nReport at %" PRId64 " ms (%" PRId64 " ms left):\n", - (uint64_t)usedTimeMsTick.count(), (uint64_t)lefTimeMsTick.count()); + printf("\nReport at %" PRIu64 " ms (%" PRIu64 " ms left):\n", + static_cast(usedTimeMsTick.count()), + static_cast(lefTimeMsTick.count())); } else { - fprintf(reportPtr_, "\nReport at %" PRId64 " ms (%" PRId64 " ms left):\n", - (uint64_t)usedTimeMsTick.count(), (uint64_t)lefTimeMsTick.count()); + fprintf(reportPtr_, "\nReport at %" PRIu64 " ms (%" PRIu64 " ms left):\n", + static_cast(usedTimeMsTick.count()), + static_cast(lefTimeMsTick.count())); } // end of comments nextReportTime += timeReport_; @@ -1900,9 +1902,10 @@ void PerfEvents::StatLoop() usedTimeMsTick = duration_cast(thisTime - startTime); durationInSec = usedTimeMsTick.count(); if (reportPtr_ == nullptr) { - printf("Timeout exit (total %" PRId64 " ms)\n", (uint64_t)usedTimeMsTick.count()); + printf("Timeout exit (total %" PRIu64 " ms)\n", static_cast(usedTimeMsTick.count())); } else { - fprintf(reportPtr_, "Timeout exit (total %" PRId64 " ms)\n", (uint64_t)usedTimeMsTick.count()); + fprintf(reportPtr_, "Timeout exit (total %" PRIu64 " ms)\n", + static_cast(usedTimeMsTick.count())); } if (trackedCommand_) { trackedCommand_->Stop(); @@ -1925,7 +1928,7 @@ void PerfEvents::StatLoop() if (!g_trackRunning) { // for user interrupt situation, print time statistic usedTimeMsTick = duration_cast(steady_clock::now() - startTime); - printf("User interrupt exit (total %" PRId64 " ms)\n", (uint64_t)usedTimeMsTick.count()); + printf("User interrupt exit (total %" PRIu64 " ms)\n", static_cast(usedTimeMsTick.count())); } if (timeReport_ == milliseconds::zero()) { diff --git a/src/perf_pipe.cpp b/src/perf_pipe.cpp index 3825c56..0b2d70b 100644 --- a/src/perf_pipe.cpp +++ b/src/perf_pipe.cpp @@ -110,8 +110,8 @@ bool PerfPipe::SendFifoAndWaitReply(const std::string &cmd, const std::chrono::m close(fdRead); return false; } - size_t size = write(fdWrite, cmd.c_str(), cmd.size()); - if (size != cmd.size()) { + ssize_t size = write(fdWrite, cmd.c_str(), cmd.size()); + if (size != static_cast(cmd.size())) { HLOGE("failed to write fifo file(%s) command(%s)", fifoFileC2S_.c_str(), cmd.c_str()); HIPERF_HILOGE(MODULE_DEFAULT, "failed to write fifo file(%{public}s) command(%{public}s).", fifoFileC2S_.c_str(), cmd.c_str()); diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index 7cf8e63..d1b9979 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -788,7 +788,7 @@ pid_t SubCommandRecord::GetPidFromAppPackage(const pid_t oldPid, const uint64_t } std::string fileName {basePath + subDir + cmdline}; if (IsSameCommand(ReadFileToString(fileName), appPackage_)) { - res = std::stoul(subDir, nullptr); + res = static_cast(std::stoul(subDir, nullptr)); HLOGD("[GetAppPackagePid]: get appid for %s is %d", appPackage_.c_str(), res); return res; } @@ -1203,8 +1203,8 @@ bool SubCommandRecord::ClientCommandResponse(const std::string& str) return false; } } - size_t size = write(clientPipeOutput_, str.c_str(), str.size()); - if (size != str.size()) { + ssize_t size = write(clientPipeOutput_, str.c_str(), str.size()); + if (size != static_cast(str.size())) { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); HLOGD("Server:%s -> %d : %zd %d:%s", str.c_str(), clientPipeOutput_, size, errno, errInfo); @@ -1223,8 +1223,8 @@ bool SubCommandRecord::ChildResponseToMain(bool response) bool SubCommandRecord::ChildResponseToMain(const std::string& str) { int tempFd = isHiperfClient_ ? clientPipeOutput_ : writeFd_; - size_t size = write(tempFd, str.c_str(), str.size()); - if (size != str.size()) { + ssize_t size = write(tempFd, str.c_str(), str.size()); + if (size != static_cast(str.size())) { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); HLOGE("write pipe failed. str:%s, size:%zd, errno:%d:%s", str.c_str(), size, errno, errInfo); diff --git a/src/subcommand_stat.cpp b/src/subcommand_stat.cpp index b91531e..ce00f4a 100644 --- a/src/subcommand_stat.cpp +++ b/src/subcommand_stat.cpp @@ -781,8 +781,8 @@ bool SubCommandStat::ClientCommandResponse(bool response) bool SubCommandStat::ClientCommandResponse(const std::string& str) { - size_t size = write(clientPipeOutput_, str.c_str(), str.size()); - if (size != str.size()) { + ssize_t size = write(clientPipeOutput_, str.c_str(), str.size()); + if (size != static_cast(str.size())) { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); HLOGD("Server:%s -> %d : %zd %d:%s", str.c_str(), clientPipeOutput_, size, errno, errInfo); -- Gitee