From 3271a62a3320b57f294aad74ac99055035148d85 Mon Sep 17 00:00:00 2001 From: buzhenwang Date: Wed, 6 Aug 2025 19:35:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=8F=E6=84=9F=E4=BF=A1=E6=81=AF=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E6=8E=92=E6=9F=A5=20Signed-off-by:leiguangyu=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: buzhenwang --- include/option.h | 4 +- src/command.cpp | 12 +-- src/hiperf_libreport.cpp | 12 +-- src/option.cpp | 2 +- src/perf_events.cpp | 2 +- src/perf_file_writer.cpp | 15 ++- src/report_protobuf_file.cpp | 4 +- src/subcommand.cpp | 14 +-- src/subcommand_dump.cpp | 16 ++-- src/subcommand_help.cpp | 2 +- src/subcommand_record.cpp | 100 ++++++++------------ src/subcommand_report.cpp | 13 +-- src/subcommand_stat.cpp | 9 +- src/symbols_file.cpp | 2 +- src/utilities.cpp | 36 +++---- src/virtual_runtime.cpp | 1 - test/unittest/common/native/report_test.cpp | 14 --- 17 files changed, 108 insertions(+), 150 deletions(-) diff --git a/include/option.h b/include/option.h index 6537c76..6cbad74 100644 --- a/include/option.h +++ b/include/option.h @@ -119,8 +119,8 @@ bool GetOptionValue(argsVector &args, std::string optionName, T &value) return true; } else { // have value but convert failed. - printf("incorrect option value '%s' for option '%s'. View the usage with the --help option.\n", - (*it).c_str(), optionName.c_str()); + printf("incorrect option value for option '%s'. View the usage with the --help option.\n", + optionName.c_str()); return false; } } diff --git a/src/command.cpp b/src/command.cpp index a04ed14..cd7b06f 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -30,7 +30,7 @@ bool Command::DispatchCommands(std::vector arguments) fullArgument.append(arg); } CommandReporter reporter(fullArgument); - HLOGD("args:%s", VectorToString(arguments).c_str()); + HLOGD("args"); while (!arguments.empty()) { // we need found main command args first auto commandOption = Option::FindMainOption(arguments.front()); @@ -41,7 +41,7 @@ bool Command::DispatchCommands(std::vector arguments) arguments.erase(arguments.begin()); if (!commandOption->callBackFunction(arguments)) { - printf("unknown options: %s\nUse the help command to view help.\n", arguments.front().c_str()); + printf("unknown options\nUse the help command to view help.\n"); return false; } // goto next args @@ -57,7 +57,7 @@ bool Command::DispatchCommands(std::vector arguments) arguments.erase(arguments.begin()); // if we found the sub command , after it processed , we will exit - HLOGD("OnSubCommandOptions -> %s", subCommand->Name().c_str()); + HLOGD("OnSubCommandOptions"); if (subCommand->OnSubCommandOptions(arguments)) { subCommand->AddReportArgs(reporter); // if some help cmd ? @@ -65,9 +65,9 @@ bool Command::DispatchCommands(std::vector arguments) return true; } - HLOGD("OnSubCommand -> %s", subCommand->Name().c_str()); + HLOGD("OnSubCommand"); if (HiperfError err = subCommand->OnSubCommand(arguments); err != HiperfError::NO_ERR) { - printf("subcommand '%s' failed\n", subCommand->Name().c_str()); + printf("subcommand failed\n"); reporter.errorCode_ = err; return false; } else { @@ -81,7 +81,7 @@ bool Command::DispatchCommands(std::vector arguments) } } else { // we don't support this command - printf("unknown args: %s\n", arguments.front().c_str()); + printf("unknown args\n"); return false; } } diff --git a/src/hiperf_libreport.cpp b/src/hiperf_libreport.cpp index fa646d0..0bf7b28 100644 --- a/src/hiperf_libreport.cpp +++ b/src/hiperf_libreport.cpp @@ -46,7 +46,7 @@ int SetDebug(bool enable) int Report(const char *perfFile, const char *reportFile, const char *reportOptions) { std::unique_ptr report = std::make_unique(); - HLOGD("report the file %s to %s\n", perfFile, reportFile); + HLOGD("report the file perfFile to reportFile\n"); if (perfFile != nullptr && reportFile != nullptr) { std::vector args; args.emplace_back("-i"); @@ -76,7 +76,7 @@ int ReportJson(const char *perfFile, const char *reportFile) int ReportUnwindJson(const char *perfFile, const char *reportFile, const char *symbolsDir) { std::unique_ptr report = std::make_unique(); - HLOGD("report the file %s to json file %s symbols from %s\n", perfFile, reportFile, symbolsDir); + HLOGD("report the file perfFile to json file reportFile symbols from symbolsDir\n"); if (perfFile != nullptr && reportFile != nullptr) { std::vector args; args.emplace_back("-i"); @@ -100,13 +100,13 @@ static std::unique_ptr GetReader(const std::string &fileName) // check if file exist if (access(fileName.c_str(), F_OK) != 0) { // file not exists - printf("Can not access data file %s\n", fileName.c_str()); + printf("Can not access data file\n"); return nullptr; } auto reader = PerfFileReader::Instance(fileName); if (reader == nullptr) { - printf("%s format not correct\n", fileName.c_str()); + printf("fileName format not correct\n"); return nullptr; } else { return reader; @@ -115,7 +115,7 @@ static std::unique_ptr GetReader(const std::string &fileName) const char *ReportGetSymbolFiles(const char *perfFile) { - HLOGD("report the file %s for symbols \n", perfFile); + HLOGD("report the file for symbols \n"); static std::string result; // static for hold the c_str buffer result.clear(); if (perfFile == nullptr) { @@ -190,7 +190,7 @@ const char *ReportGetElfArch(const char *elfPath) int Dump(const char *fileName) { std::unique_ptr dump = std::make_unique(); - HLOGD("dump the file %s\n", fileName); + HLOGD("dump the file\n"); if (fileName != nullptr) { std::vector args; args.emplace_back(fileName); diff --git a/src/option.cpp b/src/option.cpp index ba1ad6d..8be869d 100644 --- a/src/option.cpp +++ b/src/option.cpp @@ -54,7 +54,7 @@ const MainOption *FindMainOption(const std::string &argName) std::vector::iterator FindOption(argsVector &args, const std::string &optionName) { - HLOGV("try find '%s' in args: %s", optionName.c_str(), VectorToString(args).c_str()); + HLOGV("try find '%s' optionName in args", optionName.c_str()); auto tmpit = args.begin(); std::string::size_type position; for (; tmpit != args.end(); tmpit++) { diff --git a/src/perf_events.cpp b/src/perf_events.cpp index e12f968..edd118c 100644 --- a/src/perf_events.cpp +++ b/src/perf_events.cpp @@ -798,7 +798,7 @@ bool PerfEvents::EnableTracking() trackedCommand_->Stop(); } std::string commandName = trackedCommand_->GetCommandName(); - printf("failed to execute command: %zu: %s\n", commandName.size(), commandName.c_str()); + printf("failed to execute command: %zu\n", commandName.size()); return false; } } else if (trackedCommand_->GetState() != TrackedCommand::State::COMMAND_STARTED) { diff --git a/src/perf_file_writer.cpp b/src/perf_file_writer.cpp index 2526896..a8e982a 100644 --- a/src/perf_file_writer.cpp +++ b/src/perf_file_writer.cpp @@ -32,7 +32,7 @@ PerfFileWriter::~PerfFileWriter() fclose(fp_); fp_ = nullptr; if (remove(fileName_.c_str()) != 0) { - HLOGE("fail to remove file(%s).", fileName_.c_str()); + HLOGE("fail to remove file."); } } } @@ -45,7 +45,7 @@ bool PerfFileWriter::Open(const std::string &fileName, bool compressData) if (remove(fileName.c_str()) != 0) { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); - printf("can't remove exist file(%s). %d:%s\n", fileName.c_str(), errno, + printf("can't remove exist file. %d:%s\n", errno, errInfo); return false; } @@ -55,7 +55,7 @@ bool PerfFileWriter::Open(const std::string &fileName, bool compressData) if (fp_ == nullptr) { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); - printf("can't create file(%s). %d:%s\n", fileName.c_str(), errno, errInfo); + printf("can't create file. %d:%s\n", errno, errInfo); return false; } @@ -98,20 +98,17 @@ bool PerfFileWriter::Close() if (remove(fileName_.c_str()) != 0) { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); - printf("can't remove file(%s). %d:%s\n", - fileName_.c_str(), errno, errInfo); + printf("can't remove file. %d:%s\n", errno, errInfo); } if (rename(gzName.c_str(), fileName_.c_str()) != 0) { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); - printf("can't rename file(%s) to (%s). %d:%s\n", gzName.c_str(), fileName_.c_str(), - errno, errInfo); + printf("can't rename file. %d:%s\n", errno, errInfo); } } else { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); - printf("failed to compress file(%s). %d:%s\n", fileName_.c_str(), errno, - errInfo); + printf("failed to compress file. %d:%s\n", errno, errInfo); } } diff --git a/src/report_protobuf_file.cpp b/src/report_protobuf_file.cpp index 496dd59..6212665 100644 --- a/src/report_protobuf_file.cpp +++ b/src/report_protobuf_file.cpp @@ -66,7 +66,7 @@ bool ReportProtobufFileWriter::Write(const void *buffer, int size) HLOGM("writed %d bytes", size); return true; } catch (std::ofstream::failure &writeErr) { - HLOGE("write file failed %s", fileName_.c_str()); + HLOGE("write file failed"); } } else { printf("no file open for write (request %d bytes).\n", size); @@ -227,7 +227,7 @@ int ReportProtobufFileReader::Read(void *buffer, int size) return protobufFileStream_->gcount(); } - HLOGW("read file %d bytes failed %s : %s\n", size, fileName_.c_str(), readErr.what()); + HLOGW("read file %d bytes failed : %s\n", size, readErr.what()); } } else { printf("no file open for read (request %d bytes).\n", size); diff --git a/src/subcommand.cpp b/src/subcommand.cpp index 53da549..c881161 100644 --- a/src/subcommand.cpp +++ b/src/subcommand.cpp @@ -39,7 +39,7 @@ bool SubCommand::OnSubCommandOptions(std::vector args) if (showHelp_) { if (!args.empty()) { - printf("unknown option '%s'\n", args.front().c_str()); + printf("unknown option\n"); return false; } if (OnPreSubCommand()) { @@ -51,9 +51,9 @@ bool SubCommand::OnSubCommandOptions(std::vector args) if (dumpOptions_) { DumpOptions(); } - HLOGD(" args left over: (%zu): %s", args.size(), VectorToString(args).c_str()); + HLOGD(" args left over: (%zu)", args.size()); if (!args.empty()) { - printf("unknown option '%s'\n", args.front().c_str()); + printf("unknown option\n"); return false; } } else { @@ -141,7 +141,7 @@ void SubCommand::ExcludeThreadsFromSelectTids(const std::vector &ex ++pos; } if (!hasExclude) { - printf("No thread named %s was found to exclude.\n", excludeName.c_str()); + printf("No thread named was found to exclude.\n"); } } } @@ -154,7 +154,7 @@ bool SubCommand::RegisterSubCommand(const std::string& cmdName, std::function>& SubCommand::GetSubCom SubCommand *SubCommand::FindSubCommand(std::string &cmdName) { - HLOGV("%s", cmdName.c_str()); + HLOGV("cmdName"); std::lock_guard lock(subCommandMutex_); auto found = subCommandFuncMap_.find(cmdName); if (found != subCommandFuncMap_.end()) { diff --git a/src/subcommand_dump.cpp b/src/subcommand_dump.cpp index 0dc0ce9..199b3b2 100644 --- a/src/subcommand_dump.cpp +++ b/src/subcommand_dump.cpp @@ -138,10 +138,10 @@ bool SubCommandDump::PrepareDumpOutput() std::string resolvedPath = CanonicalizeSpecPath(outputFilename_.c_str()); g_outputDump = fopen(resolvedPath.c_str(), "w"); if (g_outputDump == nullptr) { - printf("unable open file to '%s' because '%d'\n", outputFilename_.c_str(), errno); + printf("unable open file because '%d'\n", errno); return false; } - printf("dump result will save at '%s'\n", outputFilename_.c_str()); + printf("dump result will save\n"); return true; } @@ -168,14 +168,14 @@ HiperfError SubCommandDump::OnSubCommand(std::vector& args) #endif if (access(dumpFileName_.c_str(), F_OK) != 0) { - printf("Can not access data file %s\n", dumpFileName_.c_str()); + printf("Can not access data file\n"); return HiperfError::ACCESS_DATA_FILE_FAIL; } // only one file should created - HLOG_ASSERT_MESSAGE(reader_ == nullptr, " perf file reader for %s\n", dumpFileName_.c_str()); + HLOG_ASSERT_MESSAGE(reader_ == nullptr, " perf file reader\n"); reader_ = PerfFileReader::Instance(dumpFileName_); if (reader_ == nullptr) { - HLOGE("HiperfFileReader::Instance(%s) return null", dumpFileName_.c_str()); + HLOGE("HiperfFileReader::Instance return null"); return HiperfError::OPEN_DATA_FILE_FAIL; } @@ -187,7 +187,7 @@ HiperfError SubCommandDump::OnSubCommand(std::vector& args) if (!dumpSymbolsPaths_.empty()) { // user give us path , we enable unwind if (!vr_.SetSymbolsPaths(dumpSymbolsPaths_)) { - printf("Failed to set symbol path(%s)\n", VectorToString(dumpSymbolsPaths_).c_str()); + printf("Failed to set symbol path\n"); return HiperfError::SET_SYMBOLS_PATH_FAIL; } } @@ -213,7 +213,7 @@ HiperfError SubCommandDump::OnSubCommand(std::vector& args) bool SubCommandDump::DumpElfFile() { - printf("dump elf: '%s'\n", elfFileName_.c_str()); + printf("dump elf\n"); auto elf = SymbolsFile::CreateSymbolsFile(elfFileName_); if (!elf->LoadSymbols(nullptr, "")) { printf("load elf failed.\n"); @@ -226,7 +226,7 @@ bool SubCommandDump::DumpElfFile() #if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF bool SubCommandDump::DumpProtoFile() { - printf("dump protobuf file: '%s'\n", protobufDumpFileName_.c_str()); + printf("dump protobuf file\n"); protobufInputFileReader_ = std::make_unique(); if (!protobufInputFileReader_->Dump(protobufDumpFileName_)) { printf("load proto failed.\n"); diff --git a/src/subcommand_help.cpp b/src/subcommand_help.cpp index 16d7d02..4360077 100644 --- a/src/subcommand_help.cpp +++ b/src/subcommand_help.cpp @@ -65,7 +65,7 @@ bool SubCommandHelp::OnHelp(std::vector &args) args.clear(); printf("%s\n", command->Help().c_str()); } else { - printf("Unknown command: '%s'\n", args.front().c_str()); + printf("Unknown command\n"); return false; } } diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index f147db6..0ebcabe 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -130,18 +130,10 @@ void SubCommandRecord::DumpOptions() const printf(" selectCpus:\t%s\n", VectorToString(selectCpus_).c_str()); printf(" timeStopSec:\t%f sec\n", timeStopSec_); printf(" frequency:\t%d\n", frequency_); - printf(" selectEvents:\t%s\n", VectorToString(selectEvents_).c_str()); - int i = 0; - for (auto &group : selectGroups_) { - i++; - printf(" selectGroups:\t%2d:%s\n", i, VectorToString(group).c_str()); - } printf(" no_inherit:\t%s\n", noInherit_ ? "true" : "false"); printf(" selectPids:\t%s\n", VectorToString(selectPids_).c_str()); printf(" selectTids:\t%s\n", VectorToString(selectTids_).c_str()); printf(" excludeTids:\t%s\n", VectorToString(excludeTidArgs_).c_str()); - printf(" excludeThreads:\t%s\n", VectorToString(excludeThreadNameArgs_).c_str()); - printf(" excludeProcessName_:\t%s\n", VectorToString(excludeProcessNameArgs_).c_str()); printf(" kernelCallChain:\t%s\n", kernelCallChain_ ? "true" : "false"); printf(" callChainUserOnly_:\t%s\n", callChainUserOnly_ ? "true" : "false"); printf(" restart:\t%s\n", restart_ ? "true" : "false"); @@ -153,15 +145,11 @@ void SubCommandRecord::DumpOptions() const printf(" disableUnwind_:\t%d\n", disableUnwind_); printf(" disableCallstackExpend_:\t%d\n", disableCallstackExpend_); printf(" enableDebugInfoSymbolic:\t%d\n", enableDebugInfoSymbolic_); - printf(" symbolDir_:\t%s\n", VectorToString(symbolDir_).c_str()); - printf(" outputFilename_:\t%s\n", outputFilename_.c_str()); - printf(" appPackage_:\t%s\n", appPackage_.c_str()); printf(" checkAppMs_:\t%d\n", checkAppMs_); printf(" clockId_:\t%s\n", clockId_.c_str()); printf(" mmapPages_:\t%d\n", mmapPages_); printf(" dataLimit:\t%s\n", strLimit_.c_str()); printf(" callStack:\t%s\n", VectorToString(callStackType_).c_str()); - printf(" branchSampleTypes:\t%s\n", VectorToString(vecBranchFilters_).c_str()); printf(" trackedCommand:\t%s\n", VectorToString(trackedCommand_).c_str()); printf(" pipe_input:\t%d\n", clientPipeInput_); printf(" pipe_output:\t%d\n", clientPipeOutput_); @@ -627,7 +615,7 @@ bool SubCommandRecord::CheckTargetProcessOptions() } if (appPackage_ != "") { if (hasTarget) { - printf("--app %s options conflict, please check usage\n", appPackage_.c_str()); + printf("--app options conflict, please check usage\n"); return false; } hasTarget = true; @@ -743,18 +731,17 @@ bool SubCommandRecord::IsAppRestarted() HIPERF_HILOGI(MODULE_DEFAULT, "[CollectPidsByAppname] collect oldpids begin"); CollectPidsByAppname(oldPids, appPackage_); for (auto it = oldPids.begin(); it != oldPids.end(); it++) { - HIPERF_HILOGI(MODULE_DEFAULT, "[IsAppRestarted] get oldpids %{public}d for %{public}s", - *it, appPackage_.c_str()); + HIPERF_HILOGI(MODULE_DEFAULT, "[IsAppRestarted] get oldpids %{public}d for app", + *it); } HIPERF_HILOGI(MODULE_DEFAULT, "[CollectPidsByAppname] collect oldpids finish"); - std::string info = "please restart " + appPackage_ + " for profiling within 30 seconds\n"; + std::string info = "please restart app for profiling within 30 seconds\n"; MsgPrintAndTrans(true, info); do { HIPERF_HILOGI(MODULE_DEFAULT, "[CollectPidsByAppname] collect newPids begin"); CollectPidsByAppname(newPids, appPackage_); for (auto it = newPids.begin(); it != newPids.end(); it++) { - HIPERF_HILOGI(MODULE_DEFAULT, "[IsAppRestarted] get newPids %{public}d for %{public}s", - *it, appPackage_.c_str()); + HIPERF_HILOGI(MODULE_DEFAULT, "[IsAppRestarted] get newPids %{public}d for app", *it); } HIPERF_HILOGI(MODULE_DEFAULT, "[CollectPidsByAppname] collect newPids finish"); std::set_intersection(oldPids.begin(), oldPids.end(), @@ -765,7 +752,7 @@ bool SubCommandRecord::IsAppRestarted() newPids.clear(); std::this_thread::sleep_for(milliseconds(CHECK_FREQUENCY)); } while (steady_clock::now() < endTime && !g_callStop.load()); - std::string err = "app " + appPackage_ + " was not stopped within 30 seconds\n"; + std::string err = "app was not stopped within 30 seconds\n"; MsgPrintAndTrans(!g_callStop.load(), err); return false; } @@ -802,9 +789,9 @@ pid_t SubCommandRecord::GetPidFromAppPackage(const pid_t oldPid, const uint64_t std::string fileName {basePath + subDir + cmdline}; if (IsSameCommand(ReadFileToString(fileName), appPackage_)) { res = static_cast(std::stoul(subDir, nullptr)); - HLOGD("[GetAppPackagePid]: get appPid for %s is %d", appPackage_.c_str(), res); - HIPERF_HILOGD(MODULE_DEFAULT, "[GetAppPackagePid] get appPid %{public}d for app %{public}s", - res, appPackage_.c_str()); + HLOGD("[GetAppPackagePid]: get appPid for app is %d", res); + HIPERF_HILOGD(MODULE_DEFAULT, "[GetAppPackagePid] get appPid %{public}d for app", + res); return res; } } @@ -818,13 +805,13 @@ bool SubCommandRecord::IsAppRunning() if (!appPackage_.empty()) { pid_t appPid = GetPidFromAppPackage(-1, waitAppRunCheckTimeOut); if (appPid <= 0) { - std::string err = "app " + appPackage_ + " not running\n"; + std::string err = "app not running\n"; MsgPrintAndTrans(!g_callStop.load(), err); return false; } - HLOGD("[CheckAppIsRunning] get appPid %d for app %s", appPid, appPackage_.c_str()); - HIPERF_HILOGD(MODULE_DEFAULT, "[CheckAppIsRunning] get appPid %{public}d for app %{public}s", - appPid, appPackage_.c_str()); + HLOGD("[CheckAppIsRunning] get appPid %d for app", appPid); + HIPERF_HILOGD(MODULE_DEFAULT, "[CheckAppIsRunning] get appPid %{public}d for app", + appPid); selectPids_.push_back(appPid); } return true; @@ -865,13 +852,13 @@ bool SubCommandRecord::ParseCallStackOption(const std::vector &call return true; } else if (callStackType[0] == "fp") { if (callStackType.size() != 1) { - printf("Invalid -s value %s.\n", VectorToString(callStackType).c_str()); + printf("Invalid -s value.\n"); return false; } isCallStackFp_ = true; } else if (callStackType[0] == "dwarf") { if (callStackType.size() > MAX_DWARF_CALL_CHAIN) { - printf("Invalid -s value %s.\n", VectorToString(callStackType).c_str()); + printf("Invalid -s value.\n"); return false; } else if (callStackType.size() == MAX_DWARF_CALL_CHAIN) { char *endPtr = nullptr; @@ -879,32 +866,29 @@ bool SubCommandRecord::ParseCallStackOption(const std::vector &call unsigned long num = 0; num = std::strtoul(callStackType.at(1).c_str(), &endPtr, 10); // 10 : decimal scale if (endPtr == callStackType.at(1).c_str() || *endPtr != '\0' || errno > 0 || num > UINT_MAX) { - printf("Invalid -s value, dwarf stack size, '%s' is illegal.\n", - callStackType.at(1).c_str()); + printf("Invalid -s value, dwarf stack size, callStackType.at(1) is illegal.\n"); return false; } callStackDwarfSize_ = static_cast(num); if (callStackDwarfSize_ < MIN_SAMPLE_STACK_SIZE) { - printf("Invalid -s value, dwarf stack size, '%s' is too small.\n", - callStackType.at(1).c_str()); + printf("Invalid -s value, dwarf stack size, callStackType.at(1) is too small.\n"); return false; } if (callStackDwarfSize_ > MAX_SAMPLE_STACK_SIZE) { - printf("Invalid -s value, dwarf stack size, '%s' is bigger than max value %u.\n", - callStackType.at(1).c_str(), MAX_SAMPLE_STACK_SIZE); + printf("Invalid -s value, dwarf stack size, callStackType.at(1) is bigger than max value %u.\n", + MAX_SAMPLE_STACK_SIZE); return false; } if ((callStackDwarfSize_ & MASK_ALIGNED_8) != 0) { - printf("Invalid -s value, dwarf stack size, '%s' is not 8 byte aligned.\n", - callStackType.at(1).c_str()); + printf("Invalid -s value, dwarf stack size, callStackType.at(1) is not 8 byte aligned.\n"); return false; } } isCallStackDwarf_ = true; SymbolsFile::needParseJsFunc_ = true; // only in record and dwarf mode need to parse } else { - printf("Invalid -s value '%s'.\n", callStackType.at(0).c_str()); + printf("Invalid -s value callStackType.at(0).\n"); return false; } return true; @@ -918,7 +902,7 @@ bool SubCommandRecord::ParseBranchSampleType(const std::vector &vec if (type != 0) { branchSampleType_ |= type; } else { - printf("Invalid -j value '%s'\n", item.c_str()); + printf("Invalid -j value\n"); return false; } } @@ -938,8 +922,7 @@ bool SubCommandRecord::ParseControlCmd(const std::string cmd) return true; } - printf("Invalid --control %s option, command should be: prepare, start, pause, resume, output, stop.\n", - cmd.c_str()); + printf("Invalid --control option, command should be: prepare, start, pause, resume, output, stop.\n"); return false; } @@ -1077,7 +1060,7 @@ bool SubCommandRecord::PreparePerfEvent() perfEvents_.SetDwarfSampleStackSize(callStackDwarfSize_); } if (!perfEvents_.SetBranchSampleType(branchSampleType_)) { - printf("branch sample %s is not supported\n", VectorToString(vecBranchFilters_).c_str()); + printf("branch sample is not supported\n"); HLOGE("Fail to SetBranchSampleType %" PRIx64 "", branchSampleType_); HIPERF_HILOGE(MODULE_DEFAULT, "[PreparePerfEvent] Fail to SetBranchSampleType %{public}" PRIx64 "", branchSampleType_); @@ -1175,7 +1158,7 @@ bool SubCommandRecord::PrepareVirtualRuntime() virtualRuntime_.EnableDebugInfoSymbolic(enableDebugInfoSymbolic_); if (!symbolDir_.empty()) { if (!virtualRuntime_.SetSymbolsPaths(symbolDir_)) { - printf("Failed to set symbol path(%s)\n", VectorToString(symbolDir_).c_str()); + printf("Failed to set symbol path\n"); return false; } } @@ -1676,9 +1659,8 @@ HiperfError SubCommandRecord::OnSubCommand(std::vector& args) ChildResponseToMain(false); CloseClientThread(); } - HLOGE("Fail to create record file %s", outputFilename_.c_str()); - HIPERF_HILOGE(MODULE_DEFAULT, "[OnSubCommand] Fail to create record file %{public}s", - outputFilename_.c_str()); + HLOGE("Fail to create record file"); + HIPERF_HILOGE(MODULE_DEFAULT, "[OnSubCommand] Fail to create record file"); return HiperfError::CREATE_OUTPUT_FILE_FAIL; } HIPERF_HILOGI(MODULE_DEFAULT, "[OnSubCommand] CreateInitRecordFile finished"); @@ -1725,8 +1707,8 @@ HiperfError SubCommandRecord::OnSubCommand(std::vector& args) startSaveFileTimes_ = steady_clock::now(); if (!backtrack_) { if (!FinishWriteRecordFile()) { - HLOGE("Fail to finish record file %s", outputFilename_.c_str()); - HIPERF_HILOGE(MODULE_DEFAULT, "Fail to finish record file %{public}s", outputFilename_.c_str()); + HLOGE("Fail to finish record file"); + HIPERF_HILOGE(MODULE_DEFAULT, "Fail to finish record file"); return HiperfError::FINISH_WRITE_RECORD_FILE_FAIL; } else if (!PostProcessRecordFile()) { HLOGE("Fail to post process record file"); @@ -2081,7 +2063,7 @@ bool SubCommandRecord::CreateInitRecordFile(bool compressData) CHECK_TRUE(AddFeatureRecordFile(), false, 0, ""); - HLOGD("create new record file %s", outputFilename_.c_str()); + HLOGD("create new record file"); return true; } @@ -2103,14 +2085,14 @@ bool SubCommandRecord::PostProcessRecordFile() fileWriter_.reset(); if (!CreateInitRecordFile(compressData_)) { // create again - HLOGEP("Fail to open data file %s ", outputFilename_.c_str()); + HLOGEP("Fail to open data file"); return false; } // read temp file auto fileReader = PerfFileReader::Instance(tempFileName); if (fileReader == nullptr) { - HLOGEP("Fail to open data file %s ", tempFileName.c_str()); + HLOGEP("Fail to open data temp file"); return false; } @@ -2132,7 +2114,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"); remove(tempFileName.c_str()); } @@ -2282,7 +2264,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"); #ifdef HIPERF_DEBUG_TIME saveFeatureTimes_ += duration_cast(steady_clock::now() - startTime); #endif @@ -2399,21 +2381,21 @@ bool SubCommandRecord::OnlineReportData() if (!report_) { return true; } - HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s begin to report file %" HILOG_PUBLIC "s", - __FUNCTION__, outputFilename_.c_str()); + HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s begin to report file", + __FUNCTION__); bool ret = false; std::string tempFileName = outputFilename_ + ".tmp"; if (rename(outputFilename_.c_str(), tempFileName.c_str()) != 0) { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); - HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s can't rename file %" HILOG_PUBLIC "s" + HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s can't rename file" "errno:%" HILOG_PUBLIC "d , errInfo: %" HILOG_PUBLIC "s\n", - __FUNCTION__, outputFilename_.c_str(), errno, errInfo); + __FUNCTION__, errno, errInfo); return false; } std::unique_ptr reporter = std::make_unique(); - HLOGD("report the file %s to report file %s \n", tempFileName.c_str(), outputFilename_.c_str()); + HLOGD("report the file to report file\n"); std::vector args; args.emplace_back("-i"); args.emplace_back(tempFileName); @@ -2427,9 +2409,9 @@ bool SubCommandRecord::OnlineReportData() if (remove(tempFileName.c_str()) != 0) { char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); - HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s remove file failed %" HILOG_PUBLIC "s" + HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s remove file failed" "errno:%" HILOG_PUBLIC "d , errInfo: %" HILOG_PUBLIC "s\n", - __FUNCTION__, tempFileName.c_str(), errno, errInfo); + __FUNCTION__, errno, errInfo); } HIPERF_HILOGI(MODULE_DEFAULT, "%" HILOG_PUBLIC "s report result %" HILOG_PUBLIC "s", __FUNCTION__, ret ? "success" : "fail"); diff --git a/src/subcommand_report.cpp b/src/subcommand_report.cpp index 4f29e25..ce46004 100644 --- a/src/subcommand_report.cpp +++ b/src/subcommand_report.cpp @@ -115,9 +115,6 @@ bool SubCommandReport::ParseOption(std::vector &args) void SubCommandReport::DumpOptions() const { printf("DumpOptions:\n"); - printf(" recordFile_:\t%s\n", recordFile_[FIRST].c_str()); - printf(" recordFile_:\t%s\n", recordFile_[SECOND].c_str()); - printf(" reportFile_:\t%s\n", reportFile_.c_str()); printf(" sortKeys:\t%s\n", VectorToString(reportOption_.sortKeys_).c_str()); } bool SubCommandReport::VerifyDisplayOption() @@ -458,14 +455,14 @@ bool SubCommandReport::LoadPerfData() // check if file exist if (access(recordFile_[index_].c_str(), F_OK) != 0) { // file not exists - printf("Can not access data file %s\n", recordFile_[index_].c_str()); + printf("Can not access data file %d\n", index_); return false; } // try load the file recordFileReader_ = PerfFileReader::Instance(recordFile_[index_]); if (recordFileReader_ == nullptr) { - HLOGE("FileReader::Instance(%s) return null", recordFile_[index_].c_str()); + HLOGE("FileReader::Instance(%d) return null", index_); return false; } @@ -553,7 +550,7 @@ bool SubCommandReport::PrepareOutput() printf("Can not access data file %s\n", recordFile_[index_].c_str()); return false; } - printf("save to protobuf file: '%s'\n", reportFile_.c_str()); + printf("save to protobuf file\n"); protobufOutputFileWriter_ = std::make_unique(); protobufOutputFileWriter_->Create(reportFile_); #endif @@ -564,10 +561,10 @@ bool SubCommandReport::PrepareOutput() std::string resolvedPath = CanonicalizeSpecPath(reportFile_.c_str()); output_ = fopen(resolvedPath.c_str(), "w"); if (output_ == nullptr) { - printf("unable open file to '%s' because '%d'\n", reportFile_.c_str(), errno); + printf("unable open file because '%d'\n", errno); return false; } else { - printf("report will save at '%s'\n", reportFile_.c_str()); + printf("report will save\n"); } } else { output_ = stdout; diff --git a/src/subcommand_stat.cpp b/src/subcommand_stat.cpp index 24d920c..dbf8048 100644 --- a/src/subcommand_stat.cpp +++ b/src/subcommand_stat.cpp @@ -61,10 +61,7 @@ void SubCommandStat::DumpOptions() const printf(" selectCpus:\t%s\n", VectorToString(selectCpus_).c_str()); printf(" timeStopSec:\t%f sec\n", timeStopSec_); printf(" timeReportMs:\t%d ms\n", timeReportMs_); - printf(" selectEvents:\t%s\n", VectorToString(selectEvents_).c_str()); - printf(" selectGroups:\t%s\n", VectorToString(selectGroups_).c_str()); printf(" noCreateNew:\t%s\n", noCreateNew_ ? "true" : "false"); - printf(" appPackage:\t%s\n", appPackage_.c_str()); printf(" checkAppMs_:\t%d\n", checkAppMs_); printf(" selectPids:\t%s\n", VectorToString(selectPids_).c_str()); printf(" selectTids:\t%s\n", VectorToString(selectTids_).c_str()); @@ -769,7 +766,7 @@ bool SubCommandStat::CreateFifoServer() } close(fd); printf("%s control hiperf counting success.\n", restart_ ? "start" : "create"); - printf("stat result will saved in %s.\n", outputFilename_ .c_str()); + printf("stat result will saved.\n"); } return true; } @@ -1017,7 +1014,7 @@ bool SubCommandStat::ParseControlCmd(const std::string& cmd) return true; } - printf("Invalid --control %s option, command should be: prepare, start, stop.\n", cmd.c_str()); + printf("Invalid --control option, command should be: prepare, start, stop.\n"); return false; } @@ -1163,7 +1160,7 @@ bool SubCommandStat::CheckOutPutFile() std::string resolvedPath = CanonicalizeSpecPath(outputFilename_.c_str()); filePtr_ = fopen(resolvedPath.c_str(), "w"); if (filePtr_ == nullptr) { - printf("unable open file to '%s' because '%d'\n", outputFilename_.c_str(), errno); + printf("unable open file because '%d'\n", errno); return false; } return true; diff --git a/src/symbols_file.cpp b/src/symbols_file.cpp index 3b68cab..e3f153c 100644 --- a/src/symbols_file.cpp +++ b/src/symbols_file.cpp @@ -1469,7 +1469,7 @@ bool SymbolsFile::CheckPathReadable(const std::string &path) const #if defined(is_ohos) && is_ohos char errInfo[ERRINFOLEN] = { 0 }; strerror_r(errno, errInfo, ERRINFOLEN); - HLOGM("'%s' is unable read,errno: %d, errmsg: %s", path.c_str(), errno, errInfo); + HLOGM("path is unable read,errno: %d, errmsg: %s", errno, errInfo); #endif return false; } diff --git a/src/utilities.cpp b/src/utilities.cpp index 696b783..69cfc2a 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -48,35 +48,35 @@ std::string CanonicalizeSpecPath(const char* src) HLOGE("Error: CanonicalizeSpecPath failed"); return ""; } else if (strlen(src) + 1 >= PATH_MAX) { - HLOGE("Error: CanonicalizeSpecPath %s failed", src); + HLOGE("Error: CanonicalizeSpecPath failed"); return ""; } char resolvedPath[PATH_MAX] = { 0 }; #if defined(_WIN32) if (!_fullpath(resolvedPath, src, PATH_MAX)) { - HLOGE("Error: _fullpath %s failed", src); + HLOGE("Error: _fullpath failed"); return ""; } #else if (access(src, F_OK) == 0) { if (strstr(src, "/proc/") == src && strstr(src, "/data/storage") != nullptr) { // for sandbox if (strncpy_s(resolvedPath, sizeof(resolvedPath), src, strlen(src)) == -1) { - HLOGE("Error: strncpy_s %s failed", src); + HLOGE("Error: strncpy_s failed"); return ""; } } else if (realpath(src, resolvedPath) == nullptr) { - HLOGE("Error: realpath %s failed", src); + HLOGE("Error: realpath failed"); return ""; } } else { std::string fileName(src); if (fileName.find("..") == std::string::npos) { if (sprintf_s(resolvedPath, PATH_MAX, "%s", src) == -1) { - HLOGE("Error: sprintf_s %s failed", src); + HLOGE("Error: sprintf_s failed"); return ""; } } else { - HLOGE("Error: find .. %s failed", src); + HLOGE("Error: find .. failed"); return ""; } } @@ -363,7 +363,7 @@ bool IsStringToIntSuccess(const std::string &str, int &val) long num = 0; num = std::strtol(str.c_str(), &endPtr, 10); // 10 : decimal scale if (endPtr == str.c_str() || *endPtr != '\0' || errno != 0 || num > INT_MAX || num < INT_MIN) { - HLOGE("get int failed, str: %s", str.c_str()); + HLOGE("get int failed"); return false; } val = static_cast(num); @@ -376,7 +376,7 @@ bool StringToUint64(const std::string &str, uint64_t &val) errno = 0; uint64_t num = std::strtoull(str.c_str(), &endPtr, 10); // 10 : decimal scale if (endPtr == str.c_str() || *endPtr != '\0' || errno != 0 || num > ULLONG_MAX || str.c_str()[0] == '-') { - HIPERF_HILOGE(MODULE_DEFAULT, "get uint64 failed, str: %{public}s", str.c_str()); + HIPERF_HILOGE(MODULE_DEFAULT, "get uint64 failed"); return false; } val = num; @@ -412,14 +412,14 @@ bool CompressFile(const std::string &dataFile, const std::string &destFile) std::string resolvedPath = CanonicalizeSpecPath(dataFile.c_str()); FILE *fp = fopen(resolvedPath.c_str(), "rb"); if (fp == nullptr) { - HLOGE("Fail to open data file %s", dataFile.c_str()); + HLOGE("Fail to open data file"); perror("Fail to fopen(rb)"); return false; } std::unique_ptr fgz(gzopen(destFile.c_str(), "wb"), gzclose); if (fgz == nullptr) { - HLOGE("Fail to call gzopen(%s)", destFile.c_str()); + HLOGE("Fail to call gzopen"); fclose(fp); return false; } @@ -452,13 +452,13 @@ bool UncompressFile(const std::string &gzipFile, const std::string &dataFile) std::string resolvedPath = CanonicalizeSpecPath(dataFile.c_str()); FILE *fp = fopen(resolvedPath.c_str(), "wb"); if (fp == nullptr) { - HLOGE("Fail to open data file %s", dataFile.c_str()); + HLOGE("Fail to open data file"); perror("Fail to fopen(rb)"); return false; } std::unique_ptr fgz(gzopen(gzipFile.c_str(), "rb"), gzclose); if (fgz == nullptr) { - HLOGE("Fail to call gzopen(%s)", gzipFile.c_str()); + HLOGE("Fail to call gzopen"); fclose(fp); return false; } @@ -652,7 +652,7 @@ std::string BufferToHexString(const unsigned char buf[], size_t size) bool IsRestarted(const std::string &appPackage) { - printf("please restart %s for profiling within 30 seconds\n", appPackage.c_str()); + printf("please restart for profiling within 30 seconds\n"); std::set oldPids {}; std::set newPids {}; std::vector intersection; @@ -669,7 +669,7 @@ bool IsRestarted(const std::string &appPackage) newPids.clear(); std::this_thread::sleep_for(milliseconds(CHECK_FREQUENCY)); } while (steady_clock::now() < endTime); - printf("app %s was not stopped within 30 seconds\n", appPackage.c_str()); + printf("app was not stopped within 30 seconds\n"); return false; } @@ -690,7 +690,7 @@ pid_t GetAppPackagePid(const std::string &appPackage, const pid_t oldPid, const std::string fileName {basePath + subDir + cmdline}; if (IsSameCommand(ReadFileToString(fileName), appPackage)) { res = std::stoul(subDir, nullptr); - HLOGD("[GetAppPackagePid]: get appid for %s is %d", appPackage.c_str(), res); + HLOGD("[GetAppPackagePid]: get appid is %d", res); return res; } } @@ -705,10 +705,10 @@ bool CheckAppIsRunning (std::vector &selectPids, const std::string &appPa if (!appPackage.empty()) { pid_t appPid = GetAppPackagePid(appPackage, -1, checkAppMs, waitAppRunCheckTimeOut); if (appPid <= 0) { - printf("app %s not running\n", appPackage.c_str()); + printf("app not running\n"); return false; } - HLOGD("[CheckAppIsRunning] get appPid %d for app %s\n", appPid, appPackage.c_str()); + HLOGD("[CheckAppIsRunning] get appPid %d for app\n", appPid); selectPids.push_back(appPid); } return true; @@ -975,7 +975,7 @@ cJSON* ParseJson(const std::string &filePath) std::string resolvedPath = CanonicalizeSpecPath(filePath.c_str()); std::ifstream inFile(resolvedPath, std::ios::in); if (!inFile.is_open()) { - HLOGE("open file %s failed", filePath.c_str()); + HLOGE("open file failed"); return nullptr; } std::string fileContent((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); diff --git a/src/virtual_runtime.cpp b/src/virtual_runtime.cpp index d211288..70d8afe 100644 --- a/src/virtual_runtime.cpp +++ b/src/virtual_runtime.cpp @@ -932,7 +932,6 @@ void VirtualRuntime::UpdateSymbols(std::shared_ptr map, pid_t pid) * seg3 /data/storage/el1/bundle/entry.hap r--p ABC * seg4 /data/storage/el1/bundle/entry.hap r--p ABC * seg1 /system/app/SceneBoard/SceneBoard.hap r--p ABC - * seg2 /system/app/SceneBoard/SceneBoard.hap r--p ABC * seg3 /system/app/SceneBoard/SceneBoard.hap r--p ABC * segN .hap r--p .an/jit/etc * 1.map.name == symbolsFile.filePath_ diff --git a/test/unittest/common/native/report_test.cpp b/test/unittest/common/native/report_test.cpp index 6475bd0..33f4a43 100644 --- a/test/unittest/common/native/report_test.cpp +++ b/test/unittest/common/native/report_test.cpp @@ -829,20 +829,6 @@ HWTEST_F(ReportTest, PrepareConsole, TestSize.Level1) EXPECT_EQ(report_->consoleWidth_, report_->ConsoleDefaultWidth); } } - -HWTEST_F(ReportTest, OverConfigIndex, TestSize.Level1) -{ - pid_t pid = fork(); - ASSERT_NE(pid, -1); - - if (pid == 0) { - report_->configIdIndexMaps_.emplace(1000u, 1000u); - report_->GetConfigName(1000); - _exit(-2); - } else { - printf("exit.\n"); - } -} } // namespace HiPerf } // namespace Developtools } // namespace OHOS -- Gitee