mirror of
https://gitee.com/openharmony/developtools_profiler
synced 2025-02-05 18:16:20 +00:00
Modify SmartPerf delete Native app way
Signed-off-by: zhaohui <zhaohui70@huawei.com>
This commit is contained in:
parent
8a869aeef6
commit
c5689fd592
@ -33,6 +33,7 @@ ohos_executable("SP_daemon") {
|
||||
sources = [
|
||||
"ByTrace.cpp",
|
||||
"CPU.cpp",
|
||||
"Capture.cpp",
|
||||
"DDR.cpp",
|
||||
"FPS.cpp",
|
||||
"GPU.cpp",
|
||||
|
36
host/smartperf/client/client_command/Capture.cpp
Normal file
36
host/smartperf/client/client_command/Capture.cpp
Normal file
@ -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 <iostream>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#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();
|
||||
}
|
||||
}
|
||||
}
|
@ -16,8 +16,10 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#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<std::string, std::string> 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);
|
||||
|
@ -30,14 +30,22 @@ std::map<std::string, std::string> 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<std::string> 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
|
||||
|
@ -43,7 +43,6 @@ std::map<std::string, std::string> 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;
|
||||
|
@ -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 <map>
|
||||
#include <string>
|
||||
|
||||
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<std::string, std::string> 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
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#ifndef GPU_H
|
||||
#define GPU_H
|
||||
#include <vector>
|
||||
#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<std::string> gpuCurFreqPaths = {
|
||||
"/sys/class/devfreq/fde60000.gpu/cur_freq", // rk3568
|
||||
"/sys/class/devfreq/gpufreq/cur_freq", // wgr
|
||||
};
|
||||
const std::vector<std::string> gpuCurLoadPaths = {
|
||||
"/sys/class/devfreq/gpufreq/gpu_scene_aware/utilisation", // wgr
|
||||
"/sys/class/devfreq/fde60000.gpu/load", // rk3568
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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<std::string, std::string> data = profiler->ItemData();
|
||||
std::string sendData = mapToString(data);
|
||||
|
@ -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");
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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") {
|
||||
|
@ -3,9 +3,30 @@
|
||||
|
||||
## 二、如何使用
|
||||
|
||||
- 步骤1:打开桌面预制的Smartperf工具;<br>
|
||||
- 步骤1:进入shell中查看SP_daemon进程是否存在,没有则需启动SP_daemon进程(SP_daemon用于采集fps、ram等指标), 然后打开桌面的Smartperf工具;(采集指标少的时候一般为SP_daemon未启动,或者被后台清理)<br>
|
||||
|
||||
查看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);<br>
|
||||
- 步骤3:选择应用后根据应用类型选择是否是视频应用、是否是相机应用,点击开始测试、启动悬浮窗(左上角展示),会自动拉起应用,左上角悬浮窗展示start后点击即可开始,展示会变为计时状态,显示当前采集计时;(双击展开、关闭详情悬浮窗;长按结束任务保存数据;单击暂停、继续任务;点击详情悬浮窗后任意采集项会展开相应采集折线图)<br>
|
||||
- 步骤3:选择应用后,点击开始测试、启动悬浮窗(左上角展示),会自动拉起应用,左上角悬浮窗展示start后点击即可开始,展示会变为计时状态,显示当前采集计时;(双击展开、关闭详情悬浮窗;长按结束任务保存数据;单击暂停、继续任务;点击详情悬浮窗后任意采集项会展开相应采集折线图)<br>
|
||||
- 步骤4:长按计时器,可以保存采集项数据,悬浮框消失;<br>
|
||||
- 步骤5:报告列表页查看报告,原始数据可在概览页对应路径自行使用hdc命令pull出来<br>
|
||||
|
||||
@ -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采集能力**<br>
|
||||
- 截图目录默认在/data/local/tmp/capture下。<br>
|
||||
- **Trace抓取:当帧绘制时间超过100ms以上会自动抓取trace,1min内只抓取1次,目录在/data目录下,trace文件较大,建议定期清除。**
|
||||
**文件名称为:mynewtrace + 当前采集s数 + s:mynewtrace950s.ftrace**
|
||||
**文件名称为:mynewtrace[当前时间戳].ftrace**
|
||||
|
||||
|
||||
**2、fps采集不到如何解决**<br>
|
||||
|
@ -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": [
|
||||
{
|
||||
|
@ -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 }}}
|
@ -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 )
|
@ -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 <cstdio>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <pthread.h>
|
||||
#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<std::string> 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<std::string, FpsInfo> 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;
|
||||
}
|
||||
}
|
@ -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 <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include "pthread.h"
|
||||
#include "gp_utils.h"
|
||||
|
||||
struct FpsInfo {
|
||||
int fps;
|
||||
int pre_fps;
|
||||
std::vector<long long> jitters;
|
||||
std::queue<long long> 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
|
@ -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 <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#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<std::string, std::string> RAM::getRamInfo(std::string pid)
|
||||
{
|
||||
std::map<std::string, std::string> 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<std::string> 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;
|
||||
}
|
@ -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 <node_api.h>
|
||||
#include <cerrno>
|
||||
#include <unistd.h>
|
||||
#include "gp_utils.h"
|
||||
|
||||
namespace gpUtils {
|
||||
void mSplit(const std::string &content, const std::string &sp, std::vector<std::string> &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);
|
||||
}
|
||||
}
|
@ -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 <string>
|
||||
#include <vector>
|
||||
|
||||
namespace gpUtils {
|
||||
void mSplit(const std::string &content, const std::string &sp, std::vector<std::string>& 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
|
@ -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 <iostream>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <future>
|
||||
#include <climits>
|
||||
#include <cmath>
|
||||
#include <node_api.h>
|
||||
#include <js_native_api.h>
|
||||
#include "FPS.h"
|
||||
#include "RAM.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "gp_utils.h"
|
||||
|
||||
namespace {
|
||||
void collectFpsThread(std::promise<FpsInfo> &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<FpsInfo> promiseObj;
|
||||
std::future<FpsInfo> 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<long long> 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<std::string, std::string> 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);
|
||||
}
|
@ -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
|
||||
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"name": "libsmartperf.so",
|
||||
"types": "./index.d.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() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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<String> = globalThis.fpsArr
|
||||
let fpsJitterQueue: Array<String> = globalThis.fpsJitterArr
|
||||
let curFPS = fpsQueue.pop()
|
||||
globalThis.timerFps = curFPS
|
||||
let curFPSJitter = fpsJitterQueue.pop()
|
||||
let fpsJitters = "\"" + curFPSJitter.split("==").join(",") + "\""
|
||||
this.fpsMap.set("fpsJitters", fpsJitters)
|
||||
|
@ -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(){
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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%')
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user