From c5689fd592136a26343b66afc3e26156be487b66 Mon Sep 17 00:00:00 2001 From: zhaohui Date: Tue, 21 Jun 2022 19:01:10 +0800 Subject: [PATCH] Modify SmartPerf delete Native app way Signed-off-by: zhaohui --- host/smartperf/client/client_command/BUILD.gn | 1 + .../client/client_command/Capture.cpp | 36 ++++ host/smartperf/client/client_command/FPS.cpp | 10 +- host/smartperf/client/client_command/GPU.cpp | 12 +- host/smartperf/client/client_command/RAM.cpp | 1 - .../include/Capture.h} | 38 ++-- .../client/client_command/include/FPS.h | 2 + .../client/client_command/include/GPU.h | 11 +- .../client_command/include/sp_thread_socket.h | 4 + .../client_command/smartperf_command.cpp | 4 + .../client_command/sp_profiler_factory.cpp | 6 + host/smartperf/client/client_ui/BUILD.gn | 1 - host/smartperf/client/client_ui/README_zh.md | 31 +++- .../client/client_ui/entry/build-profile.json | 10 +- .../client_ui/entry/src/main/cpp/BUILD.gn | 48 ----- .../entry/src/main/cpp/CMakeLists.txt | 10 - .../client_ui/entry/src/main/cpp/FPS.cpp | 173 ------------------ .../client/client_ui/entry/src/main/cpp/FPS.h | 54 ------ .../client_ui/entry/src/main/cpp/RAM.cpp | 63 ------- .../client_ui/entry/src/main/cpp/gp_utils.cpp | 105 ----------- .../client_ui/entry/src/main/cpp/gp_utils.h | 34 ---- .../client_ui/entry/src/main/cpp/profiler.cpp | 147 --------------- .../main/cpp/types/libsmartperf/index.d.ts | 23 --- .../main/cpp/types/libsmartperf/package.json | 4 - .../src/main/ets/MainAbility/MainAbility.ts | 41 +---- .../ets/common/profiler/MainWorkProfiler.ts | 2 + .../main/ets/common/profiler/NativeTaskFun.ts | 54 ------ .../main/ets/common/profiler/ProfilerTask.ets | 9 +- .../src/main/ets/common/profiler/item/CPU.ets | 12 +- .../src/main/ets/common/profiler/item/FPS.ets | 39 ++-- .../profiler/item/{NetWork.ets => NetWork.ts} | 0 .../src/main/ets/common/profiler/item/RAM.ets | 16 +- .../entry/src/main/ets/pages/FloatBall.ets | 10 +- .../entry/src/main/ets/pages/LoginPage.ets | 10 +- .../entry/src/main/ets/workers/worker.js | 119 +++++------- .../common/component/detail/Temperature.ets | 1 - .../src/main/ets/pages/TitleWindowPage.ets | 2 +- 37 files changed, 229 insertions(+), 914 deletions(-) create mode 100644 host/smartperf/client/client_command/Capture.cpp rename host/smartperf/client/{client_ui/entry/src/main/cpp/RAM.h => client_command/include/Capture.h} (50%) delete mode 100644 host/smartperf/client/client_ui/entry/src/main/cpp/BUILD.gn delete mode 100644 host/smartperf/client/client_ui/entry/src/main/cpp/CMakeLists.txt delete mode 100644 host/smartperf/client/client_ui/entry/src/main/cpp/FPS.cpp delete mode 100644 host/smartperf/client/client_ui/entry/src/main/cpp/FPS.h delete mode 100644 host/smartperf/client/client_ui/entry/src/main/cpp/RAM.cpp delete mode 100644 host/smartperf/client/client_ui/entry/src/main/cpp/gp_utils.cpp delete mode 100644 host/smartperf/client/client_ui/entry/src/main/cpp/gp_utils.h delete mode 100644 host/smartperf/client/client_ui/entry/src/main/cpp/profiler.cpp delete mode 100644 host/smartperf/client/client_ui/entry/src/main/cpp/types/libsmartperf/index.d.ts delete mode 100644 host/smartperf/client/client_ui/entry/src/main/cpp/types/libsmartperf/package.json delete mode 100644 host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/NativeTaskFun.ts rename host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/{NetWork.ets => NetWork.ts} (100%) diff --git a/host/smartperf/client/client_command/BUILD.gn b/host/smartperf/client/client_command/BUILD.gn index 795c66ca7..aa045dc6c 100644 --- a/host/smartperf/client/client_command/BUILD.gn +++ b/host/smartperf/client/client_command/BUILD.gn @@ -33,6 +33,7 @@ ohos_executable("SP_daemon") { sources = [ "ByTrace.cpp", "CPU.cpp", + "Capture.cpp", "DDR.cpp", "FPS.cpp", "GPU.cpp", diff --git a/host/smartperf/client/client_command/Capture.cpp b/host/smartperf/client/client_command/Capture.cpp new file mode 100644 index 000000000..85abf40a4 --- /dev/null +++ b/host/smartperf/client/client_command/Capture.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include "include/sp_utils.h" +#include "include/Capture.h" +namespace OHOS { +namespace SmartPerf { +void Capture::threadGetCatch(std::string curTime) +{ + std::string result; + std::string cmdCapture = "snapshot_display -f /data/local/tmp/capture/" + curTime +".png"; + SPUtils::LoadCmd(cmdCapture, result); + std::cout << "Screen Capture Thread >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl; +} +void Capture::TriggerGetCatch(long long curTime) +{ + std::string curTimeStr = std::to_string(curTime); + std::thread tStart(&Capture::threadGetCatch, this, curTimeStr); + tStart.detach(); +} +} +} diff --git a/host/smartperf/client/client_command/FPS.cpp b/host/smartperf/client/client_command/FPS.cpp index 47447bc47..71a5117b8 100644 --- a/host/smartperf/client/client_command/FPS.cpp +++ b/host/smartperf/client/client_command/FPS.cpp @@ -16,8 +16,10 @@ #include #include #include +#include #include "include/sp_utils.h" #include "include/ByTrace.h" +#include "include/Capture.h" #include "include/FPS.h" namespace OHOS { namespace SmartPerf { @@ -38,13 +40,19 @@ std::map FPS::ItemData() if (isCatchTrace > 0) { ByTrace::GetInstance().checkFpsJitters(fpsInfo.jitters); } - + if (isCapture > 0) { + Capture::GetInstance().TriggerGetCatch(SPUtils::GetCurTime()); + } return result; } void FPS::setTraceCatch() { isCatchTrace = 1; } +void FPS::setCaptureOn() +{ + isCapture = 1; +} void FPS::setPackageName(std::string pkgName) { pkg_name = std::move(pkgName); diff --git a/host/smartperf/client/client_command/GPU.cpp b/host/smartperf/client/client_command/GPU.cpp index d83cd7f17..fc449faa5 100644 --- a/host/smartperf/client/client_command/GPU.cpp +++ b/host/smartperf/client/client_command/GPU.cpp @@ -30,14 +30,22 @@ std::map GPU::ItemData() int GPU::getGpuFreq() { std::string gpuFreq; - SPUtils::LoadFile(gpuCurFreqPath, gpuFreq); + for (auto path : gpuCurFreqPaths) { + if (SPUtils::FileAccess(path)) { + SPUtils::LoadFile(path, gpuFreq); + } + } return atoi(gpuFreq.c_str()); } float GPU::getGpuLoad() { std::vector sps; std::string bufferLine; - SPUtils::LoadFile(gpuCurLoadPath, bufferLine); + for (auto path : gpuCurLoadPaths) { + if (SPUtils::FileAccess(path)) { + SPUtils::LoadFile(path, bufferLine); + } + } SPUtils::StrSplit(bufferLine, "@", sps); if (sps.size() > 0) { // rk3568 diff --git a/host/smartperf/client/client_command/RAM.cpp b/host/smartperf/client/client_command/RAM.cpp index 32fd27b91..72821e4b6 100644 --- a/host/smartperf/client/client_command/RAM.cpp +++ b/host/smartperf/client/client_command/RAM.cpp @@ -43,7 +43,6 @@ std::map RAM::getRamInfo() cmdGrep.str(""); cmdGrep << "/proc/" << processId << "/smaps_rollup"; std::string cmdRam = cmdGrep.str(); - std::cout << "RAM EXEC" << cmdRam << std::endl; std::ifstream infile(cmdRam.c_str(), std::ios::in); if (!infile) { return ramInfo; diff --git a/host/smartperf/client/client_ui/entry/src/main/cpp/RAM.h b/host/smartperf/client/client_command/include/Capture.h similarity index 50% rename from host/smartperf/client/client_ui/entry/src/main/cpp/RAM.h rename to host/smartperf/client/client_command/include/Capture.h index 997119f8f..28862170f 100644 --- a/host/smartperf/client/client_ui/entry/src/main/cpp/RAM.h +++ b/host/smartperf/client/client_command/include/Capture.h @@ -1,10 +1,10 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -12,20 +12,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef RAM_H -#define RAM_H -#include -#include - -class RAM { +#ifndef CAPTURE_H +#define CAPTURE_H +namespace OHOS { +namespace SmartPerf { +class Capture { public: - static pthread_mutex_t mutex; - static RAM* getInstance(); - std::map getRamInfo(std::string pid); + static Capture &GetInstance() + { + static Capture instance; + return instance; + } + // 截图线程 + void threadGetCatch(std::string curTime); + // 触发线程 + void TriggerGetCatch(long long curTime); private: - RAM(); - ~RAM(){}; - static RAM* instance; + Capture() {}; + Capture(const Capture &); + Capture &operator = (const Capture &); }; - -#endif +} +} +#endif \ No newline at end of file diff --git a/host/smartperf/client/client_command/include/FPS.h b/host/smartperf/client/client_command/include/FPS.h index bb81340ea..b67d61e88 100644 --- a/host/smartperf/client/client_command/include/FPS.h +++ b/host/smartperf/client/client_command/include/FPS.h @@ -37,6 +37,7 @@ struct FpsInfo { class FPS : public SpProfiler { public: void setPackageName(std::string pkgName); + void setCaptureOn(); void setTraceCatch(); FpsInfo getFpsInfo(); FpsInfo m_fpsInfo; @@ -55,6 +56,7 @@ private: std::string pkg_name; std::string cur_layer_name; int isCatchTrace = 0; + int isCapture = 0; FpsInfo GetSurfaceFrame(std::string name); }; } diff --git a/host/smartperf/client/client_command/include/GPU.h b/host/smartperf/client/client_command/include/GPU.h index ba7997408..db01dbd3c 100644 --- a/host/smartperf/client/client_command/include/GPU.h +++ b/host/smartperf/client/client_command/include/GPU.h @@ -15,6 +15,7 @@ #ifndef GPU_H #define GPU_H +#include #include "sp_profiler.h" namespace OHOS { namespace SmartPerf { @@ -34,8 +35,14 @@ private: GPU(const GPU &); GPU &operator = (const GPU &); - const std::string gpuCurFreqPath = "/sys/class/devfreq/gpufreq/cur_freq"; - const std::string gpuCurLoadPath = "/sys/class/devfreq/gpufreq/gpu_scene_aware/utilisation"; + const std::vector gpuCurFreqPaths = { + "/sys/class/devfreq/fde60000.gpu/cur_freq", // rk3568 + "/sys/class/devfreq/gpufreq/cur_freq", // wgr + }; + const std::vector gpuCurLoadPaths = { + "/sys/class/devfreq/gpufreq/gpu_scene_aware/utilisation", // wgr + "/sys/class/devfreq/fde60000.gpu/load", // rk3568 + }; }; } } diff --git a/host/smartperf/client/client_command/include/sp_thread_socket.h b/host/smartperf/client/client_command/include/sp_thread_socket.h index 0e55c3584..fb9a8ab58 100644 --- a/host/smartperf/client/client_command/include/sp_thread_socket.h +++ b/host/smartperf/client/client_command/include/sp_thread_socket.h @@ -71,8 +71,12 @@ public: if (SPUtils::LoadCmd(pidCmd, pidResult)) { SpProfilerFactory::setProfilerPid(pidResult); } + spSocket->Sendto(curPkgName); } else if (profiler == nullptr && (iterator->first == MessageType::SetProcessId)) { SpProfilerFactory::setProfilerPid(resPkgOrPid(spSocket)); + } else if (profiler == nullptr) { + std::string returnStr = iterator->second; + spSocket->Sendto(returnStr); } else { std::map data = profiler->ItemData(); std::string sendData = mapToString(data); diff --git a/host/smartperf/client/client_command/smartperf_command.cpp b/host/smartperf/client/client_command/smartperf_command.cpp index 76d9ea088..b9972e4bf 100644 --- a/host/smartperf/client/client_command/smartperf_command.cpp +++ b/host/smartperf/client/client_command/smartperf_command.cpp @@ -144,6 +144,10 @@ void SmartPerfCommand::initSomething() if (SPUtils::LoadCmd("chmod o+r /proc/stat", cmdResult) > 0) { printf("Privilege escalation! \n"); }; + if (!SPUtils::FileAccess("/data/local/tmp/capture")) { + SPUtils::LoadCmd("mkdir /data/local/tmp/capture", cmdResult); + printf("/data/local/tmp/capture created! \n"); + }; } } } diff --git a/host/smartperf/client/client_command/sp_profiler_factory.cpp b/host/smartperf/client/client_command/sp_profiler_factory.cpp index f7fe102fd..5e2d3f0ce 100644 --- a/host/smartperf/client/client_command/sp_profiler_factory.cpp +++ b/host/smartperf/client/client_command/sp_profiler_factory.cpp @@ -54,6 +54,9 @@ SpProfiler *SpProfilerFactory::getProfilerItem(MessageType messageType) case MessageType::CatchTraceStart: FPS::GetInstance().setTraceCatch(); break; + case MessageType::GetCapture: + FPS::GetInstance().setCaptureOn(); + break; default: break; } @@ -99,6 +102,9 @@ SpProfiler *SpProfilerFactory::getCmdProfilerItem(CommandType commandType) case CommandType::CT_TTRACE: FPS::GetInstance().setTraceCatch(); break; + case CommandType::CT_SNAPSHOT: + FPS::GetInstance().setCaptureOn(); + break; default: break; } diff --git a/host/smartperf/client/client_ui/BUILD.gn b/host/smartperf/client/client_ui/BUILD.gn index c10160c5e..bb45ff7b4 100644 --- a/host/smartperf/client/client_ui/BUILD.gn +++ b/host/smartperf/client/client_ui/BUILD.gn @@ -24,7 +24,6 @@ ohos_hap("SmartPerf") { part_name = "${OHOS_PROFILER_PART_NAME}" module_install_dir = "app/com.ohos.gameperceptio" js_build_mode = "debug" - shared_libraries = [ "entry/src/main/cpp:smartperf" ] } ohos_js_assets("smartperf_js_assets") { diff --git a/host/smartperf/client/client_ui/README_zh.md b/host/smartperf/client/client_ui/README_zh.md index 0772ae0c6..1c429e582 100644 --- a/host/smartperf/client/client_ui/README_zh.md +++ b/host/smartperf/client/client_ui/README_zh.md @@ -3,9 +3,30 @@ ## 二、如何使用 -- 步骤1:打开桌面预制的Smartperf工具;
+- 步骤1:进入shell中查看SP_daemon进程是否存在,没有则需启动SP_daemon进程(SP_daemon用于采集fps、ram等指标), 然后打开桌面的Smartperf工具;(采集指标少的时候一般为SP_daemon未启动,或者被后台清理)
+ +查看SP_daemon进程是否存在 +``` +C:\Users\test>hdc_std shell +# ps -ef | grep SP_daemon +root 4707 1 0 09:41:12 ? 00:00:00 SP_daemon +root 4711 4704 25 09:41:19 pts/0 00:00:00 grep SP_daemon +# + +``` +如果SP_daemon进程不存在启动SP_daemon +``` +C:\Users\test>hdc_std shell +# ps -ef | grep SP_daemon +root 4720 4718 6 09:48:43 pts/0 00:00:00 grep SP_daemon +# SP_daemon +# ps -ef | grep SP_daemon +root 4723 1 0 09:48:50 ? 00:00:00 SP_daemon +root 4727 4718 5 09:48:53 pts/0 00:00:00 grep SP_daemon +# +``` - 步骤2:点击登录,进入首页,点击开始测试页,选择被测应用,配置采集项(目前支持CPU、GPU、FPS、POWER、TEMP、RAM、截图能力、trace);
-- 步骤3:选择应用后根据应用类型选择是否是视频应用、是否是相机应用,点击开始测试、启动悬浮窗(左上角展示),会自动拉起应用,左上角悬浮窗展示start后点击即可开始,展示会变为计时状态,显示当前采集计时;(双击展开、关闭详情悬浮窗;长按结束任务保存数据;单击暂停、继续任务;点击详情悬浮窗后任意采集项会展开相应采集折线图)
+- 步骤3:选择应用后,点击开始测试、启动悬浮窗(左上角展示),会自动拉起应用,左上角悬浮窗展示start后点击即可开始,展示会变为计时状态,显示当前采集计时;(双击展开、关闭详情悬浮窗;长按结束任务保存数据;单击暂停、继续任务;点击详情悬浮窗后任意采集项会展开相应采集折线图)
- 步骤4:长按计时器,可以保存采集项数据,悬浮框消失;
- 步骤5:报告列表页查看报告,原始数据可在概览页对应路径自行使用hdc命令pull出来
@@ -19,8 +40,8 @@ | CPU负载 | 每1秒读取一次设备节点下各CPU的负载信息 | | GPU频率 | 每1秒读取一次设备节点下GPU的频点信息 | | GPU负载 | 每1秒读取一次设备节点下GPU的负载信息 | -| DDR频点 |每1秒读取一次设备节点下DDR的频点信息 | -| RAM |每1秒读取一次设备节点下DDR的频点信息 | +| DDR频点 | 每1秒读取一次设备节点下DDR的频点信息 | +| RAM | 每1秒读取一次应用进程的实际物理内存 | | 温度 | 每1秒读取一次读取一次设备节点下的soc温度等信息 | | 电流 | 每1秒读取一次设备节点下的电流信息 | | 电压 | 每1秒读取一次设备节点下电池的电压信息 | @@ -64,7 +85,7 @@ **1、关于截图、FPS、RAM、trace采集能力**
- 截图目录默认在/data/local/tmp/capture下。
- **Trace抓取:当帧绘制时间超过100ms以上会自动抓取trace,1min内只抓取1次,目录在/data目录下,trace文件较大,建议定期清除。** - **文件名称为:mynewtrace + 当前采集s数 + s:mynewtrace950s.ftrace** + **文件名称为:mynewtrace[当前时间戳].ftrace** **2、fps采集不到如何解决**
diff --git a/host/smartperf/client/client_ui/entry/build-profile.json b/host/smartperf/client/client_ui/entry/build-profile.json index 2c3591d89..aec46fb2f 100644 --- a/host/smartperf/client/client_ui/entry/build-profile.json +++ b/host/smartperf/client/client_ui/entry/build-profile.json @@ -1,15 +1,7 @@ { "apiType": "stageMode", "buildOption": { - "arkEnable": true, - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "-v -DOHOS_STL=c++_shared", - "abiFilters": [ - "armeabi-v7a" - ], - "cppFlags": "" - } + "arkEnable": true }, "targets": [ { diff --git a/host/smartperf/client/client_ui/entry/src/main/cpp/BUILD.gn b/host/smartperf/client/client_ui/entry/src/main/cpp/BUILD.gn deleted file mode 100644 index 87a17e003..000000000 --- a/host/smartperf/client/client_ui/entry/src/main/cpp/BUILD.gn +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import("//build/config/ohos/config.gni") -import("//build/ohos.gni") - -## Build so {{{ -config("config") { - visibility = [ ":*" ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Wunused-variable", - ] -} - -config("public_config") { -} - -ohos_shared_library("smartperf") { - sources = [ - "FPS.cpp", - "RAM.cpp", - "gp_utils.cpp", - "profiler.cpp", - ] - libs = [ "${clang_base_path}/lib/${abi_target}/c++/libc++.a" ] - include_dirs = [ "//developtools/profiler/host/smartperf/client/client_ui/entry/src/main/cpp" ] - configs = [ ":config" ] - - deps = [ "//foundation/arkui/napi:ace_napi" ] - - output_extension = "so" - subsystem_name = "developtools" - part_name = "profiler" -} -## Build so }}} diff --git a/host/smartperf/client/client_ui/entry/src/main/cpp/CMakeLists.txt b/host/smartperf/client/client_ui/entry/src/main/cpp/CMakeLists.txt deleted file mode 100644 index 46dd4766b..000000000 --- a/host/smartperf/client/client_ui/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(XComponent) - -set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - -include_directories(${NATIVERENDER_ROOT_PATH} - ${NATIVERENDER_ROOT_PATH}/include - ) -add_library(smartperf SHARED profiler.cpp gp_utils.cpp FPS.cpp RAM.cpp) -target_link_libraries(smartperf PUBLIC libace_napi.z.so libc++.a ) \ No newline at end of file diff --git a/host/smartperf/client/client_ui/entry/src/main/cpp/FPS.cpp b/host/smartperf/client/client_ui/entry/src/main/cpp/FPS.cpp deleted file mode 100644 index bc87a3eef..000000000 --- a/host/smartperf/client/client_ui/entry/src/main/cpp/FPS.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ - -#include -#include -#include -#include -#include -#include "gp_utils.h" -#include "FPS.h" - -pthread_mutex_t FPS::mutex; -FPS *FPS::instance = nullptr; -FPS *FPS::getInstance() -{ - if (instance == nullptr) { - pthread_mutex_lock(&mutex); - if (instance == nullptr) { - instance = new FPS(); - } - pthread_mutex_unlock(&mutex); - } - return instance; -} -FPS::FPS() -{ - pthread_mutex_init(&mutex, nullptr); -} -void FPS::setPackageName(std::string pkgName) -{ - pkg_name = std::move(pkgName); -} -FpsInfo FPS::getFpsInfo() -{ - FpsInfo fpsInfoMax; - fpsInfoMax.fps = -1; - - std::string layerName; - - std::vector sps; - gpUtils::mSplit(this->pkg_name, ".", sps); - std::string addEndChar = "0"; - const int pNameLastPos = 2; - std::string pkgSuffix = sps[pNameLastPos]; - layerName = std::string( pkgSuffix.c_str()+ addEndChar); - if (pkgSuffix.find("camera")!=std::string::npos) { - layerName = std::string("RosenRenderXComponent"); - } - - FpsInfo fpsInfo = GetSurfaceFrameDataGB(layerName); - if (fpsInfo.fps > fpsInfoMax.fps) { - fpsInfoMax = fpsInfo; - } - return fpsInfoMax; -} -FpsInfo FPS::GetSurfaceFrameDataGB(std::string name) -{ - if (name == "") { - return FpsInfo(); - } - static std::map fps_map; - if (fps_map.count(name) == 0) { - FpsInfo tmp; - tmp.fps = 0; - tmp.pre_fps = 0; - fps_map[name] = tmp; - } - FpsInfo &fpsInfo = fps_map[name]; - fpsInfo.fps = 0; - FILE *fp; - char tmp[1024]; - tmp[0] = '\0'; - std::string cmd = "hidumper -s 10 -a \"fps " + name + "\""; - fp = popen(cmd.c_str(), "r"); - if (fp == nullptr) { - return fpsInfo; - } - long long MOD = 1e9; - long long lastReadyTime = -1; - int fps_gb = 0; - if (!(fpsInfo.time_stamp_q).empty()) { - lastReadyTime = (fpsInfo.time_stamp_q).back(); - } - bool jump = false; - bool refresh = false; - int cnt = 0; - int zeroNum = 0; - while (fgets(tmp, sizeof(tmp), fp) != nullptr) { - long long frameReadyTime = 0; - std::stringstream sstream; - sstream << tmp; - sstream >> frameReadyTime; - cnt++; - if (frameReadyTime == 0) { - zeroNum++; - continue; - } - if (lastReadyTime >= frameReadyTime) { - lastReadyTime = -1; - continue; - } - refresh = true; - long long t_frameReadyTime = frameReadyTime / MOD; - long long t_lastReadyTime = lastReadyTime / MOD; - long long lastFrame = -1; - if (t_frameReadyTime == t_lastReadyTime) { - (fpsInfo.time_stamp_q).push(frameReadyTime); - } else if (t_frameReadyTime == t_lastReadyTime + 1) { - jump = true; - lastFrame = fpsInfo.last_frame_ready_time; - lastReadyTime = frameReadyTime; - int fps_tmp = 0; - fpsInfo.jitters.clear(); - while (!(fpsInfo.time_stamp_q).empty()) { - fps_tmp++; - long long currFrame = (fpsInfo.time_stamp_q.front()); - if (lastFrame != -1) { - long long jitter = currFrame - lastFrame; - fpsInfo.jitters.push_back(jitter); - } - lastFrame = currFrame; - (fpsInfo.time_stamp_q).pop(); - } - fps_gb = fps_tmp; - (fpsInfo.time_stamp_q).push(frameReadyTime); - fpsInfo.last_frame_ready_time = lastFrame; - } else if (t_frameReadyTime > t_lastReadyTime + 1) { - jump = true; - lastReadyTime = frameReadyTime; - while (!(fpsInfo.time_stamp_q).empty()) { - (fpsInfo.time_stamp_q).pop(); - } - (fpsInfo.time_stamp_q).push(frameReadyTime); - } - } - pclose(fp); - const int maxZeroNum = 120; - if (zeroNum >= maxZeroNum) { - while (!(fpsInfo.time_stamp_q.empty())) { - fpsInfo.time_stamp_q.pop(); - } - fpsInfo.fps = 0; - return fpsInfo; - } - const int minPrintLine = 5; - if (cnt < minPrintLine) { - fpsInfo.fps = fpsInfo.pre_fps; - return fpsInfo; - } - if (fps_gb > 0) { - fpsInfo.fps = fps_gb; - fpsInfo.pre_fps = fps_gb; - return fpsInfo; - } else if (refresh && !jump) { - fpsInfo.fps = fpsInfo.pre_fps; - return fpsInfo; - } else { - fpsInfo.fps = 0; - return fpsInfo; - } -} \ No newline at end of file diff --git a/host/smartperf/client/client_ui/entry/src/main/cpp/FPS.h b/host/smartperf/client/client_ui/entry/src/main/cpp/FPS.h deleted file mode 100644 index 79b8b5246..000000000 --- a/host/smartperf/client/client_ui/entry/src/main/cpp/FPS.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ -#ifndef FPS_H -#define FPS_H - -#include -#include -#include -#include -#include "pthread.h" -#include "gp_utils.h" - -struct FpsInfo { - int fps; - int pre_fps; - std::vector jitters; - std::queue time_stamp_q; - long long last_frame_ready_time; - long long current_fps_time; - FpsInfo() - { - fps = 0; - pre_fps = 0; - last_frame_ready_time = 0; - current_fps_time = 0; - } -}; -class FPS{ -public: - static FPS* getInstance(); - FpsInfo getFpsInfo(); - FpsInfo GetSurfaceFrameDataGB(std::string name); - void setPackageName(std::string pkgName); - std::string pkg_name; - static pthread_mutex_t mutex; -private: - FPS(); - ~FPS(){}; - static FPS* instance; -}; - -#endif // FPS_H diff --git a/host/smartperf/client/client_ui/entry/src/main/cpp/RAM.cpp b/host/smartperf/client/client_ui/entry/src/main/cpp/RAM.cpp deleted file mode 100644 index a5f3b4234..000000000 --- a/host/smartperf/client/client_ui/entry/src/main/cpp/RAM.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include -#include "gp_utils.h" -#include "RAM.h" - -pthread_mutex_t RAM::mutex; -RAM *RAM::instance = nullptr; -RAM *RAM::getInstance() -{ - if (instance == nullptr) - { - pthread_mutex_lock(&mutex); - if (instance == nullptr) - { - instance = new RAM(); - } - pthread_mutex_unlock(&mutex); - } - return instance; -} -RAM::RAM() -{ - pthread_mutex_init(&mutex, nullptr); -} - -std::map RAM::getRamInfo(std::string pid) -{ - std::map ramInfo; - std::string pss_value = ""; - ramInfo["pss"] = "-1"; - if (pid.size() > 0) { - std::ostringstream cmd_grep; - cmd_grep << "hidumper --mem "; - cmd_grep << pid; - std::string cmd = cmd_grep.str(); - std::string pidLine = gpUtils::readCmd(cmd); - std::vector sps; - gpUtils::mSplit(pidLine, " ", sps); - if (sps.size() > 0) { - pss_value = sps[1]; - } - } - if (atoi(pss_value.c_str()) > 0) { - ramInfo["pss"] = gpUtils::extractNumber(pss_value.c_str()); - } - return ramInfo; -} diff --git a/host/smartperf/client/client_ui/entry/src/main/cpp/gp_utils.cpp b/host/smartperf/client/client_ui/entry/src/main/cpp/gp_utils.cpp deleted file mode 100644 index fa86dc640..000000000 --- a/host/smartperf/client/client_ui/entry/src/main/cpp/gp_utils.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ -#include -#include -#include -#include "gp_utils.h" - -namespace gpUtils { - void mSplit(const std::string &content, const std::string &sp, std::vector &out) { - int index = 0; - while (index != std ::string::npos) { - int t_end = content.find_first_of(sp, index); - std::string tmp = content.substr(index, t_end - index); - if (tmp != "" && tmp != " ") - out.push_back(tmp); - if (t_end == std::string::npos) - break; - index = t_end + 1; - } - } - - bool canOpen(const std::string &path) { - FILE* fp = fopen(path.c_str(), "r"); - if (fp == nullptr) { - return false; - } - if (fclose(fp) == EOF) { - return false; - } - return true; - } - - bool canCmd(const std::string &cmd) { - FILE* pp = popen(cmd.c_str(), "r"); - if (pp == nullptr) { - return false; - } - pclose(pp); - return true; - } - - // popen - std::string readCmd(const std::string &cmd) - { - const int buffLength = 1024; - std::string res = "NA"; - FILE *pp = popen(cmd.c_str(), "r"); - if (pp == nullptr) { - return res; - } else { - char line[buffLength]; - line[0] = '\0'; - while (fgets(line, buffLength, pp) != nullptr) { - res = std::string(line); - } - } - pclose(pp); - return res; - } - - // fopen - std::string readFile(const std::string &path) - { - std::string res = "NA"; - const int buffLengh = 1024; - FILE *fp; - if ((fp = fopen(path.c_str(), "r")) != nullptr) { - char s[buffLengh]; - s[0] = '\0'; - while (fgets(s, sizeof(s), fp) != nullptr) { - res += std::string(s); - } - } - if (fp != nullptr) { - fclose(fp); - } - return res; - } - // get number_str from str - std::string extractNumber(const std::string &str) - { - int cntInt = 0; - const int shift = 10; - - for (int i = 0; str[i] != '\0'; ++i) { - if (str[i] >= '0' && str[i] <= '9') { - cntInt *= shift; - cntInt += str[i] - '0'; - } - } - return std::to_string(cntInt); - } -} \ No newline at end of file diff --git a/host/smartperf/client/client_ui/entry/src/main/cpp/gp_utils.h b/host/smartperf/client/client_ui/entry/src/main/cpp/gp_utils.h deleted file mode 100644 index e7054bfa2..000000000 --- a/host/smartperf/client/client_ui/entry/src/main/cpp/gp_utils.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - **/ -#ifndef GP_UTILS_H -#define GP_UTILS_H -#include -#include - -namespace gpUtils { - void mSplit(const std::string &content, const std::string &sp, std::vector& out); - - bool canOpen(const std::string &path); - - bool canCmd(const std::string &cmd); - - std::string extractNumber(const std::string &str); - - std::string readFile(const std::string &path); - - std::string readCmd(const std::string &cmd); -}; - -#endif // GP_UTILS_H diff --git a/host/smartperf/client/client_ui/entry/src/main/cpp/profiler.cpp b/host/smartperf/client/client_ui/entry/src/main/cpp/profiler.cpp deleted file mode 100644 index 9e0439154..000000000 --- a/host/smartperf/client/client_ui/entry/src/main/cpp/profiler.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "FPS.h" -#include "RAM.h" -#include "napi/native_api.h" -#include "gp_utils.h" - -namespace { - void collectFpsThread(std::promise &promiseObj) { - FpsInfo fpsInfo = FPS::getInstance()->getFpsInfo(); - promiseObj.set_value(fpsInfo); - } -} - - -static napi_value getFpsData(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = { nullptr }; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - napi_valuetype valuetype0; - napi_typeof(env, args[0], &valuetype0); - char pkgName[64] = {0}; - size_t typeLen = 0; - napi_get_value_string_utf8(env, args[0], pkgName, sizeof(pkgName) - 1, &typeLen); - FPS::getInstance()->setPackageName(pkgName); - - std::promise promiseObj; - std::future futureObj = promiseObj.get_future(); - std::thread tFps(collectFpsThread, ref(promiseObj)); - tFps.join(); - - FpsInfo fpsInfo = futureObj.get(); - std::string fps = std::to_string(fpsInfo.fps); - std::vector fpsJitters = fpsInfo.jitters; - std::string fps_str = fps + "|"; - for (int i = 0; i < fpsJitters.size(); ++i) { - fps_str += std::to_string(fpsJitters[i]); - fps_str += "=="; - } - napi_value fps_result; - napi_create_string_utf8(env, fps_str.c_str(), fps_str.size(), &fps_result); - return fps_result; -} - -static napi_value getRamData(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = { nullptr }; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - napi_valuetype valuetype0; - napi_typeof(env, args[0], &valuetype0); - char pidNumber[64] = {0}; - size_t typeLen = 0; - napi_get_value_string_utf8(env, args[0], pidNumber, sizeof(pidNumber) - 1, &typeLen); - std::map gramInfo = RAM::getInstance()->getRamInfo(pidNumber); - std::string ram_pss = gramInfo["pss"]; - napi_value ram_result; - napi_create_string_utf8(env, ram_pss.c_str(), ram_pss.size(), &ram_result); - return ram_result; -} - -static napi_value checkDaemon(napi_env env, napi_callback_info info) -{ - std::string status = "Dead"; - std::string spRunning = gpUtils::readCmd(std::string("ps -ef |grep SP_daemon |grep -v grep")); - if (spRunning.find("NA")!= std::string::npos) { - gpUtils::canCmd(std::string("SP_daemon")); - } else { - status = "Running"; - } - napi_value result; - napi_create_string_utf8(env, status.c_str(), status.size(), &result); - return result; -} - -static napi_value checkAccess(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = { nullptr }; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - napi_valuetype valuetype0; - napi_typeof(env, args[0], &valuetype0); - char pathName[64] = {0}; - size_t typeLen = 0; - napi_get_value_string_utf8(env, args[0], pathName, sizeof(pathName) - 1, &typeLen); - std::string pathNameStr = pathName; - std::string status = "PermissionDenied"; - bool isAccess = gpUtils::canOpen(pathNameStr); - if (isAccess) { - status = "PermissionAccessed"; - } - napi_value result; - napi_create_string_utf8(env, status.c_str(), status.size(), &result); - return result; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - { "getFpsData", nullptr, getFpsData, nullptr, nullptr, nullptr, napi_default, nullptr }, - { "getRamData", nullptr, getRamData, nullptr, nullptr, nullptr, napi_default, nullptr }, - { "checkDaemon", nullptr, checkDaemon, nullptr, nullptr, nullptr, napi_default, nullptr }, - { "checkAccess", nullptr, checkAccess, nullptr, nullptr, nullptr, napi_default, nullptr }, - }; - napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - return exports; -} -EXTERN_C_END - -static napi_module demoModule = { -.nm_version = 1, -.nm_flags = 0, -.nm_filename = nullptr, -.nm_register_func = Init, -.nm_modname = "libsmartperf", -.nm_priv = ((void *)0), -.reserved = { 0 }, -}; - -extern "C" __attribute__((constructor)) void RegisterModule(void) -{ -napi_module_register(&demoModule); -} diff --git a/host/smartperf/client/client_ui/entry/src/main/cpp/types/libsmartperf/index.d.ts b/host/smartperf/client/client_ui/entry/src/main/cpp/types/libsmartperf/index.d.ts deleted file mode 100644 index c678fb88d..000000000 --- a/host/smartperf/client/client_ui/entry/src/main/cpp/types/libsmartperf/index.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export const getFpsData: (pkg: string) => string - -export const getRamData: (pid: string) => string - -export const checkDaemon: () => string - -export const checkAccess: (path: string) => string - diff --git a/host/smartperf/client/client_ui/entry/src/main/cpp/types/libsmartperf/package.json b/host/smartperf/client/client_ui/entry/src/main/cpp/types/libsmartperf/package.json deleted file mode 100644 index 3af17c276..000000000 --- a/host/smartperf/client/client_ui/entry/src/main/cpp/types/libsmartperf/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "libsmartperf.so", - "types": "./index.d.ts" -} \ No newline at end of file diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/MainAbility/MainAbility.ts b/host/smartperf/client/client_ui/entry/src/main/ets/MainAbility/MainAbility.ts index d542ae1ca..cf71e1d0b 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/host/smartperf/client/client_ui/entry/src/main/ets/MainAbility/MainAbility.ts @@ -16,66 +16,37 @@ import Ability from '@ohos.application.Ability' import { initDb } from '../common/database/LocalRepository' import { FloatWindowFun } from '../common/ui/floatwindow/FloatWindowFun' -import { NativeTaskFun } from "../common/profiler/NativeTaskFun" import { NetWork } from '../common/profiler/item/NetWork'; +import { MainWorker } from '../common/profiler/MainWorkProfiler'; import BundleManager from '../common/utils/BundleMangerUtils'; -import SPLogger from '../common/utils/SPLogger' - var abilityWindowStage -const TAG = "MainAbility" - export default class MainAbility extends Ability { - onCreate(want, launchParam) { globalThis.showFloatingWindow=false - // Ability is creating, initialize resources for this ability BundleManager.getAppList().then(appList => { globalThis.appList = appList -// SPLogger.DEBUG(TAG,"appList-->" + JSON.stringify(appList)) -// SPLogger.DEBUG(TAG,"appList-->-->-->-->-->-->-->-->-->-->-->-->-->-->-->-->-->-->") -// SPLogger.DEBUG(TAG,"globalThis.appList-->" + JSON.stringify(globalThis.appList)) }) } - - onDestroy() { - // Ability is destroying, release resources for this ability -// SPLogger.DEBUG(TAG,"[MyApplication] MainAbility onDestroy") - } - + onDestroy() {} onWindowStageCreate(windowStage) { globalThis.abilityContext = this.context - globalThis.useDaemon = true - // Main window is created, set main page for this ability -// SPLogger.DEBUG(TAG,"[MyApplication] MainAbility onWindowStageCreate") abilityWindowStage = windowStage; abilityWindowStage.setUIContent(this.context, "pages/LoginPage", null) + globalThis.useDaemon = false } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources -// SPLogger.DEBUG(TAG,"[MyApplication] MainAbility onWindowStageDestroy") - } - + onWindowStageDestroy() {} onForeground() { initDb() - // Ability has brought to foreground FloatWindowFun.initAllFun() - NativeTaskFun.initAllFun() - //check netWork NetWork.getInstance().init() - } + MainWorker.postMessage({ "testConnection": true }) - onBackground() { - // Ability has back to background -// SPLogger.DEBUG(TAG,"[MyApplication] MainAbility onBackground") } + onBackground() {} }; -export function initTest() { - -} diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/MainWorkProfiler.ts b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/MainWorkProfiler.ts index d5fd05271..373afd17f 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/MainWorkProfiler.ts +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/MainWorkProfiler.ts @@ -36,6 +36,8 @@ MainWorker.onmessage = function (result) { let isSocketConnect = Number(arr[1]).valueOf() if (isSocketConnect > 0) { globalThis.useDaemon = true + }else{ + globalThis.useDaemon = false } default: break; diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/NativeTaskFun.ts b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/NativeTaskFun.ts deleted file mode 100644 index 9cd46ae49..000000000 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/NativeTaskFun.ts +++ /dev/null @@ -1,54 +0,0 @@ - -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { getPidOfAbility } from '../utils/SystemUtils'; -import SPLogger from '../utils/SPLogger' -import nativeProfiler from "libsmartperf.so" - - -const TAG = "NativeTaskFun" - -export class NativeTaskFun { - static initAllFun() { - globalThis.CreateNativeFps = ((pkgName: string) => { - let fpsStr: string = nativeProfiler.getFpsData(pkgName) -// SPLogger.DEBUG(TAG, "nativeProfiler" + "--> fpsStr:" + fpsStr) - return fpsStr - }) - globalThis.CreateNativeRam = (() => { - let ramStr: string = nativeProfiler.getRamData(globalThis.processPid) -// SPLogger.DEBUG(TAG, "nativeProfiler" + "--> ramStr :" + ramStr) - globalThis.ramArr.push(ramStr) - return ramStr - }) - - globalThis.CheckDaemon = (() => { - let status: string = nativeProfiler.checkDaemon() -// SPLogger.DEBUG(TAG, "nativeProfiler" + "--> daemon status :" + status) - return status - }) - - globalThis.checkAccess = ((path: string) => { -// SPLogger.DEBUG("BaseProfilerUtils","native check path is start..."+ "path:" + path); - let status: string = nativeProfiler.checkAccess(path) -// SPLogger.DEBUG("BaseProfilerUtils","native check path is finish..."+ "path:" + path); -// SPLogger.DEBUG(TAG, "nativeProfiler --> "+ path + " status :" + status) - return status - }) - - let status = globalThis.CheckDaemon() - SPLogger.DEBUG(TAG, "nativeProfiler" + "--> daemon status :" + status) - } -} diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/ProfilerTask.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/ProfilerTask.ets index 768dc02a5..1adc521cf 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/ProfilerTask.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/ProfilerTask.ets @@ -48,13 +48,6 @@ export class ProfilerTask { } } } - //默认不使用daemon -// globalThis.useDaemon = false -// let status = globalThis.CheckDaemon() -// if (status == "Running") { -// globalThis.useDaemon = true -// } -// SPLogger.DEBUG(ProfilerTask.name,'ProfilerTask initModule:Daemon status ' + status) } getSupports(keys:string[]){ @@ -103,7 +96,7 @@ export class ProfilerTask { if (typeCollect != null) { let gpData:GPData =typeCollect.readData() if(typeCollect instanceof CPU){ - typeCollect.readCPULoad() + gpDataArr.push(typeCollect.readCPULoad()) } gpDataArr.push(gpData) SPLogger.DEBUG(ProfilerTask.name,"profiler ProfilerTask:curData:"+gpData); diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/CPU.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/CPU.ets index 279478afd..46397a940 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/CPU.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/CPU.ets @@ -44,13 +44,11 @@ export class CPU extends BaseProfiler { } isSupport(){ - if(isAccess(CPU_CONFIG.CPU_BASE)&&isAccess(CPU_CONFIG.CPU_LOAD)){ - - if (globalThis.checkAccess(CPU_CONFIG.CPU_LOAD) == "PermissionAccessed") { - - return true - } - +// if(isAccess(CPU_CONFIG.CPU_BASE)&&isAccess(CPU_CONFIG.CPU_LOAD)){ +// return true +// } + if (globalThis.useDaemon) { + return true } return false } diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/FPS.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/FPS.ets index b0e285587..ede536cfc 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/FPS.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/FPS.ets @@ -12,10 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createGPData, extractNumber , isAccess} from '../base/BaseProfilerUtils'; +import { createGPData, extractNumber } from '../base/BaseProfilerUtils'; import { BaseProfiler } from '../base/BaseProfiler' import { CollectorType } from '../base/ProfilerConstant' import { SocketProfiler } from '../base/SocketProfiler' +import { MainWorker } from '../MainWorkProfiler' import SPLogger from '../../../common/utils/SPLogger' export class FPS extends BaseProfiler implements SocketProfiler { @@ -35,33 +36,39 @@ export class FPS extends BaseProfiler implements SocketProfiler { } isSupport(){ - return true + if (globalThis.useDaemon) { + return true + } + return false } readData() { -// if (globalThis.useDaemon) { -// this.readMessageQueue() -// } else { - let fpsStr: string = globalThis.CreateNativeFps(globalThis.collectPkg) - if (fpsStr.length > 0) { - let fpsArr = fpsStr.split("|") - this.fpsMap.set("fps", extractNumber(fpsArr[0])) - let fpsJitters = "\"" + fpsArr[1].split("==").join(",") + "\"" - this.fpsMap.set("fpsJitters", fpsJitters) - globalThis.fpsArr.push(fpsArr[0]) - globalThis.fpsJitterArr.push(fpsArr[1]) - globalThis.timerFps = fpsArr[0] - } -// } + if (globalThis.useDaemon) { + this.readMessageQueue() + } + // else { + // let fpsStr: string = globalThis.CreateNativeFps(globalThis.collectPkg) + // if (fpsStr.length > 0) { + // let fpsArr = fpsStr.split("|") + // this.fpsMap.set("fps", extractNumber(fpsArr[0])) + // let fpsJitters = "\"" + fpsArr[1].split("==").join(",") + "\"" + // this.fpsMap.set("fpsJitters", fpsJitters) + // globalThis.fpsArr.push(fpsArr[0]) + // globalThis.fpsJitterArr.push(fpsArr[1]) + // globalThis.timerFps = fpsArr[0] + // } + // } return createGPData("FPS", this.fpsMap) } readMessageQueue() { + MainWorker.postMessage({ "fps": true, "pkg": globalThis.collectPkg }) SPLogger.DEBUG(FPS.name, "messageQueue for fps" + globalThis.fpsArr.length) if (globalThis.fpsArr.length > 0) { let fpsQueue: Array = globalThis.fpsArr let fpsJitterQueue: Array = globalThis.fpsJitterArr let curFPS = fpsQueue.pop() + globalThis.timerFps = curFPS let curFPSJitter = fpsJitterQueue.pop() let fpsJitters = "\"" + curFPSJitter.split("==").join(",") + "\"" this.fpsMap.set("fpsJitters", fpsJitters) diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/NetWork.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/NetWork.ts similarity index 100% rename from host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/NetWork.ets rename to host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/NetWork.ts diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/RAM.ets b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/RAM.ets index 22465edcf..fccd8094f 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/RAM.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/common/profiler/item/RAM.ets @@ -34,18 +34,22 @@ export class RAM extends BaseProfiler implements SocketProfiler{ } isSupport(){ - return true + if (globalThis.useDaemon) { + return true + } + return false } readData() { if (globalThis.useDaemon) { this.readMessageQueue() - }else{ - let ramStr:string = globalThis.CreateNativeRam(globalThis.collectPkg) - if (ramStr.length > 0) { - this.ramMap.set("pss", ramStr) - } } + // else{ + // let ramStr:string = globalThis.CreateNativeRam(globalThis.collectPkg) + // if (ramStr.length > 0) { + // this.ramMap.set("pss", ramStr) + // } + // } return createGPData("RAM", this.ramMap) } readMessageQueue(){ diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/pages/FloatBall.ets b/host/smartperf/client/client_ui/entry/src/main/ets/pages/FloatBall.ets index f810138b0..9eee6da82 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/pages/FloatBall.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/pages/FloatBall.ets @@ -16,7 +16,7 @@ import { secToTime } from '../common/utils/TimeUtils'; import { TaskStatus } from '../common/profiler/base/ProfilerConstant'; import { ProfilerTask } from "../common/profiler/ProfilerTask" import { initFloatWindow,destoryAllFloatWindow } from '../common/ui/floatwindow/utils/FloatWindowUtils' - +import { MainWorker } from '../common/profiler/MainWorkProfiler' @Entry @Component @@ -62,6 +62,12 @@ struct FloatBall { initAllCollect() { console.log("collectIntervalCollect initAllCollect...."); if (globalThis.collectConfigs != -1 && globalThis.collectPkg != -1) { + if(globalThis.collectConfigs.screen_capture){ + MainWorker.postMessage({"screen_capture":true}) + } + if(globalThis.collectConfigs.trace){ + MainWorker.postMessage({"catch_trace_start":true}) + } globalThis.collectIntervalCollect = setInterval(() => { console.log("collectIntervalCollect running...."); if (this.playerState == TaskStatus.task_running) { @@ -99,8 +105,8 @@ struct FloatBall { } longEvent() { - this.destroyAllWindow() ProfilerTask.getInstance().taskStop() + this.destroyAllWindow() this.clearAllInterVal() } diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/pages/LoginPage.ets b/host/smartperf/client/client_ui/entry/src/main/ets/pages/LoginPage.ets index fdc357255..7b1f36bce 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/pages/LoginPage.ets +++ b/host/smartperf/client/client_ui/entry/src/main/ets/pages/LoginPage.ets @@ -12,17 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import router from '@system.router'; @Entry @Component struct Login { - aboutToAppear() { - console.log("cur router length:" + router.getLength()) - console.log("cur router state:" + router.getState()) - } - build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { Column() { @@ -38,9 +32,7 @@ struct Login { .height('45vp') .textAlign(TextAlign.Center) .onClick(() => { - router.push({ uri: 'pages/MainPage', params: { - title: "123" - } }) + router.push({ uri: 'pages/MainPage' }) }) } .width('100%') diff --git a/host/smartperf/client/client_ui/entry/src/main/ets/workers/worker.js b/host/smartperf/client/client_ui/entry/src/main/ets/workers/worker.js index fab810b91..aa1ebe8e5 100644 --- a/host/smartperf/client/client_ui/entry/src/main/ets/workers/worker.js +++ b/host/smartperf/client/client_ui/entry/src/main/ets/workers/worker.js @@ -16,7 +16,7 @@ import worker from '@ohos.worker'; // 导入worker模块 import net_socket from '@ohos.net.socket'; - +const workTag = "SmartPerf::Work:: " let parentPort = worker.parentPort; // 获取parentPort属性 export let IPv4 = 1 @@ -24,7 +24,7 @@ export let IPv4 = 1 export let IPv4BindAddr = { address: "127.0.0.1", family: IPv4, - port: 8283 + port: 8282 } export let UdpSendAddress = { @@ -38,76 +38,58 @@ export let flagPackageNum = 0 export let udp = net_socket.constructUDPSocketInstance() udp.bind(IPv4BindAddr, err => { if (err) { - console.log('Worker socket bind fail'); + console.log(workTag + 'Worker socket bind fail'); return; } - console.log('Worker socket bind success'); + console.log(workTag + 'Worker socket bind success'); udp.getState((err, data) => { if (err) { - console.log('Worker socket getState fail'); + console.log(workTag + 'Worker socket getState fail'); return; } - console.log('Worker socket getState success:' + JSON.stringify(data)); + console.log(workTag + 'Worker socket getState success:' + JSON.stringify(data)); }) }) - -parentPort.onexit = function (e) { - console.log("Worker onexit") -} - -parentPort.onerror = function (e) { - console.log("Worker onerror") -} - -parentPort.onmessageerror = function (e) { - console.log("Worker onmessageerror") -} - -udp.on('listening', () => { - console.log("Worker socket on listening success"); -}); -udp.on('close', () => { - console.log("Worker socket on close success"); -}); - -udp.on('error', err => { - console.log("Worker socket on error, err:" + JSON.stringify(err)) -}); parentPort.onmessage = function (e) { let socketCollectItems = e.data - console.log("sub worker recv:" + JSON.stringify(e.data)); + console.log(workTag + "sub worker recv:" + JSON.stringify(e.data)); let messageSetPkg = "set_pkgName::" + socketCollectItems.pkg udp.getState((err, data) => { if (err) { parentPort.postMessage("UdpStatus$-1") - console.log("Worker socket getState error", err); + console.log(workTag + "Worker socket getState error", err); } - console.log('Worker socket getState success:' + JSON.stringify(data)); + console.log(workTag + 'Worker socket getState success:' + JSON.stringify(data)); - parentPort.postMessage("UdpStatus$1") - if (flagPackageNum < 2) { - udp.send({ - address: UdpSendAddress, - data: messageSetPkg - }) - } - flagPackageNum++ - - if (socketCollectItems.fps) { - let messageFps = "get_fps_and_jitters::0::0" - if (socketCollectItems.is_video) { - messageFps = "get_fps_and_jitters::1::0" - } else if (socketCollectItems.is_camera) { - messageFps = "get_fps_and_jitters::0::1" + if (socketCollectItems.testConnection) { + for (let i = 0;i < 10; i++) { + udp.send({ + address: UdpSendAddress, + data: "set_pkgName::com.ohos.gameperceptio" + }) + console.log(workTag + "Worker socket test connection send"); } + } + + if (flagPackageNum < 2) { + if (socketCollectItems.pkg != undefined) { + udp.send({ + address: UdpSendAddress, + data: messageSetPkg + }) + flagPackageNum++ + } + } + if (socketCollectItems.fps) { + let messageFps = "get_fps_and_jitters" udp.send({ address: UdpSendAddress, data: messageFps }) - console.log("sub worker messageFps :" + messageFps); + console.log(workTag + "sub worker messageFps :" + messageFps); } if (socketCollectItems.ram) { @@ -116,24 +98,14 @@ parentPort.onmessage = function (e) { address: UdpSendAddress, data: messageRam }) - console.log("sub worker messageRam :" + messageRam); + console.log(workTag + "sub worker messageRam :" + messageRam); } - if (socketCollectItems.screen_capture) { udp.send({ address: UdpSendAddress, data: "get_capture" }) - console.log("sub worker screen_capture :" + screen_capture); - } - - if (socketCollectItems.power) { - let messagePower = "get_power" - udp.send({ - address: UdpSendAddress, - data: messagePower - }) - console.log("sub worker messagePower :" + messagePower); + console.log(workTag + "sub worker screen_capture :" + "get_capture"); } if (socketCollectItems.catch_trace_start) { let messageTrace = "catch_trace_start" @@ -141,16 +113,8 @@ parentPort.onmessage = function (e) { address: UdpSendAddress, data: messageTrace }) + console.log(workTag + "sub worker catch_trace_start :" + "catch_trace_start"); } - if (socketCollectItems.catch_trace_finish) { - let messageTrace = "catch_trace_finish::" + socketCollectItems.traceName - udp.send({ - address: UdpSendAddress, - data: messageTrace - }) - } - - }) } @@ -161,15 +125,18 @@ udp.on("message", function (data) { for (let i = 0;i < dataView.byteLength; ++i) { str += String.fromCharCode(dataView.getUint8(i)) } - console.log("sub worker Socket recv:" + str); + console.log(workTag + "sub worker SocketRecv:" + str); + if (str.length > 0) { + parentPort.postMessage("UdpStatus$1") + } try { if (includes(str, "pss")) { parentPort.postMessage("RAM$" + str) } else if (includes(str, "fps")) { if (str.indexOf("$$") != -1) { let arrStr = str.split("$$") - if(arrStr.length > 0){ - if(arrStr[0].indexOf("||") != -1 && arrStr[1].indexOf("||") != -1){ + if (arrStr.length > 0) { + if (arrStr[0].indexOf("||") != -1 && arrStr[1].indexOf("||") != -1) { let fps = arrStr[0].split("||") let fpsJitter = arrStr[1].split("||") parentPort.postMessage("FPS$" + fps[1].toString() + "$" + fpsJitter[1].toString()) @@ -178,7 +145,7 @@ udp.on("message", function (data) { } } } catch (e) { - console.log("SockOnMessage recv callback err:" + e) + console.log(workTag + "SockOnMessage recv callback err:" + e) } }) @@ -194,10 +161,8 @@ function includes(all, sub) { for (let i = 0; i < all.length - subLength + 1; i++) { - if (all.charAt(i) == firstChar) - { - if (all.substring(i, i + subLength) == sub) - { + if (all.charAt(i) == firstChar) { + if (all.substring(i, i + subLength) == sub) { return true; } } diff --git a/host/smartperf/client/client_ui_w/entry/src/main/ets/common/component/detail/Temperature.ets b/host/smartperf/client/client_ui_w/entry/src/main/ets/common/component/detail/Temperature.ets index 0dedc7b1f..5a54c60c9 100644 --- a/host/smartperf/client/client_ui_w/entry/src/main/ets/common/component/detail/Temperature.ets +++ b/host/smartperf/client/client_ui_w/entry/src/main/ets/common/component/detail/Temperature.ets @@ -685,7 +685,6 @@ export struct Temperature { Stack({ alignContent: Alignment.TopStart }) { Scroll() { Column({ space: 20 }) { - LineChart({lineChartModel: this.lineChartModel2}) Text("ShellFrontTemp(℃)") { }.fontWeight(FontWeight.Bold).fontColor(Color.Blue).fontSize('15fp').textAlign(TextAlign.Center) diff --git a/host/smartperf/client/client_ui_w/entry/src/main/ets/pages/TitleWindowPage.ets b/host/smartperf/client/client_ui_w/entry/src/main/ets/pages/TitleWindowPage.ets index df2036a94..ebd413b4b 100644 --- a/host/smartperf/client/client_ui_w/entry/src/main/ets/pages/TitleWindowPage.ets +++ b/host/smartperf/client/client_ui_w/entry/src/main/ets/pages/TitleWindowPage.ets @@ -24,7 +24,7 @@ struct TitleWindowPage { } else { this.FpsTimer = globalThis.timerFps } - this.currentNow = globalThis.tTndex.currentNow + this.currentNow = 0 - Number(globalThis.tTndex.currentNow) this.gpuFrequency = Number((globalThis.tTndex.gpuFrequency / 1e6).toFixed(2)).valueOf() this.gpuLoad = parseInt(globalThis.tTndex.gpuLoad) this.ddrFrequency = Number(globalThis.tTndex.ddrFrequency / 1e6).valueOf()