From 4bba8c7b1be9f792c246df004b8ec5c75db9cfc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Wed, 13 Aug 2025 14:00:06 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- host/smartperf/client/client_command/smartperf_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/host/smartperf/client/client_command/smartperf_main.cpp b/host/smartperf/client/client_command/smartperf_main.cpp index f2ccb73da..c1b7f1072 100644 --- a/host/smartperf/client/client_command/smartperf_main.cpp +++ b/host/smartperf/client/client_command/smartperf_main.cpp @@ -95,8 +95,8 @@ static bool g_checkCmdParam(std::vector &argv, std::string &errorIn ) { keys.insert(argv[1].substr(1).c_str()); } - for (auto& a : OHOS::SmartPerf::COMMAND_MAP) { - keys.insert(a.first.substr(1)); // No prefix required '-' + for (auto& a : OHOS::SmartPerf::COMMAND_MAP_REVERSE) { + keys.insert(a.second.substr(1)); // No prefix required '-' } /* ************The command line for the following parameters is not implemented****************** */ -- Gitee From dfdd59a090e04b5467b61eb5cb279d616c8e40d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Wed, 13 Aug 2025 16:01:38 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- .../client/client_command/include/common.h | 21 +++++++++++++++++++ .../include/smartperf_command.h | 2 -- .../client/client_command/smartperf_main.cpp | 4 ++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/host/smartperf/client/client_command/include/common.h b/host/smartperf/client/client_command/include/common.h index 6e6e8d081..0b966f5fe 100644 --- a/host/smartperf/client/client_command/include/common.h +++ b/host/smartperf/client/client_command/include/common.h @@ -222,6 +222,27 @@ const std::unordered_map COMMAND_MAP_REVERSE = { { CommandType::CT_HCI, std::string("-HCI") }, }; +const std::unordered_map COMMAND_SHELL_MAP = { + { std::string("-N"), CommandType::CT_N }, + { std::string("-PKG"), CommandType::CT_PKG }, + { std::string("-PID"), CommandType::CT_PID }, + { std::string("-threads"), CommandType::CT_THREADS }, + { std::string("-c"), CommandType::CT_C }, + { std::string("-ci"), CommandType::CT_CI }, + { std::string("-g"), CommandType::CT_G }, + { std::string("-f"), CommandType::CT_F }, + { std::string("-t"), CommandType::CT_T }, + { std::string("-p"), CommandType::CT_P }, + { std::string("-print"), CommandType::CT_PRINT }, + { std::string("-r"), CommandType::CT_R }, + { std::string("-snapshot"), CommandType::CT_SNAPSHOT }, + { std::string("-net"), CommandType::CT_NET }, + { std::string("-VIEW"), CommandType::CT_VIEW }, + { std::string("-OUT"), CommandType::CT_OUT }, + { std::string("-d"), CommandType::CT_D }, + { std::string("-fl"), CommandType::CT_FL }, + { std::string("-ftl"), CommandType::CT_FTL }, +}; const std::unordered_map COMMAND_HELP_MAP = { { CommandHelp::HELP, std::string("--help") }, diff --git a/host/smartperf/client/client_command/include/smartperf_command.h b/host/smartperf/client/client_command/include/smartperf_command.h index 6e0f06850..c1bf2168a 100644 --- a/host/smartperf/client/client_command/include/smartperf_command.h +++ b/host/smartperf/client/client_command/include/smartperf_command.h @@ -38,8 +38,6 @@ public: " -PID set process pid, must add, for example: -PID 3568 \n" " -threads get threads, must add -PID or -PKG for example: \n" "\t\t -threads -PID 3568 or -threads -PKG ohos.samples.ecg \n" - " -fds get file descriptor, must add -PID or -PKG for example: \n" - "\t\t -fds -PID 3568 or -fds -PKG ohos.samples.ecg \n" " -c get device CPU frequency and CPU usage, process CPU usage and CPU load .. \n" " -ci get cpu instructions and cycles \n" " -g get device GPU frequency and GPU load \n" diff --git a/host/smartperf/client/client_command/smartperf_main.cpp b/host/smartperf/client/client_command/smartperf_main.cpp index c1b7f1072..72bb62906 100644 --- a/host/smartperf/client/client_command/smartperf_main.cpp +++ b/host/smartperf/client/client_command/smartperf_main.cpp @@ -95,8 +95,8 @@ static bool g_checkCmdParam(std::vector &argv, std::string &errorIn ) { keys.insert(argv[1].substr(1).c_str()); } - for (auto& a : OHOS::SmartPerf::COMMAND_MAP_REVERSE) { - keys.insert(a.second.substr(1)); // No prefix required '-' + for (auto& a : OHOS::SmartPerf::COMMAND_SHELL_MAP) { + keys.insert(a.first.substr(1)); // No prefix required '-' } /* ************The command line for the following parameters is not implemented****************** */ -- Gitee From 66084a6ad812c3f1b2d93f707278bbb89fd52c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Fri, 15 Aug 2025 15:09:21 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- .../client/client_command/include/common.h | 15 ---- .../include/smartperf_command.h | 2 - .../client/client_command/include/sp_utils.h | 3 + .../client/client_command/smartperf_main.cpp | 2 + .../client/client_command/sp_utils.cpp | 73 ++++++++++++++----- 5 files changed, 58 insertions(+), 37 deletions(-) diff --git a/host/smartperf/client/client_command/include/common.h b/host/smartperf/client/client_command/include/common.h index 0b966f5fe..0644fab88 100644 --- a/host/smartperf/client/client_command/include/common.h +++ b/host/smartperf/client/client_command/include/common.h @@ -147,35 +147,20 @@ const std::unordered_map COMMAND_MAP = { { std::string("-PKG"), CommandType::CT_PKG }, { std::string("-PID"), CommandType::CT_PID }, { std::string("-OUT"), CommandType::CT_OUT }, - { std::string("-c"), CommandType::CT_C }, { std::string("-CPU"), CommandType::CT_C }, - { std::string("-g"), CommandType::CT_G }, { std::string("-GPU"), CommandType::CT_G }, - { std::string("-f"), CommandType::CT_F }, { std::string("-FPS"), CommandType::CT_F }, { std::string("-LOW_POWER"), CommandType::CT_F }, - { std::string("-fds"), CommandType::CT_FDS }, { std::string("-FDS"), CommandType::CT_FDS }, - { std::string("-t"), CommandType::CT_T }, { std::string("-TEMP"), CommandType::CT_T }, - { std::string("-p"), CommandType::CT_P }, { std::string("-POWER"), CommandType::CT_P }, - { std::string("-print"), CommandType::CT_PRINT }, - { std::string("-r"), CommandType::CT_R }, { std::string("-RAM"), CommandType::CT_R }, { std::string("-TRACE"), CommandType::CT_TRACE }, - { std::string("-threads"), CommandType::CT_THREADS }, - { std::string("-snapshot"), CommandType::CT_SNAPSHOT }, - { std::string("-SCREEN"), CommandType::CT_SNAPSHOT }, - { std::string("-d"), CommandType::CT_D }, { std::string("-DDR"), CommandType::CT_D }, { std::string("-INTERVAL"), CommandType::CT_INTERVAL }, { std::string("-SESSIONID"), CommandType::CT_SESSIONID }, - { std::string("-net"), CommandType::CT_NET }, { std::string("-NET"), CommandType::CT_NET }, { std::string("-VIEW"), CommandType::CT_VIEW }, - { std::string("-fl"), CommandType::CT_FL }, - { std::string("-ftl"), CommandType::CT_FTL }, { std::string("-gc"), CommandType::CT_GC }, { std::string("-GPU_COUNTER"), CommandType::CT_GC }, { std::string("-nav"), CommandType::CT_NAV }, diff --git a/host/smartperf/client/client_command/include/smartperf_command.h b/host/smartperf/client/client_command/include/smartperf_command.h index c1bf2168a..8d94539ac 100644 --- a/host/smartperf/client/client_command/include/smartperf_command.h +++ b/host/smartperf/client/client_command/include/smartperf_command.h @@ -60,7 +60,6 @@ public: " -server start a process to listen to the socket message of the start and stop commands \n" " -clear clear the process ID \n" " -ohtestfps used by the vilidator to obtain the fps, the collection times can be set \n" - " -editorServer start a process to listen to the socket message of the editor \n" " -recordcapacity get the battery level difference \n" " --version get version \n" " --help get help \n" @@ -79,7 +78,6 @@ public: "SP_daemon -server \n" "SP_daemon -clear \n" "SP_daemon -ohtestfps 10 \n" - "SP_daemon -editorServer \n" "SP_daemon -recordcapacity \n" "example3: These parameters need to be used separately \n" "SP_daemon -editor responseTime ohos.samples.ecg app name \n" diff --git a/host/smartperf/client/client_command/include/sp_utils.h b/host/smartperf/client/client_command/include/sp_utils.h index 3e3a57172..8d759d569 100644 --- a/host/smartperf/client/client_command/include/sp_utils.h +++ b/host/smartperf/client/client_command/include/sp_utils.h @@ -148,6 +148,9 @@ bool VeriyKey(std::set& keys, std::map& m bool VerifyValueStr(std::map& mapInfo, std::string& errorInfo); bool IntegerValueVerification(std::set &keys, std::map &mapInfo, std::string &errorInfo); +bool RemSpaceAndTraPara(std::vector& outParam, std::map& mapInfo, + std::string &errorInfo); +bool IsInvalidInputfromComParam(const std::string& param, std::string &errorInfo); bool IsHmKernel(); std::string GetCpuNum(); void GetCurrentTime(int prevTime); diff --git a/host/smartperf/client/client_command/smartperf_main.cpp b/host/smartperf/client/client_command/smartperf_main.cpp index 72bb62906..beaeeab3a 100644 --- a/host/smartperf/client/client_command/smartperf_main.cpp +++ b/host/smartperf/client/client_command/smartperf_main.cpp @@ -104,6 +104,8 @@ static bool g_checkCmdParam(std::vector &argv, std::string &errorIn keys.erase("f2"); keys.erase("fl"); keys.erase("ftl"); + keys.erase("editorServer"); + keys.erase("deviceServer"); return OHOS::SmartPerf::SPUtils::VeriyParameter(keys, str, errorInfo); } diff --git a/host/smartperf/client/client_command/sp_utils.cpp b/host/smartperf/client/client_command/sp_utils.cpp index b1fe62e4c..5e4e3dd06 100644 --- a/host/smartperf/client/client_command/sp_utils.cpp +++ b/host/smartperf/client/client_command/sp_utils.cpp @@ -517,12 +517,39 @@ bool SPUtils::IntegerVerification(const std::string& str, std::string& errorInfo bool SPUtils::VeriyParameter(std::set &keys, const std::string& param, std::string &errorInfo) { - std::string keyParam; - std::string valueParm; std::vector out; - std::vector subOut; std::map mapInfo; + if (!IsInvalidInputfromComParam(param, errorInfo)) { + LOGE("%s", errorInfo.c_str()); + return false; + } + + SPUtils::StrSplit(param, "-", out); + if (!RemSpaceAndTraPara(out, mapInfo, errorInfo)) { + LOGE("%s", errorInfo.c_str()); + return false; + } + + if (!VeriyKey(keys, mapInfo, errorInfo)) { + LOGE("%s", errorInfo.c_str()); + return false; + } + + if (!VerifyValueStr(mapInfo, errorInfo)) { + LOGE("%s", errorInfo.c_str()); + return false; + } + + if (!IntegerValueVerification(keys, mapInfo, errorInfo)) { + LOGE("%s", errorInfo.c_str()); + return false; + } + return true; +} + +bool SPUtils::IsInvalidInputfromComParam(const std::string& param, std::string &errorInfo) +{ if (param.empty()) { errorInfo = "The parameter cannot be empty"; return false; @@ -532,9 +559,30 @@ bool SPUtils::VeriyParameter(std::set &keys, const std::string& par LOGE("-PKG and -PID cannot be used together with"); return false; } - SPUtils::StrSplit(param, "-", out); + const size_t paramLength = 1; + if (param.length() == paramLength && param[0] == '-') { + errorInfo = "invalid parameter -- '" + param + "'"; + return false; + } + std::string commandShell; + for (const auto& a : COMMAND_SHELL_MAP) { + commandShell = a.first.substr(1); + } + if (param.find("--") != std::string::npos && param.find(commandShell)) { + errorInfo = "invalid parameter -- '" + param + "'"; + return false; + } + return true; +} - for (auto it = out.begin(); it != out.end(); ++it) { // Parsing keys and values +bool SPUtils::RemSpaceAndTraPara(std::vector& outParam, std::map& mapInfo, + std::string &errorInfo) +{ + std::string keyParam; + std::string valueParm; + std::vector subOut; + + for (auto it = outParam.begin(); it != outParam.end(); ++it) { // Parsing keys and values subOut.clear(); SPUtils::StrSplit(*it, " ", subOut); if (mapInfo.end() != mapInfo.find(subOut[0])) { @@ -554,21 +602,6 @@ bool SPUtils::VeriyParameter(std::set &keys, const std::string& par mapInfo[keyParam] = ""; } } - - if (!VeriyKey(keys, mapInfo, errorInfo)) { - LOGE("%s", errorInfo.c_str()); - return false; - } - - if (!VerifyValueStr(mapInfo, errorInfo)) { - LOGE("%s", errorInfo.c_str()); - return false; - } - - if (!IntegerValueVerification(keys, mapInfo, errorInfo)) { - LOGE("%s", errorInfo.c_str()); - return false; - } return true; } -- Gitee From 8b38e866ce9a14e0e6fbb647980ab5abc7cb4d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Fri, 15 Aug 2025 08:05:50 +0000 Subject: [PATCH 4/4] =?UTF-8?q?update=20host/smartperf/client/client=5Fcom?= =?UTF-8?q?mand/include/common.h.=20=E5=8F=82=E6=95=B0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- .../client/client_command/include/common.h | 71 ++++--------------- 1 file changed, 15 insertions(+), 56 deletions(-) diff --git a/host/smartperf/client/client_command/include/common.h b/host/smartperf/client/client_command/include/common.h index 0644fab88..04921821b 100644 --- a/host/smartperf/client/client_command/include/common.h +++ b/host/smartperf/client/client_command/include/common.h @@ -147,20 +147,35 @@ const std::unordered_map COMMAND_MAP = { { std::string("-PKG"), CommandType::CT_PKG }, { std::string("-PID"), CommandType::CT_PID }, { std::string("-OUT"), CommandType::CT_OUT }, + { std::string("-c"), CommandType::CT_C }, { std::string("-CPU"), CommandType::CT_C }, + { std::string("-g"), CommandType::CT_G }, { std::string("-GPU"), CommandType::CT_G }, + { std::string("-f"), CommandType::CT_F }, { std::string("-FPS"), CommandType::CT_F }, { std::string("-LOW_POWER"), CommandType::CT_F }, + { std::string("-fds"), CommandType::CT_FDS }, { std::string("-FDS"), CommandType::CT_FDS }, + { std::string("-t"), CommandType::CT_T }, { std::string("-TEMP"), CommandType::CT_T }, + { std::string("-p"), CommandType::CT_P }, { std::string("-POWER"), CommandType::CT_P }, + { std::string("-print"), CommandType::CT_PRINT }, + { std::string("-r"), CommandType::CT_R }, { std::string("-RAM"), CommandType::CT_R }, { std::string("-TRACE"), CommandType::CT_TRACE }, + { std::string("-threads"), CommandType::CT_THREADS }, + { std::string("-snapshot"), CommandType::CT_SNAPSHOT }, + { std::string("-SCREEN"), CommandType::CT_SNAPSHOT }, + { std::string("-d"), CommandType::CT_D }, { std::string("-DDR"), CommandType::CT_D }, { std::string("-INTERVAL"), CommandType::CT_INTERVAL }, { std::string("-SESSIONID"), CommandType::CT_SESSIONID }, + { std::string("-net"), CommandType::CT_NET }, { std::string("-NET"), CommandType::CT_NET }, { std::string("-VIEW"), CommandType::CT_VIEW }, + { std::string("-fl"), CommandType::CT_FL }, + { std::string("-ftl"), CommandType::CT_FTL }, { std::string("-gc"), CommandType::CT_GC }, { std::string("-GPU_COUNTER"), CommandType::CT_GC }, { std::string("-nav"), CommandType::CT_NAV }, @@ -173,62 +188,6 @@ const std::unordered_map COMMAND_MAP = { { std::string("-HCI"), CommandType::CT_HCI }, }; -const std::unordered_map COMMAND_MAP_REVERSE = { - { CommandType::CT_N, std::string("-N") }, - { CommandType::CT_PKG, std::string("-PKG") }, - { CommandType::CT_PID, std::string("-PID") }, - { CommandType::CT_OUT, std::string("-OUT") }, - { CommandType::CT_C, std::string("-c") }, - { CommandType::CT_G, std::string("-g") }, - { CommandType::CT_F, std::string("-f") }, - { CommandType::CT_FDS, std::string("-fds") }, - { CommandType::CT_T, std::string("-t") }, - { CommandType::CT_P, std::string("-p") }, - { CommandType::CT_PRINT, std::string("-print") }, - { CommandType::CT_R, std::string("-r") }, - { CommandType::CT_TRACE, std::string("-TRACE") }, - { CommandType::CT_THREADS, std::string("-threads") }, - { CommandType::CT_SNAPSHOT, std::string("-snapshot") }, - { CommandType::CT_D, std::string("-d") }, - { CommandType::CT_INTERVAL, std::string("-INTERVAL") }, - { CommandType::CT_SESSIONID, std::string("-SESSIONID") }, - { CommandType::CT_NET, std::string("-net") }, - { CommandType::CT_VIEW, std::string("-VIEW") }, - { CommandType::CT_FL, std::string("-fl") }, - { CommandType::CT_FTL, std::string("-ftl") }, - { CommandType::CT_GC, std::string("-GPU_COUNTER") }, - { CommandType::CT_NAV, std::string("-nav") }, - { CommandType::CT_O, std::string("-o") }, - { CommandType::CT_LF, std::string("-lockfreq") }, - { CommandType::CT_AS, std::string("-aischedule") }, - { CommandType::CT_GE, std::string("-ge") }, - { CommandType::CT_CI, std::string("-ci") }, - { CommandType::CT_FC, std::string("-fc") }, - { CommandType::CT_HCI, std::string("-HCI") }, -}; - -const std::unordered_map COMMAND_SHELL_MAP = { - { std::string("-N"), CommandType::CT_N }, - { std::string("-PKG"), CommandType::CT_PKG }, - { std::string("-PID"), CommandType::CT_PID }, - { std::string("-threads"), CommandType::CT_THREADS }, - { std::string("-c"), CommandType::CT_C }, - { std::string("-ci"), CommandType::CT_CI }, - { std::string("-g"), CommandType::CT_G }, - { std::string("-f"), CommandType::CT_F }, - { std::string("-t"), CommandType::CT_T }, - { std::string("-p"), CommandType::CT_P }, - { std::string("-print"), CommandType::CT_PRINT }, - { std::string("-r"), CommandType::CT_R }, - { std::string("-snapshot"), CommandType::CT_SNAPSHOT }, - { std::string("-net"), CommandType::CT_NET }, - { std::string("-VIEW"), CommandType::CT_VIEW }, - { std::string("-OUT"), CommandType::CT_OUT }, - { std::string("-d"), CommandType::CT_D }, - { std::string("-fl"), CommandType::CT_FL }, - { std::string("-ftl"), CommandType::CT_FTL }, -}; - const std::unordered_map COMMAND_HELP_MAP = { { CommandHelp::HELP, std::string("--help") }, { CommandHelp::VERSION, std::string("--version") }, -- Gitee