diff --git a/smartperf_device/device_command/cmds/include/smartperf_command.h b/smartperf_device/device_command/cmds/include/smartperf_command.h index e36069770bcc6e62ad4814310e68cb4ae3e71a81..8d94539ac17afd334a89ca1ed8e359dbc95ac8ac 100644 --- a/smartperf_device/device_command/cmds/include/smartperf_command.h +++ b/smartperf_device/device_command/cmds/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" @@ -62,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" @@ -81,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/smartperf_device/device_command/cmds/src/smartperf_command.cpp b/smartperf_device/device_command/cmds/src/smartperf_command.cpp index 30bef234e46367786cd068e08c51de4c180a8e1b..49f849ae3f64b2c927b9e3b5ac5c9d17ba82bac5 100644 --- a/smartperf_device/device_command/cmds/src/smartperf_command.cpp +++ b/smartperf_device/device_command/cmds/src/smartperf_command.cpp @@ -54,9 +54,8 @@ SmartPerfCommand::SmartPerfCommand(std::vector& argv) } if (argv[1].find("-editorServer") != std::string::npos) { WLOGI("############################# Found '-editorServer' argument in argv"); + std::string token = argv[1].substr(serverCommandLength, argv[1].length() - serverCommandLength); SPUtils::KillStartDaemon(); - const size_t tokenStartPosition = 14; - std::string token = argv[1].substr(tokenStartPosition, argv[1].length() - tokenStartPosition); HelpCommand(CommandHelp::EDITORSERVER, token); } else if (argv[1].find("-deviceServer") != std::string::npos) { WLOGI("############################# Found '-deviceServer' argument in argv"); diff --git a/smartperf_device/device_command/collector/include/ByTrace.h b/smartperf_device/device_command/collector/include/ByTrace.h index 45b280068a0606df10e3bb4786600dbea6568670..d284ff410bcda62a061efea406cf3008f23edfd2 100644 --- a/smartperf_device/device_command/collector/include/ByTrace.h +++ b/smartperf_device/device_command/collector/include/ByTrace.h @@ -27,34 +27,31 @@ public: return instance; } std::map ItemData() override; - // trace配置 - void SetTraceConfig(long long mThreshold, int mLowfps) const; // 校验fps-jitters - void CheckFpsJitters(long long& jitters, int cfps) const; - // 触发trace - void SetByTrace() const; + void CheckFpsJitters(long long& jitters, int cfps); + void SetByTrace(); void ClearTraceFiles() const; void RemoveTraceFiles() const; void CpTraceFile() const; + long long GetThreshold() const; + int GetLowFps() const; + void SendSurfaceCaton(long long& jitters, int cfps); static inline std::string jittersAndLowFps = ""; static inline std::string hiviewTrace = ""; public: - // 抓trace触发条件:默认 某一帧的某个jitter>100 ms触发 - mutable long long threshold = 100; - mutable long long lastEnableTime = 0; - // 低帧触发 - mutable int lowfps = -1; - // 前2秒采的不准 - mutable int times = 0; - mutable std::string traceCpPath_ {"/data/local/tmp/hitrace"}; - mutable long long comperTime = 1000; - mutable long long nowTime = 0; + long long lastEnableTime = 0; + std::string traceCpPath_ {"/data/local/tmp/hitrace"}; + long long nowTime = 0; + int times = 0; private: ByTrace() {}; ByTrace(const ByTrace &); ByTrace &operator = (const ByTrace &); - mutable std::string hiviewTracePath_ {"/data/log/hiview/unified_collection/trace/special/"}; + const std::string hiviewTracePath_ {"/data/log/hiview/unified_collection/trace/special/"}; + + long long jitterTimesTaken = 0; + int lowFps = -1; }; } } diff --git a/smartperf_device/device_command/collector/include/CPU.h b/smartperf_device/device_command/collector/include/CPU.h index 81b3e8dca07b08a07b3c85f3eb33914a2c4b0e98..eac3bb4bd553e1c4ddb4b08dde922dcf4f791ea9 100644 --- a/smartperf_device/device_command/collector/include/CPU.h +++ b/smartperf_device/device_command/collector/include/CPU.h @@ -52,7 +52,6 @@ public: std::map GetCpuCoreCurFreqs(); void GetCpuFreqItemData(std::map &cpuFreqResult); void GetCpuUsageItemData(std::map &cpuUsageResult); - private: CPU() {}; CPU(const CPU &); diff --git a/smartperf_device/device_command/collector/include/Dubai.h b/smartperf_device/device_command/collector/include/Dubai.h index 2fe3e6484f178ec725930bfcfb481ea0a132d0d3..33adfc03fc021162e7e4053fd547536872e06eab 100644 --- a/smartperf_device/device_command/collector/include/Dubai.h +++ b/smartperf_device/device_command/collector/include/Dubai.h @@ -14,7 +14,6 @@ */ #ifndef DUBAI_H #define DUBAI_H -#include namespace OHOS { namespace SmartPerf { class Dubai { @@ -26,7 +25,7 @@ public: } // dubai db转移smartperf 沙箱 static void MoveDubaiDb(); - // testsa自拉起SP db文件转移到local + // testsa自拉起SP dubai db转移到local static void MoveDubaiDb(const std::string &path); // dubai -b static void DumpDubaiBegin(); diff --git a/smartperf_device/device_command/collector/include/cpu_info.h b/smartperf_device/device_command/collector/include/cpu_info.h index ec518cebb027cfa165522a0fe4e4edf6ee91542b..53e9c378a74003a923d2f4d2d4e0eb81271134d8 100644 --- a/smartperf_device/device_command/collector/include/cpu_info.h +++ b/smartperf_device/device_command/collector/include/cpu_info.h @@ -25,7 +25,8 @@ #include #include -namespace OHOS::SmartPerf { +namespace OHOS { +namespace SmartPerf { class CPUInfo : public SpProfiler { public: static CPUInfo &GetInstance() @@ -51,5 +52,5 @@ private: std::string buffer_; }; } - +} #endif // CPU_INFO_H \ No newline at end of file diff --git a/smartperf_device/device_command/collector/include/effective.h b/smartperf_device/device_command/collector/include/effective.h index 42db10703024a6f4b661c738daaf30705de375f8..146514af39cc4fce0cae97ca5329bfa4a938a700 100644 --- a/smartperf_device/device_command/collector/include/effective.h +++ b/smartperf_device/device_command/collector/include/effective.h @@ -20,8 +20,8 @@ #include #include #include - -namespace OHOS::SmartPerf { +namespace OHOS { +namespace SmartPerf { class Effective : public SpProfiler { public: static Effective &GetInstance() @@ -108,5 +108,5 @@ private: std::string conFig_ = R"(CONFIG)"; }; } - +} #endif \ No newline at end of file diff --git a/smartperf_device/device_command/collector/include/parse_slide_fps_trace.h b/smartperf_device/device_command/collector/include/parse_slide_fps_trace.h index a55e2a0ae600e8c3b317d9a66ac81c16f84cd1b5..24475d24d3ad38ed4ff41077f7368ab55889d2ba 100644 --- a/smartperf_device/device_command/collector/include/parse_slide_fps_trace.h +++ b/smartperf_device/device_command/collector/include/parse_slide_fps_trace.h @@ -26,7 +26,8 @@ public: double ParseSlideFpsTraceNoh(const std::string& file); double CalculateTime(); std::string GetLineTime(const std::string& lineStr) const; - std::string CutString(const std::string& lineStr, const std::string &start, const std::string &end, size_t offset) const; + std::string CutString(const std::string& lineStr, const std::string &start, + const std::string &end, size_t offset) const; void AppSwiperScroll(const std::string& line); private: std::ifstream infile; diff --git a/smartperf_device/device_command/collector/src/ByTrace.cpp b/smartperf_device/device_command/collector/src/ByTrace.cpp index 5fa043f7b67e9013b3601e0741a7dc878c7d9c72..a09e1759ddc002950c6c74c4f3859dd739e6d39c 100644 --- a/smartperf_device/device_command/collector/src/ByTrace.cpp +++ b/smartperf_device/device_command/collector/src/ByTrace.cpp @@ -23,7 +23,7 @@ #include "include/common.h" namespace { -constexpr long long RM_10000 = 10000; +constexpr long long TIME_DIFF_THRESHOLD = 10000; } namespace OHOS { namespace SmartPerf { @@ -32,39 +32,51 @@ std::map ByTrace::ItemData() return std::map(); } -void ByTrace::SetTraceConfig(long long mThreshold, int mLowfps) const +long long ByTrace::GetThreshold() const { - threshold = mThreshold; - lowfps = mLowfps; - LOGD("ByTrace::SetTraceConfig threshold(%lld), lowfps(%d)", threshold, lowfps); + long long jitters = jitterTimesTaken; + return jitters; } -void ByTrace::SetByTrace() const +int ByTrace::GetLowFps() const +{ + int lowfps = lowFps; + return lowfps; +} + +void ByTrace::SetByTrace() { std::vector values; std::string delimiter = "||"; std::string delim = "="; + size_t boundSize = 2; SPUtils::StrSplit(jittersAndLowFps, delimiter, values); - long long mThreshold = 0; - int lowFps = 0; + bool jitterTimesTakenSet = false; + bool lowFpsSet = false; for (std::string& vItem : values) { std::vector vItems; SPUtils::StrSplit(vItem, delim, vItems); - if (vItems[0] == "fpsJitterTime") { - mThreshold = SPUtilesTye::StringToSometype(vItems[1]); - } - if (vItems[0] == "lowFps") { - lowFps = SPUtilesTye::StringToSometype(vItems[1]); + if (vItems.size() >= boundSize) { + if (vItems[0] == "fpsJitterTime") { + jitterTimesTaken = SPUtilesTye::StringToSometype(vItems[1]); + jitterTimesTakenSet = true; + } + if (vItems[0] == "lowFps") { + lowFps = SPUtilesTye::StringToSometype(vItems[1]); + lowFpsSet = true; + } } } - SetTraceConfig(mThreshold, lowFps); + if (!jitterTimesTakenSet || !lowFpsSet) { + LOGE("ByTrace::Missing required parameters in jittersAndLowFps"); + return; + } + LOGD("ByTrace::SetByTrace jitterTimesTaken(%lld), lowFps(%d)", jitterTimesTaken, lowFps); } void ByTrace::ClearTraceFiles() const { - if (!std::filesystem::exists(traceCpPath_)) { - SPUtils::CreateDir(traceCpPath_); - } else { + if (std::filesystem::exists(traceCpPath_)) { RemoveTraceFiles(); } } @@ -82,34 +94,54 @@ void ByTrace::RemoveTraceFiles() const void ByTrace::CpTraceFile() const { + if (!std::filesystem::exists(traceCpPath_)) { + SPUtils::CreateDir(traceCpPath_); + } + if (!std::filesystem::is_directory(traceCpPath_)) { + LOGE("Destination path is not a directory."); + return; + } std::string result; std::string cpResult; + constexpr const char* cpCommand = "cp -r "; + constexpr const char* chmodCommand = "chmod 777 "; const std::string cpHiviewTracePath = hiviewTracePath_ + hiviewTrace; - const std::string cpTrace = "cp -r " + cpHiviewTracePath + " " + traceCpPath_; - SPUtils::LoadCmd(cpTrace, result); - if (!result.empty()) { - const std::string tracePathChmod = "chmod 777 " + traceCpPath_; - SPUtils::LoadCmd(tracePathChmod, cpResult); + const std::string cpTrace = cpCommand + cpHiviewTracePath + " " + traceCpPath_; + if (!SPUtils::LoadCmd(cpTrace, result)) { + LOGE("Copy failed."); + return; } + std::string tracePathChmod = chmodCommand + traceCpPath_; + if (!SPUtils::LoadCmd(tracePathChmod, result)) { + LOGE("Chmod failed."); + return; + } + LOGD("ByTrace::CpTraceFile result = (%s)", result.c_str()); } -void ByTrace::CheckFpsJitters(long long& jitters, int cfps) const +void ByTrace::CheckFpsJitters(long long& jitters, int cfps) { times++; - int two = 2; + const int two = 2; if (times > two) { nowTime = SPUtils::GetCurTime(); if (lastEnableTime > 0) { long long diff = - lastEnableTime > nowTime ? (LLONG_MAX - lastEnableTime + nowTime) : (nowTime - lastEnableTime); - LOGD("ByTrace::Time difference: %lld ms", diff); - if (diff > RM_10000) { - LOGW("ByTrace::Time difference exceeded threshold, resetting start capture time."); - lastEnableTime = 0; - } + (nowTime >= lastEnableTime) ? (nowTime - lastEnableTime) : (LLONG_MAX - lastEnableTime + nowTime + 1); + LOGD("ByTrace::Time difference: %llu ms", diff); + if (diff > TIME_DIFF_THRESHOLD) { + LOGW("ByTrace::Time difference exceeded threshold, resetting start capture time."); + lastEnableTime = 0; + } } + SendSurfaceCaton(jitters, cfps); } - if (cfps < lowfps || jitters > threshold) { +} + +void ByTrace::SendSurfaceCaton(long long& jitters, int cfps) +{ + if (cfps < lowFps || jitters > jitterTimesTaken) { + LOGD("ByTrace::SendSurfaceCaton jitters(%lld), cfps(%d)", jitters, cfps); if (lastEnableTime == 0) { lastEnableTime = nowTime; ipcCallback_("surfaceCaton"); diff --git a/smartperf_device/device_command/collector/src/Dubai.cpp b/smartperf_device/device_command/collector/src/Dubai.cpp index abbd47d82be7f6f5494ad06748003041a43b82ac..580c10f0640a69c6b45dfdc584ddbddc942ef5dd 100644 --- a/smartperf_device/device_command/collector/src/Dubai.cpp +++ b/smartperf_device/device_command/collector/src/Dubai.cpp @@ -60,11 +60,11 @@ void Dubai::MoveDubaiDb() void Dubai::MoveDubaiDb(const std::string &path) { std::string result; - const std::string dubaiLocalPath = "/data/local/tmp/dubai"; + const std::string dubaiLocalPath = "/data/local/tmp/dubai/"; SPUtils::CreateDir(dubaiLocalPath); const std::string cpDubai = "cp " + path + " " + dubaiLocalPath; const std::string dubaiPathChmod = "chmod 777 " + dubaiLocalPath + "dubai.db"; - LOGD("cpDubai:(%s), dubaiPathChmod:(%s)", + LOGD("cpDubai: (%s), dubaiPathChmod: (%s)", cpDubai.c_str(), dubaiPathChmod.c_str()); if (!IsFileAccessible(path)) { sleep(1); diff --git a/smartperf_device/device_command/collector/src/FPS.cpp b/smartperf_device/device_command/collector/src/FPS.cpp index 38907a534b8a717b7593e3418cd7527f24aa44ee..a39458369680ce426081565dcfaea65aea31c3ae 100644 --- a/smartperf_device/device_command/collector/src/FPS.cpp +++ b/smartperf_device/device_command/collector/src/FPS.cpp @@ -87,7 +87,7 @@ std::map FPS::GetFpsAndJitters(FpsInfo &fpsInfoResult, long long maxJitters = 0; if (!fpsInfoResult.jitters.empty()) { auto maxElement = std::max_element(fpsInfoResult.jitters.begin(), fpsInfoResult.jitters.end()); - maxJitters = *maxElement / oneSec; + maxJitters = static_cast(*maxElement / oneSec); } ByTrace::GetInstance().CheckFpsJitters(maxJitters, fpsInfoResult.fps); } @@ -329,6 +329,7 @@ void FPS::ReadDataFromPipe(int fd) } std::stringstream sstream; while (fgets(tmp, sizeof(tmp), fp) != nullptr) { + LOGD("FPS::ReadDataFromPipe::dump time: %s", tmp); std::string tmpStr(tmp); curScreenTimestamp = 0; sstream.clear(); @@ -355,6 +356,7 @@ FpsInfo FPS::GetFpsInfoByRs(const std::string& name) s >> nodeId; LOGD("FPS::GetFpsInfoByRs nodeId: (%lld)", nodeId); std::string fpsInfoResult = OHOS::Rosen::RSInterfaces::GetInstance().GetRefreshInfoToSP(nodeId); + LOGD("FPS fpsInfoResult: %s", fpsInfoResult.c_str()); std::stringstream iss; iss << fpsInfoResult; std::string timeStampLine; diff --git a/smartperf_device/device_command/collector/src/GPU.cpp b/smartperf_device/device_command/collector/src/GPU.cpp index fb53299a35227ad749b902d29741688395a5dcff..3c1570cf3500f866a017021704f0a1630736c327 100644 --- a/smartperf_device/device_command/collector/src/GPU.cpp +++ b/smartperf_device/device_command/collector/src/GPU.cpp @@ -43,6 +43,7 @@ std::map GPU::ItemData() result["gpuFrequency"] = "NA"; result["gpuLoad"] = "NA"; } + LOGI("GPU:ItemData map size(%u)", result.size()); return result; } diff --git a/smartperf_device/device_command/collector/src/GpuCounterCallback.cpp b/smartperf_device/device_command/collector/src/GpuCounterCallback.cpp index 0d30860904580000305879c1e42e6440df002a18..9c2e2121f03d169a4ceb798fb140d7854ad0104e 100644 --- a/smartperf_device/device_command/collector/src/GpuCounterCallback.cpp +++ b/smartperf_device/device_command/collector/src/GpuCounterCallback.cpp @@ -249,13 +249,10 @@ namespace OHOS { gpuCounter.pop_back(); continue; } - backData->duration = durationTime; - std::string gpuPerfInfoItemStr = GetGpuPerfInfoItem(backData); gpuCounterInstance.GetGpuCounterData().push_back(gpuPerfInfoItemStr); gpuCounterInstance.GetGpuCounterSaveReportData().push_back(gpuPerfInfoItemStr); - GetRealTime(backData); } diff --git a/smartperf_device/device_command/collector/src/Temperature.cpp b/smartperf_device/device_command/collector/src/Temperature.cpp index 715204785d490452ac40d8326b4269951ab9bcf0..a8a82af3803a513b72a271c6654872389b35c97e 100644 --- a/smartperf_device/device_command/collector/src/Temperature.cpp +++ b/smartperf_device/device_command/collector/src/Temperature.cpp @@ -52,6 +52,7 @@ std::map Temperature::ItemData() SPUtils::LoadFile(dirTemp, temp); GetTempInfos(result, type, temp); } + LOGI("Temperature:ItemData map size(%u)", result.size()); return result; } diff --git a/smartperf_device/device_command/collector/src/cpu_info.cpp b/smartperf_device/device_command/collector/src/cpu_info.cpp index 98f87d0aaabe01de7c437713939b17ce2a6d6409..45091f591a7e10287245e7afcf29e3c3e597e631 100644 --- a/smartperf_device/device_command/collector/src/cpu_info.cpp +++ b/smartperf_device/device_command/collector/src/cpu_info.cpp @@ -85,7 +85,7 @@ void CPUInfo::CalculateCPIInfo(const std::string line, double &cpi_total, size_t } void CPUInfo::StartExecutionOnce(bool isPause) -{ +{ (void)isPause; Stop(); if (pids_.empty()) { diff --git a/smartperf_device/device_command/collector/src/sdk_data_recv.cpp b/smartperf_device/device_command/collector/src/sdk_data_recv.cpp index 6e61efe4622dc9038d32831d42d5a1fd9a18af28..2e0eeb5d46a7292827fa5d3c3daf77b58be36570 100644 --- a/smartperf_device/device_command/collector/src/sdk_data_recv.cpp +++ b/smartperf_device/device_command/collector/src/sdk_data_recv.cpp @@ -59,6 +59,9 @@ namespace OHOS { OHOS::system::SetParameter("debug.smartperf.sdkdataenable", "1"); collectRunring = true; WLOGI("Starting sdkdata collection in new thread"); + if (th_.joinable()) { + th_.join(); + } th_ = std::thread([this]() { ServerThread(); }); } diff --git a/smartperf_device/device_command/include/common.h b/smartperf_device/device_command/include/common.h index 70a9aa01967c6ddf804d8ab70bd8fe8397388a71..0644fab88674b3853e3769d4e0f00e73d3466d76 100644 --- a/smartperf_device/device_command/include/common.h +++ b/smartperf_device/device_command/include/common.h @@ -37,6 +37,7 @@ enum class MessageType { GET_POWER, GET_CAPTURE, CATCH_ONE_TRACE, + CATCH_TRACE_FINISH, SET_DUBAI_DB, START_DUBAI_DB, CATCH_NETWORK_TRAFFIC, @@ -72,6 +73,7 @@ const std::unordered_map MESSAGE_MAP = { { MessageType::GET_CAPTURE, std::string("get_capture") }, { MessageType::GET_MEMORY_INFO, std::string("get_memory") }, { MessageType::CATCH_ONE_TRACE, std::string("catch_one_trace") }, + { MessageType::CATCH_TRACE_FINISH, std::string("catch_trace_finish") }, { MessageType::SET_DUBAI_DB, std::string("set_dubai_db") }, { MessageType::START_DUBAI_DB, std::string("start_dubai_db") }, { MessageType::CATCH_NETWORK_TRAFFIC, std::string("catch_network_traffic") }, @@ -145,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("-TRACE"), CommandType::CT_TRACE }, { 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 }, @@ -199,7 +186,7 @@ const std::unordered_map COMMAND_MAP_REVERSE = { { 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_TRACE, std::string("-TRACE") }, { CommandType::CT_THREADS, std::string("-threads") }, { CommandType::CT_SNAPSHOT, std::string("-snapshot") }, { CommandType::CT_D, std::string("-d") }, @@ -220,6 +207,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/smartperf_device/device_command/include/sp_csv_util.h b/smartperf_device/device_command/include/sp_csv_util.h index 2778aff9cf726529ff99da03feb5c936f304c191..b0a875ca773e7563d7bb141d6632d21b0190431b 100644 --- a/smartperf_device/device_command/include/sp_csv_util.h +++ b/smartperf_device/device_command/include/sp_csv_util.h @@ -41,7 +41,7 @@ public: std::string cmdResult; SPUtils::LoadCmd(CMD_COMMAND_MAP.at(CmdCommand::USER_PERMISSIONS), cmdResult); outFile.open(path.c_str(), std::ios::out | std::ios::trunc); - if (SPUtils::GetPathPermissions(path) && outFile.is_open() && path == "/data/local/tmp/data.csv" && + if (SPUtils::GetPathPermissions(path) && outFile.is_open() && path == "/data/local/tmp/data.csv" && (cmdResult == "root" || cmdResult == "shell")) { std::string cmd = "chmod 777 " + path; SPUtils::LoadCmd(cmd, cmdResult); @@ -134,6 +134,7 @@ public: std::string partitionName = "/data"; std::string dirName = "/data/local/tmp"; struct statfs partitionStat; + if (statfs(partitionName.c_str(), &partitionStat) != 0) { LOGE("Get remain partition size failed, partitionName = %{public}s", partitionName.c_str()); return; diff --git a/smartperf_device/device_command/scenarios/src/stalling_rate_trace.cpp b/smartperf_device/device_command/scenarios/src/stalling_rate_trace.cpp index 77b31060b560176838095fa634d880e843a62953..4a66a64e851003f50fba6f12df346f207b3ef632 100644 --- a/smartperf_device/device_command/scenarios/src/stalling_rate_trace.cpp +++ b/smartperf_device/device_command/scenarios/src/stalling_rate_trace.cpp @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include #include @@ -99,15 +100,15 @@ void StallingRateTrace::JudgFrameRate() bool tabsDynamicExists = hasDynamic(appTabsDynamicFinishTime, appTabsDynamicStartTime); if (!appListDynamicExists) { - LOGD("no app list Dynamic"); //û��APP listӾ�� + LOGD("no app list Dynamic"); //没有APP list泳道 frameLossRate = swiperDynamicExists ? swiperFrameLossRate : tabsDynamicExists ? tabsFrameLossRate : -1; } else if (!swiperDynamicExists) { - LOGD("no swiper Dynamic"); //û��swiper Ӿ�� + LOGD("no swiper Dynamic"); //没有swiper 泳道 frameLossRate = appListDynamicExists ? appFrameLossRate : tabsDynamicExists ? tabsFrameLossRate : -1; } else if (!tabsDynamicExists) { - LOGD("no tabs Dynamic"); //û��tabs Ӿ�� + LOGD("no tabs Dynamic"); //没有tabs 泳道 frameLossRate = appListDynamicExists ? appFrameLossRate : swiperDynamicExists ? swiperFrameLossRate : -1; } else { @@ -119,7 +120,7 @@ void StallingRateTrace::MultiLaneFrameRate() { if (appFrameLossRate == 0) { if (swiperFrameLossRate > 0) { - LOGD("no app list hitchTime"); //û��app list���ٴ��� + LOGD("no app list hitchTime"); //没有app list卡顿次数 frameLossRate = swiperFrameLossRate; } else if (tabsFrameLossRate > 0) { frameLossRate = tabsFrameLossRate; @@ -127,7 +128,7 @@ void StallingRateTrace::MultiLaneFrameRate() frameLossRate = 0; } } else if (swiperFrameLossRate == 0) { - LOGD("no swiper list hitchTime"); //û��swiper list���ٴ��� + LOGD("no swiper list hitchTime"); //没有swiper list卡顿次数 if (appFrameLossRate > 0) { frameLossRate = appFrameLossRate; } else if (tabsFrameLossRate > 0) { @@ -136,7 +137,7 @@ void StallingRateTrace::MultiLaneFrameRate() frameLossRate = 0; } } else if (tabsFrameLossRate == 0) { - LOGD("no tabs list hitchTime"); //û��tabs list���ٴ��� + LOGD("no tabs list hitchTime"); //没有tabs list卡顿次数 if (appFrameLossRate > 0) { frameLossRate = appFrameLossRate; } else if (swiperFrameLossRate > 0) { diff --git a/smartperf_device/device_command/services/ipc/include/sp_server_socket.h b/smartperf_device/device_command/services/ipc/include/sp_server_socket.h index 4b0929579a0a03c0ae4de5c1c4a6c74cf3c6d049..cd680c2ffa24c52431c7288ee4020dec57d3f5a2 100644 --- a/smartperf_device/device_command/services/ipc/include/sp_server_socket.h +++ b/smartperf_device/device_command/services/ipc/include/sp_server_socket.h @@ -39,7 +39,6 @@ public: // 关闭 void Close(); std::string RecvBuf() const; - bool IsValid(); private: int sock = -1; diff --git a/smartperf_device/device_command/services/ipc/include/sp_thread_socket.h b/smartperf_device/device_command/services/ipc/include/sp_thread_socket.h index 1d76524cbbf717a8e3aa5a8edf5d1435256cf253..c14f94e17567a172116a7301c4f3bbfa8a32dd37 100644 --- a/smartperf_device/device_command/services/ipc/include/sp_thread_socket.h +++ b/smartperf_device/device_command/services/ipc/include/sp_thread_socket.h @@ -16,8 +16,9 @@ #define SP_THREAD_SOCKET_H #include "sp_server_socket.h" #include "sp_task.h" -#include #include "ByTrace.h" +#include +#include "GpuCounter.h" namespace OHOS { namespace SmartPerf { enum class SocketConnectType { @@ -93,6 +94,7 @@ private: bool socketConnect = true; std::string checkToken = ""; // 拉起测试时校验 bool isNeedUdpToken = true; // 如果是hdc shell拉起,不需要校验token以兼容旧版本 + GpuCounter &gpuCounter = GpuCounter::GetInstance(); const std::string traceOriginPath = "/data/log/hiview/unified_collection/trace/special/"; const std::string indexFilePath = "/data/local/tmp/smartperf/1/t_index_info.csv"; const std::string gpuCounterfilePath = "/data/local/tmp/smartperfDevice"; @@ -108,8 +110,15 @@ private: SPTask &spTask = SPTask::GetInstance(); std::thread udpStartCollect; + ~SpThreadSocket() + { + if (udpStartCollect.joinable()) { + udpStartCollect.join(); + } + } std::shared_ptr taskMgr_ {nullptr}; ByTrace &bytrace = ByTrace::GetInstance(); + bool firstFlag = true; }; } } diff --git a/smartperf_device/device_command/services/ipc/src/sp_server_socket.cpp b/smartperf_device/device_command/services/ipc/src/sp_server_socket.cpp index 61223f5182118f7ef18d159bb1737a4efabe6b21..bfd5c5cb3587b3b92c655c95d0917d8fe0952c8a 100644 --- a/smartperf_device/device_command/services/ipc/src/sp_server_socket.cpp +++ b/smartperf_device/device_command/services/ipc/src/sp_server_socket.cpp @@ -136,18 +136,5 @@ std::string SpServerSocket::RecvBuf() const return recvBuf; } -bool SpServerSocket::IsValid() -{ - if (sock < 0) { - LOGE("SpServerSocket::Init Socket Create Failed"); - return false; - } - int error = 0; - socklen_t len = sizeof(error); - if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { - return false; - } - return (error == 0); -} } } diff --git a/smartperf_device/device_command/services/ipc/src/sp_thread_socket.cpp b/smartperf_device/device_command/services/ipc/src/sp_thread_socket.cpp index 70227373618fa7e14bf7728130bec0ab4815aec5..dd78055d209731c3d8137be8342d834097b0590b 100644 --- a/smartperf_device/device_command/services/ipc/src/sp_thread_socket.cpp +++ b/smartperf_device/device_command/services/ipc/src/sp_thread_socket.cpp @@ -1,3 +1,4 @@ + /* * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +25,6 @@ #include #include #include -#include "include/GameEvent.h" #include "parameters.h" #include "include/sp_csv_util.h" #include "include/sdk_data_recv.h" @@ -40,6 +40,7 @@ #include "include/Network.h" #include "include/startup_delay.h" #include "include/Dubai.h" +#include "include/GameEvent.h" #include "include/GetLog.h" #include "include/RAM.h" #include "include/FPS.h" @@ -399,10 +400,10 @@ void SpThreadSocket::HandleMsg(SpServerSocket &spSocket) return; } RemoveToken(recvBuf); - if (recvBuf.find("init::") != std::string::npos) { - LOGD("UDP recv : %s", recvBuf.c_str()); + if (recvBuf.find("init::") != std::string::npos && firstFlag) { HandleMsgTrace(recvBuf); UdpStartInitFunc(recvBuf, spSocket); + firstFlag = false; break; } if (!SPUtils::IsSubString(recvBuf, iterator->second)) { @@ -438,7 +439,7 @@ void SpThreadSocket::HandleMsg(SpServerSocket &spSocket) void SpThreadSocket::HandleMsgTrace(std::string& recvMessage) { - const std::string traceWord = "-trace::"; + const std::string traceWord = "-TRACE::"; const size_t startPos = recvMessage.find(traceWord); const size_t tarceLength = traceWord.length(); const size_t colonLength = 2; @@ -465,11 +466,7 @@ void SpThreadSocket::UdpStartInitFunc(const std::string& recvBuf, SpServerSocket taskMgr_->WriteToCSV(); } taskMgr_ = std::make_shared(true); - auto lambdaTask = [spSocket = std::ref(spSocket)](const std::string &data) mutable { - if (spSocket.get().IsValid()) { - spSocket.get().Sendto(data); - } - }; + auto lambdaTask = [&spSocket](const std::string &data) { spSocket.Sendto(data); }; taskMgr_->SetIPCCallback(lambdaTask); taskMgr_->AddTask(recvBuf); spTask.SetAppCmd(recvBuf); @@ -565,10 +562,11 @@ void SpThreadSocket::ConnectAndSendFile(SpServerSocket &spSocket, const std::str return; } std::string sendFileSizeMsg = "SendFileSize:::" + std::to_string(fileSize); - LOGD("UDP START sendFileSizeMsg = %s", sendFileSizeMsg.c_str()); + LOGI("UDP START sendFileSizeMsg = %s", sendFileSizeMsg.c_str()); spSocket.Sendto(sendFileSizeMsg); - LOGD("UDP Sendto sendFileSizeMsg = %s", sendFileSizeMsg.c_str()); + LOGI("UDP Sendto sendFileSizeMsg = %s", sendFileSizeMsg.c_str()); }); + std::thread sendFileThread([this, filePath]() { int fileSocket = -1; int connectCount = 0; @@ -687,6 +685,10 @@ void SpThreadSocket::HandleNullMsg(SpServerSocket &spSocket, SpProfiler *profile } else if (iterator->first == MessageType::CATCH_ONE_TRACE) { bytrace.hiviewTrace = SplitMsg(recvBuf); bytrace.CpTraceFile(); + } else if (iterator->first == MessageType::CATCH_TRACE_FINISH) { + tracefilePath = ""; + GetSocketPort(recvBuf); + ConnectAndSendFile(spSocket, tracefilePath); } else if (iterator->first == MessageType::GET_CPU_NUM) { retCode = SPUtils::GetCpuNum(); spSocket.Sendto(retCode); diff --git a/smartperf_device/device_command/services/task_mgr/include/argument_parser.h b/smartperf_device/device_command/services/task_mgr/include/argument_parser.h index 38df95ff35353a73cb83222e72483746fc7f71a5..d2765082bc969af52fc0eb276c2f93ebd11f4cac 100644 --- a/smartperf_device/device_command/services/task_mgr/include/argument_parser.h +++ b/smartperf_device/device_command/services/task_mgr/include/argument_parser.h @@ -115,7 +115,6 @@ private: {"-lockfreq", {ArgumentParser::ArgType::BOOL}}, {"-nav", {ArgumentParser::ArgType::BOOL}}, {"-SESSIONID", {ArgumentParser::ArgType::STRING, "session id"}}, - {"-aischedule", {ArgumentParser::ArgType::BOOL, "get AI schedule status"}}, // UDP {"-CPU", {ArgumentParser::ArgType::BOOL}}, @@ -130,7 +129,7 @@ private: {"-DDR", {ArgumentParser::ArgType::BOOL}}, {"-NET", {ArgumentParser::ArgType::BOOL}}, {"-HCI", {ArgumentParser::ArgType::BOOL}}, - {"-trace", {ArgumentParser::ArgType::BOOL}}, + {"-TRACE", {ArgumentParser::ArgType::BOOL}}, }; std::unordered_map values_; std::vector errors_; diff --git a/smartperf_device/device_command/services/task_mgr/include/task_manager.h b/smartperf_device/device_command/services/task_mgr/include/task_manager.h index b6d6a743d5fe781501f8370cb89de5326ec3c8f3..1b5e7a7ff95aa2bec6de6f6cf8dba607bcab26f7 100644 --- a/smartperf_device/device_command/services/task_mgr/include/task_manager.h +++ b/smartperf_device/device_command/services/task_mgr/include/task_manager.h @@ -35,7 +35,7 @@ public: class TaskManager { public: - TaskManager(bool isIPC = false); + explicit TaskManager(bool isIPC = false); void AddTask(const std::unordered_map& argv); void AddTask(const std::string& argv); @@ -68,15 +68,16 @@ private: void SaveRegularly(std::chrono::steady_clock::time_point& loopEnd); void ProcessCurrentBatch(std::map& data); void ProcessOnceTask(bool start); + void MainLoop(); void GpuCounterProcess(const ArgumentParser::ArgValue& value); - void SpecialKeyProcess(const std::string& specKey); + void SpecialKeyProcess(const std::string specKey); ThreadPool threadPool_ {4}; int32_t collectCount_ {-1}; std::atomic_bool running_ {false}; std::thread mainLoop_; - std::vector normalTask_; - std::vector priorityTask_; + std::set normalTask_; + std::set priorityTask_; std::map> datas_; std::mutex mtx_; std::string fileName_ {"/data/local/tmp/data.csv"}; diff --git a/smartperf_device/device_command/services/task_mgr/src/argument_parser.cpp b/smartperf_device/device_command/services/task_mgr/src/argument_parser.cpp index 66bd6385671371d24c98c45bb82992b7be1201e8..318c1c8988f0e3045db9bece23cf9adbf1799f7b 100644 --- a/smartperf_device/device_command/services/task_mgr/src/argument_parser.cpp +++ b/smartperf_device/device_command/services/task_mgr/src/argument_parser.cpp @@ -72,7 +72,6 @@ void ArgumentParser::HandleIntParameter(const std::string& key, std::string valu { if (spec.type == ArgType::INT) { int val = SPUtilesTye::StringToSometype(value); - if (spec.min && val < *spec.min) { errors_.push_back("Value for " + key + " below min: " + std::to_string(*spec.min)); return; diff --git a/smartperf_device/device_command/services/task_mgr/src/sp_task.cpp b/smartperf_device/device_command/services/task_mgr/src/sp_task.cpp index 47abc793c2cb9ca6a40ad0086aec0e83d718b754..6152de17ba2de78058ab93ec0eac154dffc9b6bb 100644 --- a/smartperf_device/device_command/services/task_mgr/src/sp_task.cpp +++ b/smartperf_device/device_command/services/task_mgr/src/sp_task.cpp @@ -453,7 +453,6 @@ void SPTask::ClearStopFlag() gpuCounter.GetInstance().SaveData(outGpuCounterDataPath); } - gpuCounter.GetGpuCounterData().clear(); Capture::GetInstance().SetCollectionNum(); KillHiperfCmd(); } diff --git a/smartperf_device/device_command/services/task_mgr/src/task_manager.cpp b/smartperf_device/device_command/services/task_mgr/src/task_manager.cpp index 39432b438444dedd956229d4a2328ff20efd4b55..ba3112ff88c476e9a63e3473b0f4cbcb0c688267 100644 --- a/smartperf_device/device_command/services/task_mgr/src/task_manager.cpp +++ b/smartperf_device/device_command/services/task_mgr/src/task_manager.cpp @@ -96,12 +96,12 @@ void TaskManager::GpuCounterProcess(const ArgumentParser::ArgValue& value) GpuCounter::GetInstance().SetFrequency(frequency); } else { LOGW("GPU_COUNTER frequency must be a factor of 50 and in range [50,1000], " + - "this frequency is %d, set to 50", frequency); + "this frequency is %d, set to 50", frequency); GpuCounter::GetInstance().SetFrequency(defaultFreq); } } -void TaskManager::SpecialKeyProcess(const std::string& specKey) +void TaskManager::SpecialKeyProcess(const std::string specKey) { if (specKey == "-LOW_POWER") { FPS::GetInstance().hapLowFpsFlag = true; @@ -155,9 +155,9 @@ void TaskManager::AddTask(const std::unordered_mapipcCallback_ = ipcCallback_; if (iter->second == CommandType::CT_C || iter->second == CommandType::CT_P) { - priorityTask_.emplace_back(pro); + priorityTask_.insert(pro); } else { - normalTask_.emplace_back(pro); + normalTask_.insert(pro); } } } @@ -175,7 +175,7 @@ void TaskManager::AddTask(SpProfiler* task, bool priority) return; } LOGD("Start the collection in the start/stop mode"); - priority ? priorityTask_.emplace_back(task) : normalTask_.emplace_back(task); + priority ? priorityTask_.insert(task) : normalTask_.insert(task); } void TaskManager::AddTask(std::vector& argv) @@ -253,6 +253,7 @@ void TaskManager::SaveRegularly(std::chrono::steady_clock::time_point& loopEnd) if (!recordData_) { return; } + if ((loopEnd - currentTimePoint_) >= std::chrono::minutes(SAVE_DATA_INTERVAL_MINUTE) && !(SpProfilerFactory::editorFlag)) { std::unique_lock lock(mtx_); @@ -276,7 +277,6 @@ void TaskManager::SaveRegularly(std::chrono::steady_clock::time_point& loopEnd) void TaskManager::Start(bool record) { if (priorityTask_.empty() && normalTask_.empty()) { - LOGD("No mission"); return; } ProcessOnceTask(true); @@ -286,49 +286,56 @@ void TaskManager::Start(bool record) SetRecordState(true); } mainLoop_ = std::thread([this]() { - while (running_) { - auto loopStart = std::chrono::steady_clock::now(); - bool recordData = recordData_.load(); - if (dataIndex_++ == collectCount_) { - break; - } - LOGD("data index: %u", dataIndex_); - std::map currDatas; - currDatas.emplace("timestamp", std::to_string(SPUtils::GetCurTime())); - if (recordData) { - datas_.emplace(dataIndex_, - std::map{{"timestamp", std::to_string(SPUtils::GetCurTime())}}); - } - for (auto& item : priorityTask_) { - currDatas.merge(threadPool_.PushTask(&TaskManager::TaskFun, this, item, dataIndex_, recordData).get()); - } - std::vector>> result; - for (auto& item : normalTask_) { - result.emplace_back(threadPool_.PushTask(&TaskManager::TaskFun, this, item, dataIndex_, recordData)); - } - for (auto& item : result) { - currDatas.merge(item.get()); - } - for (auto& item : OHOS::SmartPerf::GpuCounter::GetInstance().GetGpuRealtimeData()) { - currDatas.insert(item); - } - if (nextTime_ != nullptr) { - *nextTime_ = SPUtils::GetCurTime(); - } - ProcessCurrentBatch(currDatas); - auto loopEnd = std::chrono::steady_clock::now(); - SaveRegularly(loopEnd); - auto elapsed = std::chrono::duration_cast(loopEnd - loopStart); - if (elapsed < std::chrono::seconds(1)) { - std::this_thread::sleep_for(std::chrono::seconds(1) - elapsed); - } - } - LOGD("main loop exit"); - ProcessOnceTask(false); - finishCond_.notify_all(); + MainLoop(); }); } +void TaskManager::MainLoop() +{ + while (running_) { + auto loopStart = std::chrono::steady_clock::now(); + bool recordData = recordData_.load(); + if (dataIndex_++ == collectCount_) { + break; + } + LOGD("data index: %u", dataIndex_); + std::map currDatas; + currDatas.emplace("timestamp", std::to_string(SPUtils::GetCurTime())); + if (recordData) { + datas_.emplace(dataIndex_, + std::map{{"timestamp", std::to_string(SPUtils::GetCurTime())}}); + } + for (auto& item : priorityTask_) { + currDatas.merge(threadPool_.PushTask(&TaskManager::TaskFun, this, item, dataIndex_, recordData).get()); + } + std::vector>> result; + for (auto& item : normalTask_) { + result.emplace_back(threadPool_.PushTask(&TaskManager::TaskFun, this, item, dataIndex_, recordData)); + } + for (auto& item : result) { + currDatas.merge(item.get()); + } + for (auto& item : OHOS::SmartPerf::GpuCounter::GetInstance().GetGpuRealtimeData()) { + currDatas.insert(item); + } + if (nextTime_ != nullptr) { + *nextTime_ = SPUtils::GetCurTime(); + } + ProcessCurrentBatch(currDatas); + auto loopEnd = std::chrono::steady_clock::now(); + SaveRegularly(loopEnd); + auto elapsed = std::chrono::duration_cast(loopEnd - loopStart); + if (elapsed < std::chrono::seconds(1)) { + std::this_thread::sleep_for(std::chrono::seconds(1) - elapsed); + } + } + LOGD("main loop exit"); + ProcessOnceTask(false); + running_ = false; + finishCond_.notify_all(); + scheduleSaveDataCond_.notify_all(); +} + void TaskManager::WriteToCSV() { std::unique_lock lock(mtx_); @@ -397,7 +404,6 @@ void TaskManager::Stop(bool pause) } mainLoop_.join(); } - if (scheduleSaveDataTh_.joinable()) { { std::lock_guard lock(mtx_); @@ -406,7 +412,6 @@ void TaskManager::Stop(bool pause) scheduleSaveDataCond_.notify_all(); scheduleSaveDataTh_.join(); } - if (!pause) { LOGD("Start/Stop Collection End"); threadPool_.Stop(); @@ -416,7 +421,7 @@ void TaskManager::Stop(bool pause) void TaskManager::Wait() { std::unique_lock lock(finishMtx_); - finishCond_.wait(lock); + finishCond_.wait(lock, [this] { return !running_.load(); }); } void TaskManager::CollectData(std::map>& datas) diff --git a/smartperf_device/device_command/smartperf_main.cpp b/smartperf_device/device_command/smartperf_main.cpp index 9c628c91fc420999fbf8bd81b07ff4bf1fd7dbb8..beaeeab3a96a93bd8f21af46ca0d860b0c194db2 100644 --- a/smartperf_device/device_command/smartperf_main.cpp +++ b/smartperf_device/device_command/smartperf_main.cpp @@ -95,7 +95,7 @@ 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) { + for (auto& a : OHOS::SmartPerf::COMMAND_SHELL_MAP) { keys.insert(a.first.substr(1)); // No prefix required '-' } @@ -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); } @@ -113,6 +115,35 @@ static void SocketStopCommand() cc.SocketStop(); } +static void SocketStartCommand(int argc, char *argv[]) +{ + OHOS::SmartPerf::SPUtils::KillStartDaemon(); + std::string startStr = ""; + std::string endStr = ""; + std::string pidCmd = OHOS::SmartPerf::CMD_COMMAND_MAP.at(OHOS::SmartPerf::CmdCommand::PIDOF_SP); + OHOS::SmartPerf::SPUtils::LoadCmd(pidCmd, startStr); + OHOS::SmartPerf::ClientControl cc; + cc.StartSPDaemon(); + OHOS::SmartPerf::SPUtils::LoadCmd(pidCmd, endStr); + std::vector startParams; + std::vector endParams; + OHOS::SmartPerf::SPUtils::StrSplit(startStr, " ", startParams); + OHOS::SmartPerf::SPUtils::StrSplit(endStr, " ", endParams); + std::string result; + const int maxExpectedArgs = 100; + for (int i = 2; i < argc && i < maxExpectedArgs; i++) { + result += argv[i]; + if (i != argc - 1) { + result += " "; + } + } + if (startParams.size() == endParams.size()) { + std::cout << "The last collection is interrupted." << std::endl; + std::cout << "SP_daemon -start " << result << " started collecting..." << std::endl; + } + cc.SocketStart(result); +} + static void RecordCapacity() { const std::string capacityRmPath = "/sys/class/power_supply/Battery/capacity_rm"; @@ -173,31 +204,7 @@ static int ProcessSpecificParameter(int argc, char *argv[], std::vector 1 && strcmp(argv[1], "-start") == 0) { - OHOS::SmartPerf::SPUtils::KillStartDaemon(); - std::string startStr = ""; - std::string endStr = ""; - std::string pidCmd = OHOS::SmartPerf::CMD_COMMAND_MAP.at(OHOS::SmartPerf::CmdCommand::PIDOF_SP); - OHOS::SmartPerf::SPUtils::LoadCmd(pidCmd, startStr); - OHOS::SmartPerf::ClientControl cc; - cc.StartSPDaemon(); - OHOS::SmartPerf::SPUtils::LoadCmd(pidCmd, endStr); - std::vector startParams; - std::vector endParams; - OHOS::SmartPerf::SPUtils::StrSplit(startStr, " ", startParams); - OHOS::SmartPerf::SPUtils::StrSplit(endStr, " ", endParams); - std::string result; - const int maxExpectedArgs = 100; - for (int i = 2; i < argc && i < maxExpectedArgs; i++) { - result += argv[i]; - if (i != argc - 1) { - result += " "; - } - } - if (startParams.size() == endParams.size()) { - std::cout << "The last collection is interrupted." << std::endl; - std::cout << "SP_daemon -start " << result << " started collecting..." << std::endl; - } - cc.SocketStart(result); + SocketStartCommand(argc, argv); std::cout << "command exec finished!" << std::endl; return 0; } else if (argc > 1 && strcmp(argv[1], "-stop") == 0) { @@ -214,7 +221,6 @@ static int ProcessSpecificParameter(int argc, char *argv[], std::vector result; + + auto actualResult = fps.GetFpsAndJitters(fpsInfoResult, result); + + EXPECT_EQ(fpsInfoResult.fps, 124); + EXPECT_EQ(actualResult["fps"], "124"); + EXPECT_EQ(actualResult["fpsJitters"], "10;;20;;30"); +} + +HWTEST_F(SPdaemonFpsTest, GetFpsAndJittersTest02, TestSize.Level0) +{ + FPS &fps = FPS::GetInstance(); + FpsInfo fpsInfoResult; + fpsInfoResult.jitters = {100, 200, 300}; + std::map result; + + std::map actualResult = fps.GetFpsAndJitters(fpsInfoResult, result); + + EXPECT_EQ(actualResult["fpsJitters"], "100;;200;;300"); +} + +HWTEST_F(SPdaemonFpsTest, GetFpsAndJittersTest03, TestSize.Level0) +{ + FPS &fps = FPS::GetInstance(); + FpsInfo fpsInfoResult; + std::map result; + + std::map actualResult = fps.GetFpsAndJitters(fpsInfoResult, result); + + EXPECT_NE(actualResult.find("fpsJitters"), actualResult.end()); +} + +HWTEST_F(SPdaemonFpsTest, GetFpsAndJittersTest04, TestSize.Level0) +{ + FPS &fps = FPS::GetInstance(); + FpsInfo fpsInfoResult; + fpsInfoResult.fps = 120; + fpsInfoResult.jitters = {100, 200, 300}; + std::map result; + + std::map actualResult = fps.GetFpsAndJitters(fpsInfoResult, result); + + EXPECT_NE(actualResult.find("fps"), actualResult.end()); + EXPECT_NE(actualResult.find("fpsJitters"), actualResult.end()); +} } } \ No newline at end of file diff --git a/smartperf_device/device_command/test/unittest/sp_task_test.cpp b/smartperf_device/device_command/test/unittest/sp_task_test.cpp index b3f5b66be117e78f1f2a1a866aa39377a8ae885d..724c41e00e4886dd81c155a83b37743b281a469d 100644 --- a/smartperf_device/device_command/test/unittest/sp_task_test.cpp +++ b/smartperf_device/device_command/test/unittest/sp_task_test.cpp @@ -27,6 +27,7 @@ #include "sp_task.h" #include "parameters.h" #include "GPU.h" +#include "effective.h" using namespace testing::ext; using namespace std; diff --git a/smartperf_device/device_command/test/unittest/sp_utils_test.cpp b/smartperf_device/device_command/test/unittest/sp_utils_test.cpp index b027c9be4eadf848e0e806d926d9461a3ca3c00d..397387a27265f92ed31da6a0cc32a739b521aed0 100644 --- a/smartperf_device/device_command/test/unittest/sp_utils_test.cpp +++ b/smartperf_device/device_command/test/unittest/sp_utils_test.cpp @@ -295,31 +295,19 @@ HWTEST_F(SPdaemonUtilsTest, IntegerValueVerificationTest01, TestSize.Level1) HWTEST_F(SPdaemonUtilsTest, IntegerValueVerificationTest02, TestSize.Level1) { - std::string errorInfo = ""; - std::string outOfRangeString = "123a456"; - bool result = SPUtils::IntegerVerification(outOfRangeString, errorInfo); - EXPECT_FALSE(result); + std::string errorInfo; + std::string longString(11, '1'); + EXPECT_FALSE(SPUtils::IntegerVerification(longString, errorInfo)); EXPECT_EQ(errorInfo, "invalid option parameters"); } HWTEST_F(SPdaemonUtilsTest, IntegerValueVerificationTest03, TestSize.Level1) { - std::string errorInfo = ""; - std::string outOfRangeString = "12345678901"; - bool result = SPUtils::IntegerVerification(outOfRangeString, errorInfo); - EXPECT_FALSE(result); + std::string errorInfo; + EXPECT_FALSE(SPUtils::IntegerVerification("123a456", errorInfo)); EXPECT_EQ(errorInfo, "invalid option parameters"); } -HWTEST_F(SPdaemonUtilsTest, IntegerValueVerificationTest04, TestSize.Level1) -{ - std::string errorInfo = ""; - std::string outOfRangeString = "000123"; - bool result = SPUtils::IntegerVerification(outOfRangeString, errorInfo); - EXPECT_TRUE(result); - EXPECT_TRUE(errorInfo.empty()); -} - HWTEST_F(SPdaemonUtilsTest, IntegerValueVerificationTest05, TestSize.Level1) { std::string errorInfo = ""; diff --git a/smartperf_device/device_command/utils/src/sp_profiler_factory.cpp b/smartperf_device/device_command/utils/src/sp_profiler_factory.cpp index de8dc3377a0a1da77651ebb0ee3303e9d76baa35..cd2270e4549ef0e01ad378bf1a58aa0635eda385 100644 --- a/smartperf_device/device_command/utils/src/sp_profiler_factory.cpp +++ b/smartperf_device/device_command/utils/src/sp_profiler_factory.cpp @@ -179,8 +179,8 @@ SpProfiler *SpProfilerFactory::GetCmdProfilerItemOption(CommandType commandType, break; case CommandType::CT_TRACE: ByTrace::GetInstance().SetByTrace(); - profiler = &ByTrace::GetInstance(); FPS::GetInstance().SetTraceCatch(); + profiler = &ByTrace::GetInstance(); break; case CommandType::CT_AS: profiler = &AISchedule::GetInstance(); diff --git a/smartperf_device/device_command/utils/src/sp_utils.cpp b/smartperf_device/device_command/utils/src/sp_utils.cpp index 29f10195a131c340d703df7336cb7410d8a5faa3..5e4e3dd064e7ff061db300a35c46cc8bd033851d 100644 --- a/smartperf_device/device_command/utils/src/sp_utils.cpp +++ b/smartperf_device/device_command/utils/src/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; } @@ -853,10 +886,11 @@ int& SPUtils::GetTtyDeviceFd() void SPUtils::GetTestsaPlugin(int command) { -#ifdef ARKTEST_ENABLE + #ifdef ARKTEST_ENABLE + //Call the function std::string stopJsonString = "{\"command\": \"stopCollect\"}"; OHOS::testserver::TestServerClient::GetInstance().SpDaemonProcess(command, stopJsonString); -#endif + #endif } void SPUtils::KillStartDaemon()