mirror of
https://gitee.com/openharmony/developtools_profiler
synced 2024-11-23 06:50:12 +00:00
commit
c3066bc9f5
@ -58,6 +58,7 @@ ohos_executable("SP_daemon") {
|
||||
"profiler_fps.cpp",
|
||||
"smartperf_command.cpp",
|
||||
"smartperf_main.cpp",
|
||||
"sp_log.cpp",
|
||||
"sp_parse_fps.cpp",
|
||||
"sp_profiler_factory.cpp",
|
||||
"sp_server_socket.cpp",
|
||||
@ -72,10 +73,15 @@ ohos_executable("SP_daemon") {
|
||||
part_name = "${OHOS_PROFILER_PART_NAME}"
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hiview:libucollection_utility",
|
||||
"image_framework:image_native",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"LOG_DOMAIN = 0xD004100",
|
||||
]
|
||||
}
|
||||
## Build so }}}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "cpu_collector.h"
|
||||
#include "collect_result.h"
|
||||
#include "include/startup_delay.h"
|
||||
#include "include/sp_log.h"
|
||||
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::HiviewDFX::UCollectUtil;
|
||||
@ -81,6 +82,7 @@ void CPU::SetPackageName(std::string pName)
|
||||
{
|
||||
OHOS::SmartPerf::StartUpDelay sp;
|
||||
processId = sp.GetPidByPkg(pName);
|
||||
LOGE("cpu.processId===: %s", processId.c_str());
|
||||
}
|
||||
std::vector<CpuFreqs> CPU::GetCpuFreq()
|
||||
{
|
||||
@ -93,6 +95,8 @@ std::vector<CpuFreqs> CPU::GetCpuFreq()
|
||||
cpuFreqs.cpuId = cpufreq[i].cpuId;
|
||||
cpuFreqs.curFreq = cpufreq[i].curFreq;
|
||||
cpuFreqs2.push_back(cpuFreqs);
|
||||
LOGE("cpuFreqs.cpuId: %s", std::to_string(cpufreq[i].cpuId).c_str());
|
||||
LOGE("cpuFreqs.curFreq: %s", std::to_string(cpufreq[i].curFreq).c_str());
|
||||
}
|
||||
return cpuFreqs2;
|
||||
}
|
||||
@ -117,6 +121,14 @@ std::vector<CpuUsageInfos> CPU::GetCpuUsage()
|
||||
cpuUsageInfos.irqUsage = cpuInfo.irqUsage;
|
||||
cpuUsageInfos.softIrqUsage = cpuInfo.softIrqUsage;
|
||||
workload.push_back(cpuUsageInfos);
|
||||
LOGE("UsageCpuId: %s", cpuInfo.cpuId.c_str());
|
||||
LOGE("userUsage: %s", std::to_string(cpuInfo.userUsage).c_str());
|
||||
LOGE("niceUsage: %s", std::to_string(cpuInfo.niceUsage).c_str());
|
||||
LOGE("systemUsage: %s", std::to_string(cpuInfo.systemUsage).c_str());
|
||||
LOGE("idleUsage: %s", std::to_string(cpuInfo.idleUsage).c_str());
|
||||
LOGE("ioWaitUsage: %s", std::to_string(cpuInfo.ioWaitUsage).c_str());
|
||||
LOGE("irqUsage: %s", std::to_string(cpuInfo.irqUsage).c_str());
|
||||
LOGE("softIrqUsage: %s", std::to_string(cpuInfo.softIrqUsage).c_str());
|
||||
}
|
||||
return workload;
|
||||
}
|
||||
@ -136,6 +148,12 @@ std::map<std::string, std::string> CPU::GetSysProcessCpuLoad() const
|
||||
processCpuInfo["ProcCpuUsage"] = std::to_string(data.cpuUsage * oneHundred);
|
||||
processCpuInfo["ProcUCpuUsage"] = std::to_string(data.uCpuUsage * oneHundred);
|
||||
processCpuInfo["ProcSCpuUsage"] = std::to_string(data.sCpuUsage * oneHundred);
|
||||
LOGE("ProcId: %s", std::to_string(data.pid).c_str());
|
||||
LOGE("ProcAppName: %s", data.procName.c_str());
|
||||
LOGE("ProcCpuLoad: %s", std::to_string(data.cpuLoad).c_str());
|
||||
LOGE("ProcCpuUsage: %s", std::to_string(data.cpuUsage).c_str());
|
||||
LOGE("ProcUCpuUsage: %s", std::to_string(data.uCpuUsage).c_str());
|
||||
LOGE("ProcSCpuUsage: %s", std::to_string(data.sCpuUsage).c_str());
|
||||
return processCpuInfo;
|
||||
}
|
||||
return processCpuInfo;
|
||||
|
@ -16,11 +16,13 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include "include/sp_utils.h"
|
||||
#include "include/ByTrace.h"
|
||||
#include "include/Capture.h"
|
||||
#include "include/FPS.h"
|
||||
#include "include/sp_log.h"
|
||||
namespace OHOS {
|
||||
namespace SmartPerf {
|
||||
std::map<std::string, std::string> FPS::ItemData()
|
||||
@ -83,12 +85,28 @@ std::string FPS::GetSurface()
|
||||
SPUtils::LoadCmd(cmdString1 + cmdString2 + cmdString3, cmdResult);
|
||||
size_t position1 = cmdResult.find("[");
|
||||
size_t position2 = cmdResult.find("]");
|
||||
LOGE("cmdResult==: %s", (cmdResult.substr(position1 + 1, position2 - position1 - 1)).c_str());
|
||||
return cmdResult.substr(position1 + 1, position2 - position1 - 1);
|
||||
}
|
||||
static void PrintFpsInfo(FpsInfo &fpsInfo, std::string Tag, std::string Type)
|
||||
{
|
||||
LOGE("Print fps: %s", std::to_string(fpsInfo.fps).c_str());
|
||||
LOGE("Print Tag: %s", Tag.c_str());
|
||||
LOGE("Print Type: %s", Type.c_str());
|
||||
std::string jitterStr = "";
|
||||
std::string split = "";
|
||||
for (size_t i = 0; i < fpsInfo.jitters.size(); i++) {
|
||||
if (i > 0) {
|
||||
split = ";;";
|
||||
}
|
||||
jitterStr += split + std::to_string(fpsInfo.jitters[i]);
|
||||
}
|
||||
LOGE("Print Tag: %s", Tag.c_str());
|
||||
}
|
||||
std::string FPS::CutLayerName(std::string layerName)
|
||||
{
|
||||
std::string subLayerName;
|
||||
int twenty = 20;
|
||||
size_t twenty = 20;
|
||||
if (layerName.size() > twenty) {
|
||||
subLayerName = layerName.substr(0, twenty);
|
||||
} else {
|
||||
@ -105,15 +123,12 @@ FpsInfo FPS::GetFpsInfo()
|
||||
if (pkgName.empty()) {
|
||||
return fpsInfoMax;
|
||||
}
|
||||
std::string layerName;
|
||||
std::vector<std::string> sps;
|
||||
SPUtils::StrSplit(this->pkgName, ".", sps);
|
||||
const uint64_t pNameLastPos = sps.size();
|
||||
std::string pkgSuffix = sps[pNameLastPos - 1];
|
||||
layerName = std::string(pkgSuffix.c_str());
|
||||
std::string layerName = std::string(sps[pNameLastPos - 1].c_str());
|
||||
std::string uniteLayer = "DisplayNode";
|
||||
uniteLayer = GetSurface();
|
||||
std::string spSurfacePrefix = "sp_";
|
||||
std::string line = GetLayer(layerName);
|
||||
std::vector<std::string> params;
|
||||
SPUtils::StrSplit(line, ":", params);
|
||||
@ -122,15 +137,14 @@ FpsInfo FPS::GetFpsInfo()
|
||||
std::string focusSurface = params[0];
|
||||
FpsInfo uniteFpsInfo;
|
||||
std::string subStrLayerName = CutLayerName(layerName);
|
||||
if (focusSurface.find(subStrLayerName) != std::string::npos) {
|
||||
LOGE("layerName: %s", "uniteLayer: %s", "line: %s", "focusSurface: %s", "subStrLayerName: %s",
|
||||
layerName.c_str(), uniteLayer.c_str(), line.c_str(), focusSurface.c_str(), subStrLayerName.c_str());
|
||||
if ((focusSurface.find(subStrLayerName) != std::string::npos) && (strcmp(pkgZOrd.c_str(), zOrd.c_str()) != 0)) {
|
||||
uniteFpsInfo = GetSurfaceFrame(uniteLayer);
|
||||
PrintFpsInfo(uniteFpsInfo, uniteLayer, "one");
|
||||
}
|
||||
if ((focusSurface.find(spSurfacePrefix) != std::string::npos) && (strcmp(pkgZOrd.c_str(), zOrd.c_str()) != 0)) {
|
||||
if (uniteFpsInfo.fps <= fpsValue) {
|
||||
uniteFpsInfo = GetSurfaceFrame(uniteLayer);
|
||||
}
|
||||
}
|
||||
FpsInfo fpsInfo = GetSurfaceFrame(layerName);
|
||||
FpsInfo fpsInfo = GetSurfaceFrame(focusSurface);
|
||||
PrintFpsInfo(fpsInfo, focusSurface, "two");
|
||||
if (fpsInfo.fps > uniteFpsInfo.fps) {
|
||||
fpsInfoMax = fpsInfo;
|
||||
} else {
|
||||
@ -140,8 +154,12 @@ FpsInfo FPS::GetFpsInfo()
|
||||
fpsInfoMax.fps = fpsValue;
|
||||
}
|
||||
if (flagFpsInfo == fpsInfoMax) {
|
||||
flagFpsInfo = fpsInfoMax;
|
||||
fpsInfoMax.Clear();
|
||||
if (cntFpsInfo.fps != 0) {
|
||||
fpsInfoMax = cntFpsInfo;
|
||||
} else {
|
||||
flagFpsInfo = fpsInfoMax;
|
||||
fpsInfoMax.Clear();
|
||||
}
|
||||
return fpsInfoMax;
|
||||
} else {
|
||||
flagFpsInfo = fpsInfoMax;
|
||||
@ -166,6 +184,7 @@ FpsInfo FPS::GetSurfaceFrame(std::string name)
|
||||
FILE *fp;
|
||||
static char tmp[1024];
|
||||
std::string cmd = "hidumper -s 10 -a \"fps " + name + "\"";
|
||||
LOGE("cmd=====: %s", cmd.c_str());
|
||||
fp = popen(cmd.c_str(), "r");
|
||||
if (fp == nullptr) {
|
||||
return fpsInfo;
|
||||
@ -180,10 +199,12 @@ FpsInfo FPS::GetSurfaceFrame(std::string name)
|
||||
}
|
||||
bool jump = false;
|
||||
bool refresh = false;
|
||||
|
||||
int cnt = 0;
|
||||
int zeroNum = 0;
|
||||
LOGE("dump time: start!");
|
||||
while (fgets(tmp, sizeof(tmp), fp) != nullptr) {
|
||||
std::string str(tmp);
|
||||
LOGE("dump time: %s", str.c_str());
|
||||
long long frameReadyTime = 0;
|
||||
std::stringstream sstream;
|
||||
sstream << tmp;
|
||||
@ -221,37 +242,57 @@ FpsInfo FPS::GetSurfaceFrame(std::string name)
|
||||
lastFrame = currFrame;
|
||||
(fpsInfo.timeStampQ).pop();
|
||||
}
|
||||
|
||||
fpsGb = fpsTmp;
|
||||
|
||||
LOGE("fpsGb====: %s", std::to_string(fpsGb).c_str());
|
||||
(fpsInfo.timeStampQ).push(frameReadyTime);
|
||||
|
||||
fpsInfo.lastFrameReadyTime = lastFrame;
|
||||
} else if (tFrameReadyTime > tLastReadyTime + 1) {
|
||||
jump = true;
|
||||
lastReadyTime = frameReadyTime;
|
||||
|
||||
while (!(fpsInfo.timeStampQ).empty()) {
|
||||
(fpsInfo.timeStampQ).pop();
|
||||
}
|
||||
|
||||
(fpsInfo.timeStampQ).push(frameReadyTime);
|
||||
}
|
||||
int total = 138;
|
||||
if (cnt == total && fpsGb != 0) {
|
||||
LOGE("cnt == total && fpsGb != 0");
|
||||
lastReadyTime = frameReadyTime;
|
||||
int fpsTmp = 0;
|
||||
cntFpsInfo.jitters.clear();
|
||||
while (!(fpsInfo.timeStampQ).empty()) {
|
||||
fpsTmp++;
|
||||
long long currFrame = (fpsInfo.timeStampQ.front());
|
||||
if (lastFrame != -1) {
|
||||
long long jitter = currFrame - lastFrame;
|
||||
cntFpsInfo.jitters.push_back(jitter);
|
||||
} else {
|
||||
long long jitter = currFrame - currFrame / mod * mod;
|
||||
cntFpsInfo.jitters.push_back(jitter);
|
||||
}
|
||||
lastFrame = currFrame;
|
||||
(fpsInfo.timeStampQ).pop();
|
||||
}
|
||||
cntFpsInfo.fps = fpsTmp;
|
||||
LOGE("cntFpsInfo.fps====: %s", std::to_string(cntFpsInfo.fps).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
const int maxZeroNum = 120;
|
||||
const int maxZeroNum = 130;
|
||||
if (zeroNum >= maxZeroNum) {
|
||||
LOGE("zeroNum====: %s", std::to_string(zeroNum).c_str());
|
||||
while (!(fpsInfo.timeStampQ.empty())) {
|
||||
fpsInfo.timeStampQ.pop();
|
||||
}
|
||||
fpsInfo.fps = 0;
|
||||
fpsInfo.jitters.clear();
|
||||
LOGE("fpsInfo.fps0: %s", std::to_string(fpsInfo.fps).c_str());
|
||||
return fpsInfo;
|
||||
}
|
||||
const int minPrintLine = 5;
|
||||
if (cnt < minPrintLine) {
|
||||
fpsInfo.fps = fpsInfo.preFps;
|
||||
LOGE("fpsInfo.fps1: %s", std::to_string(fpsInfo.fps).c_str());
|
||||
return fpsInfo;
|
||||
}
|
||||
if (!fpsInfo.timeStampQ.empty() && fpsInfo.timeStampQ.back() == lastLineTime) {
|
||||
@ -259,17 +300,24 @@ FpsInfo FPS::GetSurfaceFrame(std::string name)
|
||||
if (fpsGb == 0) {
|
||||
fpsInfo.jitters.clear();
|
||||
}
|
||||
LOGE("fpsInfo.fps2: %s", std::to_string(fpsInfo.fps).c_str());
|
||||
LOGE("lastLineTime: %s", std::to_string(lastLineTime).c_str());
|
||||
return fpsInfo;
|
||||
}
|
||||
if (fpsGb > 0) {
|
||||
fpsInfo.fps = fpsGb;
|
||||
fpsInfo.preFps = fpsGb;
|
||||
LOGE("fpsInfo.fps3: %s", std::to_string(fpsInfo.fps).c_str());
|
||||
LOGE("fpsInfo.preFps3: %s", std::to_string(fpsInfo.preFps).c_str());
|
||||
return fpsInfo;
|
||||
} else if (refresh && !jump) {
|
||||
fpsInfo.fps = fpsInfo.preFps;
|
||||
LOGE("fpsInfo.fps4: %s", std::to_string(fpsInfo.fps).c_str());
|
||||
return fpsInfo;
|
||||
} else {
|
||||
fpsInfo.fps = 0;
|
||||
fpsInfo.jitters.clear();
|
||||
LOGE("fpsInfo.fps5: %s", std::to_string(fpsInfo.fps).c_str());
|
||||
return fpsInfo;
|
||||
}
|
||||
}
|
||||
@ -283,15 +331,15 @@ std::string FPS::GetLayer(std::string pkgSurface)
|
||||
if (fd != nullptr) {
|
||||
int lineNum = 0;
|
||||
char buf[1024] = {'\0'};
|
||||
|
||||
const int paramFourteen = 14;
|
||||
const int paramTwentyFour = 24;
|
||||
const int paramThree = 3;
|
||||
const int windowNameIndex = 0;
|
||||
const int windowIdIndex = 3;
|
||||
const int focusNameIndex = 2;
|
||||
|
||||
while ((fgets(buf, sizeof(buf), fd)) != nullptr) {
|
||||
std::string line = buf;
|
||||
LOGE("hidumperline: %s", line.c_str());
|
||||
if (line[0] == '-' || line[0] == ' ') {
|
||||
continue;
|
||||
}
|
||||
@ -305,6 +353,10 @@ std::string FPS::GetLayer(std::string pkgSurface)
|
||||
DumpEntity dumpEntity { params[0], params[1], params[2], params[3], params[7]};
|
||||
dumpEntityList.push_back(dumpEntity);
|
||||
}
|
||||
if (params.size() == paramFourteen || params.size() == paramTwentyFour) {
|
||||
DumpEntity dumpEntity { params[0], params[2], params[2], params[3], params[6]};
|
||||
dumpEntityList.push_back(dumpEntity);
|
||||
}
|
||||
if (params.size() == paramThree) {
|
||||
curFocusId = params[focusNameIndex];
|
||||
break;
|
||||
@ -316,16 +368,30 @@ std::string FPS::GetLayer(std::string pkgSurface)
|
||||
|
||||
std::string focusWindowName = "NA";
|
||||
std::string pkgZOrd = "-1";
|
||||
std::string spSurfacePrefix = "sp_";
|
||||
std::string floatWindow = "floatWindow";
|
||||
int curId = std::stoi(curFocusId);
|
||||
LOGE("getLayerCurId====: %s", std::to_string(curId).c_str());
|
||||
for (size_t i = 0; i < dumpEntityList.size(); i++) {
|
||||
DumpEntity dumpItem = dumpEntityList[i];
|
||||
int curWinId = std::stoi(dumpItem.windId);
|
||||
if (curId == curWinId) {
|
||||
LOGE("curId == curWinId");
|
||||
if ((dumpItem.windowName.find(spSurfacePrefix) != std::string::npos ||
|
||||
dumpItem.windowName.find(floatWindow) != std::string::npos) && dumpItem.zOrd != "-1") {
|
||||
continue;
|
||||
}
|
||||
focusWindowName = dumpItem.windowName;
|
||||
LOGE("focusWindowName: %s", focusWindowName.c_str());
|
||||
LOGE("dumpItem.windowName: %s", dumpItem.windowName.c_str());
|
||||
}
|
||||
if (dumpItem.windowName.find(pkgSurface) != std::string::npos)
|
||||
{
|
||||
if (dumpItem.windowName.find(pkgSurface) != std::string::npos && dumpItem.zOrd != "-1") {
|
||||
focusWindowName = dumpItem.windowName;
|
||||
pkgZOrd = dumpItem.zOrd;
|
||||
LOGE("pkgZOrd: %s", pkgZOrd.c_str());
|
||||
LOGE("dumpItem.zOrd: %s", dumpItem.zOrd.c_str());
|
||||
LOGE("focusWindowName2: %s", focusWindowName.c_str());
|
||||
LOGE("dumpItem.windowName2: %s", dumpItem.windowName.c_str());
|
||||
}
|
||||
}
|
||||
return focusWindowName + ":" + pkgZOrd;
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "include/sp_utils.h"
|
||||
#include "gpu_collector.h"
|
||||
#include "collect_result.h"
|
||||
#include "include/sp_log.h"
|
||||
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::HiviewDFX::UCollectUtil;
|
||||
@ -38,6 +39,7 @@ int GPU::GetGpuFreq()
|
||||
{
|
||||
std::shared_ptr<GpuCollector> collector = GpuCollector::Create();
|
||||
CollectResult<GpuFreq> result = collector->CollectGpuFrequency();
|
||||
LOGE("GpuFrequency: %s", std::to_string(result.data.curFeq).c_str());
|
||||
return result.data.curFeq;
|
||||
}
|
||||
|
||||
@ -45,6 +47,7 @@ float GPU::GetGpuLoad()
|
||||
{
|
||||
std::shared_ptr<GpuCollector> collector = GpuCollector::Create();
|
||||
CollectResult<SysGpuLoad> result = collector->CollectSysGpuLoad();
|
||||
LOGE("SysGpuLoad: %s", std::to_string(result.data.gpuLoad).c_str());
|
||||
return float(result.data.gpuLoad);
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "sys/time.h"
|
||||
#include "securec.h"
|
||||
#include "include/sp_utils.h"
|
||||
#include "include/sp_log.h"
|
||||
#define LARGE_BUFF_MAX_LEN (256)
|
||||
namespace OHOS {
|
||||
namespace SmartPerf {
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <iostream>
|
||||
#include "include/sp_utils.h"
|
||||
#include "include/Power.h"
|
||||
#include "include/sp_log.h"
|
||||
namespace OHOS {
|
||||
namespace SmartPerf {
|
||||
std::map<std::string, std::string> Power::ItemData()
|
||||
@ -26,6 +27,8 @@ std::map<std::string, std::string> Power::ItemData()
|
||||
SPUtils::LoadFile(voltageNowPath, voltageNow);
|
||||
result["currentNow"] = currentNow;
|
||||
result["voltageNow"] = voltageNow;
|
||||
LOGE("currentNow: %s", currentNow.c_str());
|
||||
LOGE("voltageNow: %s", voltageNow.c_str());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "include/sp_utils.h"
|
||||
#include <dirent.h>
|
||||
#include "include/Temperature.h"
|
||||
#include "include/sp_log.h"
|
||||
namespace OHOS {
|
||||
namespace SmartPerf {
|
||||
std::map<std::string, std::string> Temperature::ItemData()
|
||||
@ -35,7 +36,9 @@ std::map<std::string, std::string> Temperature::ItemData()
|
||||
std::map<std::string, std::string> result;
|
||||
for (auto dir : dirs) {
|
||||
std::string dirType = dir + "/type";
|
||||
LOGE("dirType====: %s", dirType.c_str());
|
||||
std::string dirTemp = dir + "/temp";
|
||||
LOGE("dirTemp====: %s", dirTemp.c_str());
|
||||
|
||||
if (SPUtils::FileAccess(dirType)) {
|
||||
std::string type;
|
||||
@ -44,7 +47,9 @@ std::map<std::string, std::string> Temperature::ItemData()
|
||||
SPUtils::LoadFile(dirTemp, temp);
|
||||
for (auto node : collectNodes) {
|
||||
if (type.find(node) != std::string::npos) {
|
||||
LOGE("type====: %s", type.c_str());
|
||||
float t = std::stof(temp);
|
||||
LOGE("temp====: %s", temp.c_str());
|
||||
result[type] = std::to_string(t / 1e3);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,10 @@ namespace SmartPerf {
|
||||
int ClientControl::SocketStart(std::string args)
|
||||
{
|
||||
std::string messageInit = message + args;
|
||||
OHOS::SmartPerf::ClientControl::InitSocket();
|
||||
int resultId = OHOS::SmartPerf::ClientControl::InitSocket();
|
||||
if (resultId == 1) {
|
||||
return resultId;
|
||||
}
|
||||
send(clientSocket, messageInit.c_str(), strlen(messageInit.c_str()), 0);
|
||||
read(clientSocket, buffer, numBuff);
|
||||
send(clientSocket, message1, strlen(message1), 0);
|
||||
@ -39,10 +42,12 @@ int ClientControl::SocketStart(std::string args)
|
||||
dest[i] = '\0';
|
||||
if (strcmp(dest, "start::True") == 0) {
|
||||
std::cout << "SP_daemon Collection begins" << std::endl;
|
||||
OHOS::SmartPerf::ClientControl::CloseSocket();
|
||||
} else {
|
||||
std::cout << "SP_daemon Collection begins failed" << std::endl;
|
||||
OHOS::SmartPerf::StartUpDelay sd;
|
||||
sd.GetSpTcp();
|
||||
}
|
||||
OHOS::SmartPerf::ClientControl::CloseSocket();
|
||||
return 0;
|
||||
}
|
||||
int ClientControl::SocketStop()
|
||||
@ -59,10 +64,12 @@ int ClientControl::SocketStop()
|
||||
if (strcmp(dest, "stop::True") == 0) {
|
||||
std::cout << "SP_daemon Collection ended" << std::endl;
|
||||
std::cout << "Output Path: data/local/tmp/smartperf/1/t_index_info.csv" << std::endl;
|
||||
OHOS::SmartPerf::StartUpDelay sd;
|
||||
sd.GetSpTcp();
|
||||
OHOS::SmartPerf::ClientControl::CloseSocket();
|
||||
} else {
|
||||
std::cout << "SP_daemon Collection ended failed" << std::endl;
|
||||
}
|
||||
OHOS::SmartPerf::ClientControl::CloseSocket();
|
||||
return 0;
|
||||
}
|
||||
int ClientControl::InitSocket()
|
||||
@ -77,6 +84,9 @@ int ClientControl::InitSocket()
|
||||
serverAddress.sin_port = htons(protNumber);
|
||||
if (connect(clientSocket, reinterpret_cast<struct sockaddr*>(&serverAddress), sizeof(serverAddress)) < 0) {
|
||||
std::cout << "Failed to connect to server" << std::endl;
|
||||
OHOS::SmartPerf::StartUpDelay sd;
|
||||
sd.GetSpTcp();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -89,6 +99,8 @@ void ClientControl::StartSPDaemon()
|
||||
int ClientControl::CloseSocket()
|
||||
{
|
||||
shutdown(clientSocket, SHUT_RD);
|
||||
close(clientSocket);
|
||||
clientSocket = -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -59,8 +59,6 @@ std::string ControlCallCmd::GetResult(std::vector<std::string> v)
|
||||
result = SmartPerf::ControlCallCmd::StartFrameFps(v);
|
||||
} else if (v[typeName] == "fpsohtest") {
|
||||
SPUtils::LoadCmd("GP_daemon_fps 10", result);
|
||||
} else if (v[typeName] == "screen") {
|
||||
result = SPUtils::GetScreen();
|
||||
} else if (v[typeName] == "frameLoss") {
|
||||
SmartPerf::ControlCallCmd::GetFrame();
|
||||
} else if (v[typeName] == "appStartTime") {
|
||||
@ -130,7 +128,7 @@ std::string ControlCallCmd::SlideList()
|
||||
thGetHisysId.join();
|
||||
double responseTime = radar.ParseRadarResponse(str);
|
||||
stream << responseTime;
|
||||
std::string responseSlide = "responseTime:" + stream.str() + "ms";
|
||||
std::string responseSlide = "ResponseTime:" + stream.str() + "ms";
|
||||
double sFps = slideFpsTrace.ParseSlideFpsTraceNoh(traceName);
|
||||
std::ostringstream streamFps;
|
||||
streamFps << sFps;
|
||||
|
@ -67,6 +67,7 @@ public:
|
||||
std::string GetLayer(std::string pkgSurface);
|
||||
FpsInfo mFpsInfo;
|
||||
FpsInfo flagFpsInfo;
|
||||
FpsInfo cntFpsInfo;
|
||||
static FPS &GetInstance()
|
||||
{
|
||||
static FPS instance;
|
||||
|
@ -80,7 +80,8 @@ enum class CommandType {
|
||||
};
|
||||
enum class CommandHelp {
|
||||
HELP,
|
||||
VERSION
|
||||
VERSION,
|
||||
SCREEN,
|
||||
};
|
||||
|
||||
const std::unordered_map<std::string, CommandType> commandMap = {
|
||||
@ -113,6 +114,7 @@ const std::unordered_map<CommandType, std::string> COMMAND_MAP_REVERSE = {
|
||||
const std::unordered_map<CommandHelp, std::string> commandHelpMap = {
|
||||
{ CommandHelp::HELP, std::string("--help") },
|
||||
{ CommandHelp::VERSION, std::string("--version") },
|
||||
{ CommandHelp::SCREEN, std::string("-screen") },
|
||||
};
|
||||
|
||||
enum class TraceStatus {
|
||||
|
@ -28,24 +28,38 @@ public:
|
||||
const std::string smartPerfVersion = "1.0.2\n";
|
||||
const std::string smartPerfMsgErr = "error input!\n use command '--help' get more information\n";
|
||||
const std::string smartPerfMsg = "usage: SP_daemon <options> <arguments> \n"
|
||||
"--------------------------------------------------------------------\n"
|
||||
"-------------------------------------------------------------------------------------\n"
|
||||
"These are common commands list:\n"
|
||||
" -N set the collection times, for example: -N 10 \n"
|
||||
" -PKG set package name, must add, for example: -PKG ohos.samples.ecg \n"
|
||||
" -c get device cpuFreq and cpuUsage, process cpuUsage and cpuLoad .. \n"
|
||||
" -g get device gpuFreq and gpuLoad \n"
|
||||
" -f get app refresh fps and fps jitters \n"
|
||||
" -t get soc-temp gpu-temp .. \n"
|
||||
"-profilerfps get refresh fps and timestamp \n"
|
||||
" -t get soc-temp battery-temp .. \n"
|
||||
" -p get current_now and voltage_now \n"
|
||||
" -r get process memory and total memory .. \n"
|
||||
" -snapshot get screen capture\n"
|
||||
" -net get networkUp and networkDown\n"
|
||||
"--------------------------------------------------------------------\n"
|
||||
" -start collection start command \n"
|
||||
" -stop collection stop command \n"
|
||||
" -VIEW set layler, for example: -VIEW DisplayNode \n"
|
||||
" -screen get screen resolution \n"
|
||||
"-------------------------------------------------------------------------------------\n"
|
||||
"Example 1: SP_daemon -N 20 -c -g -t -p -r -net -snapshot \n"
|
||||
"--------------------------------------------------------------------\n"
|
||||
"---------------------------------------------------------------------------------------\n"
|
||||
"Example 2: SP_daemon -N 20 -PKG ohos.samples.ecg -c -g -t -p -f -r -net -snapshot\n"
|
||||
"---------------------------------------------------------------------------------------\n";
|
||||
"-------------------------------------------------------------------------------------\n"
|
||||
"-------------------------------------------------------------------------------------\n"
|
||||
"Example 2: SP_daemon -N 20 -PKG ohos.samples.ecg -c -g -t -p -f -r -net -snapshot \n"
|
||||
"-------------------------------------------------------------------------------------\n"
|
||||
"-------------------------------------------------------------------------------------\n"
|
||||
"Example 3: SP_daemon -start -c \n"
|
||||
"-------------------------------------------------------------------------------------\n"
|
||||
"-------------------------------------------------------------------------------------\n"
|
||||
"Example 4: SP_daemon -stop \n"
|
||||
"-------------------------------------------------------------------------------------\n"
|
||||
"-------------------------------------------------------------------------------------\n"
|
||||
"Example 5: SP_daemon -screen \n"
|
||||
"-------------------------------------------------------------------------------------\n";
|
||||
const int oneParam = 1;
|
||||
const int twoParam = 2;
|
||||
const int threeParamMore = 3;
|
||||
|
42
host/smartperf/client/client_command/include/sp_log.h
Normal file
42
host/smartperf/client/client_command/include/sp_log.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
||||
* 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 OHOS_SP_LOG_H
|
||||
#define OHOS_SP_LOG_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace SmartPerf {
|
||||
typedef enum {
|
||||
SP_LOG_DEBUG,
|
||||
SP_LOG_INFO,
|
||||
SP_LOG_WARN,
|
||||
SP_LOG_ERROR,
|
||||
} SpLogLevel;
|
||||
|
||||
void SpLog(SpLogLevel logLevel, const char *fmt, ...);
|
||||
|
||||
#define LOGD(fmt, ...) \
|
||||
SpLog(SP_LOG_DEBUG, (std::string("[") + "SP_daemon" +"][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
|
||||
|
||||
#define LOGI(fmt, ...) \
|
||||
SpLog(SP_LOG_INFO, (std::string("[") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
|
||||
|
||||
#define LOGW(fmt, ...) \
|
||||
SpLog(SP_LOG_WARN, (std::string("[") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
|
||||
|
||||
#define LOGE(fmt, ...) \
|
||||
SpLog(SP_LOG_ERROR, (std::string("[") + "SP_daemon" + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
|
||||
} // namespace SmartPerf
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_SP_LOG_H
|
@ -36,7 +36,7 @@ public:
|
||||
int Send(std::string sendBuf);
|
||||
int Recv();
|
||||
// 关闭
|
||||
void Close() const;
|
||||
void Close();
|
||||
std::string RecvBuf() const;
|
||||
|
||||
private:
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "sp_task.h"
|
||||
#include "control_call_cmd.h"
|
||||
#include "startup_delay.h"
|
||||
#include "sp_log.h"
|
||||
namespace OHOS {
|
||||
namespace SmartPerf {
|
||||
class SpThreadSocket {
|
||||
@ -116,6 +117,7 @@ public:
|
||||
SPTask::GetInstance().StopTask();
|
||||
spSocket.Send("stop::True");
|
||||
flagRunning = false;
|
||||
spSocket.Close();
|
||||
} else if (recvStr.find("SP_daemon -editor") != std::string::npos) {
|
||||
EditorRecv(recvStr, spSocket);
|
||||
}
|
||||
@ -147,26 +149,33 @@ public:
|
||||
auto iterator = messageMap.begin();
|
||||
while (iterator != messageMap.end()) {
|
||||
std::string recvBuf = spSocket.RecvBuf();
|
||||
std::cout << "recvBuf" << recvBuf << std::endl;
|
||||
if (SPUtils::IsSubString(recvBuf, iterator->second)) {
|
||||
SpProfiler *profiler = SpProfilerFactory::GetProfilerItem(iterator->first);
|
||||
if (profiler == nullptr && (iterator->first == MessageType::SET_PKG_NAME)) {
|
||||
std::string curPkgName = SplitMsg(recvBuf);
|
||||
SpProfilerFactory::SetProfilerPkg(curPkgName);
|
||||
spSocket.Sendto(curPkgName);
|
||||
LOGE("sendData1: %s", curPkgName.c_str());
|
||||
} else if (profiler == nullptr && (iterator->first == MessageType::SET_PROCESS_ID)) {
|
||||
std::string curPkgName1 = SplitMsg(recvBuf);
|
||||
SpProfilerFactory::SetProfilerPkg(curPkgName1);
|
||||
LOGE("sendData2: %s", curPkgName1.c_str());
|
||||
} else if (profiler == nullptr && (iterator->first == MessageType::CATCH_TRACE_CONFIG)) {
|
||||
SpProfilerFactory::SetByTrace(SplitMsg(recvBuf));
|
||||
LOGE("sendData3: %s", recvBuf.c_str());
|
||||
} else if (profiler == nullptr && (iterator->first == MessageType::CATCH_TRACE_CMD)) {
|
||||
SpProfilerFactory::SetByTraceCmd(SplitMsg(recvBuf));
|
||||
LOGE("sendData4: %s", recvBuf.c_str());
|
||||
} else if (profiler == nullptr) {
|
||||
std::string returnStr = iterator->second;
|
||||
spSocket.Sendto(returnStr);
|
||||
LOGE("sendData5: %s", returnStr.c_str());
|
||||
} else {
|
||||
std::map<std::string, std::string> data = profiler->ItemData();
|
||||
std::string sendData = MapToString(data);
|
||||
spSocket.Sendto(sendData);
|
||||
LOGE("sendData6: %s", sendData.c_str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ static void GetSectionsFps(FpsInfo &fpsInfo)
|
||||
} else if (msJiange < msAdd && msAdd <= (msJiange + 1e8)) {
|
||||
printf("sectionsFps:%d|%lld\n", msCount * ten, msStartTime);
|
||||
printCount++;
|
||||
msStartTime = fpsInfo.currentFpsTime + (msAdd / 1e6);
|
||||
msStartTime += 1e2;
|
||||
msCount = 1;
|
||||
msJiange += 1e8;
|
||||
} else {
|
||||
|
@ -74,6 +74,10 @@ void SmartPerfCommand::HelpCommand(CommandHelp type) const
|
||||
if (type == CommandHelp::VERSION) {
|
||||
std::cout << smartPerfVersion << std::endl;
|
||||
}
|
||||
if (type == CommandHelp::SCREEN) {
|
||||
std::string result = SPUtils::GetScreen();
|
||||
std::cout << result << std::endl;
|
||||
}
|
||||
}
|
||||
void SmartPerfCommand::HandleCommand(std::string argStr, std::string argStr1)
|
||||
{
|
||||
|
96
host/smartperf/client/client_command/sp_log.cpp
Normal file
96
host/smartperf/client/client_command/sp_log.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
|
||||
* 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 "sp_log.h"
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef HI_LOG_ENABLE
|
||||
#include "hilog/log.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <cstdio>
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace SmartPerf {
|
||||
const int32_t LOG_MAX_LEN = 10000;
|
||||
|
||||
static void SpLogOut(SpLogLevel logLevel, const char *logBuf)
|
||||
{
|
||||
#ifdef HI_LOG_ENABLE
|
||||
LogLevel hiLogLevel = LOG_INFO;
|
||||
switch (logLevel) {
|
||||
case SP_LOG_DEBUG:
|
||||
hiLogLevel = LOG_DEBUG;
|
||||
break;
|
||||
case SP_LOG_INFO:
|
||||
hiLogLevel = LOG_INFO;
|
||||
break;
|
||||
case SP_LOG_WARN:
|
||||
hiLogLevel = LOG_WARN;
|
||||
break;
|
||||
case SP_LOG_ERROR:
|
||||
hiLogLevel = LOG_ERROR;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
(void)HiLogPrint(LOG_CORE, hiLogLevel, LOG_DOMAIN, "SP_daemon", "%{public}s", logBuf);
|
||||
#else
|
||||
switch (logLevel) {
|
||||
case SP_LOG_DEBUG:
|
||||
printf("[D]%s\n", logBuf);
|
||||
break;
|
||||
case SP_LOG_INFO:
|
||||
printf("[I]%s\n", logBuf);
|
||||
break;
|
||||
case SP_LOG_WARN:
|
||||
printf("[W]%s\n", logBuf);
|
||||
break;
|
||||
case SP_LOG_ERROR:
|
||||
printf("[E]%s\n", logBuf);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SpLog(SpLogLevel logLevel, const char *fmt, ...)
|
||||
{
|
||||
char logBuf[LOG_MAX_LEN] = {0};
|
||||
va_list arg;
|
||||
int32_t ret = memset_s(&arg, sizeof(va_list), 0, sizeof(va_list));
|
||||
if (ret != 0) {
|
||||
SpLogOut(logLevel, "SP log memset_s error.");
|
||||
return;
|
||||
}
|
||||
va_start(arg, fmt);
|
||||
ret = vsprintf_s(logBuf, sizeof(logBuf), fmt, arg);
|
||||
va_end(arg);
|
||||
if (ret < 0) {
|
||||
SpLogOut(logLevel, "SP log length error.");
|
||||
return;
|
||||
}
|
||||
SpLogOut(logLevel, logBuf);
|
||||
}
|
||||
} // namespace SmartPerf
|
||||
} // namespace OHOS
|
@ -15,6 +15,7 @@
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include "include/sp_server_socket.h"
|
||||
namespace OHOS {
|
||||
namespace SmartPerf {
|
||||
@ -78,9 +79,11 @@ int SpServerSocket::Send(std::string sendBuf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SpServerSocket::Close() const
|
||||
void SpServerSocket::Close()
|
||||
{
|
||||
shutdown(sock, SHUT_RD);
|
||||
close(sock);
|
||||
sock = -1;
|
||||
}
|
||||
|
||||
int SpServerSocket::Recvfrom()
|
||||
|
@ -97,6 +97,7 @@ ErrCode SPTask::StartTask(std::function<void(std::string data)> msgTask)
|
||||
long long lastTime = SPUtils::GetCurTime();
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
std::map<std::string, std::string> dataMap;
|
||||
dataMap.insert(std::pair<std::string, std::string>(std::string("timestamp"), std::to_string(lastTime)));
|
||||
for (std::string itConfig:curTaskInfo.taskConfig) {
|
||||
SpProfiler *profiler = SpProfilerFactory::GetCmdProfilerItem(commandMap.at(itConfig));
|
||||
std::map<std::string, std::string> itemMap = profiler->ItemData();
|
||||
|
@ -138,16 +138,13 @@ void StartUpDelay::GetHisysIdComplete()
|
||||
}
|
||||
bool StartUpDelay::GetSpTcp()
|
||||
{
|
||||
std::string str = "";
|
||||
bool flagTcp = false;
|
||||
SPUtils::LoadCmd("netstat -anp |grep 8284", str);
|
||||
size_t pos = str.find("SP_daemon");
|
||||
if (pos == std::string::npos) {
|
||||
flagTcp = false;
|
||||
} else {
|
||||
flagTcp = true;
|
||||
}
|
||||
return flagTcp;
|
||||
std::string resultPid;
|
||||
std::string str;
|
||||
SPUtils::LoadCmd("pidof SP_daemon", resultPid);
|
||||
size_t splitFlag = resultPid.find(" ");
|
||||
resultPid = resultPid.substr(0, splitFlag);
|
||||
SPUtils::LoadCmd("kill " + resultPid, str);
|
||||
return false;
|
||||
}
|
||||
std::thread StartUpDelay::ThreadGetHisysIdResponse()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user