mirror of
https://gitee.com/openharmony/developtools_profiler
synced 2024-12-02 12:16:25 +00:00
HAP端采集转daemon
Signed-off-by: frank-huangran <frank.huangran@huawei.com>
This commit is contained in:
parent
1c4d5625dd
commit
e585b56ca7
@ -20,8 +20,7 @@ namespace OHOS {
|
||||
namespace SmartPerf {
|
||||
enum class MessageType {
|
||||
GET_CPU_NUM,
|
||||
GET_CPU_FREQ,
|
||||
GET_CPU_LOAD,
|
||||
GET_CPU_FREQ_LOAD,
|
||||
SET_PKG_NAME,
|
||||
SET_PROCESS_ID,
|
||||
GET_FPS_AND_JITTERS,
|
||||
@ -46,8 +45,7 @@ enum class MessageType {
|
||||
|
||||
const std::unordered_map<MessageType, std::string> MESSAGE_MAP = {
|
||||
{ MessageType::GET_CPU_NUM, std::string("get_cpu_num") },
|
||||
{ MessageType::GET_CPU_FREQ, std::string("get_cpu_freq") },
|
||||
{ MessageType::GET_CPU_LOAD, std::string("get_cpu_load") },
|
||||
{ MessageType::GET_CPU_FREQ_LOAD, std::string("get_cpu_freq_load") },
|
||||
{ MessageType::SET_PKG_NAME, std::string("set_pkgName") },
|
||||
{ MessageType::SET_PROCESS_ID, std::string("set_pid") },
|
||||
{ MessageType::GET_FPS_AND_JITTERS, std::string("get_fps_and_jitters") },
|
||||
|
@ -188,25 +188,8 @@ public:
|
||||
continue;
|
||||
}
|
||||
SpProfiler *profiler = SpProfilerFactory::GetProfilerItem(iterator->first);
|
||||
if (profiler == nullptr && (iterator->first == MessageType::SET_PKG_NAME)) {
|
||||
retCode = SplitMsg(recvBuf);
|
||||
SpProfilerFactory::SetProfilerPkg(retCode);
|
||||
spSocket.Sendto(retCode);
|
||||
std::string processId = "";
|
||||
OHOS::SmartPerf::StartUpDelay sp;
|
||||
processId = sp.GetPidByPkg(retCode);
|
||||
SpProfilerFactory::SetProfilerPidByPkg(processId);
|
||||
} else if (profiler == nullptr && (iterator->first == MessageType::FPS_STOP)) {
|
||||
spSocket.Sendto(resultFPS);
|
||||
resultFPS = "FPS||";
|
||||
} else if (profiler == nullptr && (iterator->first == MessageType::CATCH_TRACE_CONFIG ||
|
||||
iterator->first == MessageType::CATCH_TRACE_CMD)) {
|
||||
SpProfilerFactory::SetByTrace(SplitMsg(recvBuf));
|
||||
} else if (profiler == nullptr && (iterator->first == MessageType::BACK_TO_DESKTOP)) {
|
||||
BackDesktop();
|
||||
} else if (profiler == nullptr) {
|
||||
retCode = iterator->second;
|
||||
spSocket.Sendto(retCode);
|
||||
if (profiler == nullptr) {
|
||||
HandleNullMsg(spSocket, profiler, retCode, RecvBuf, iterator);
|
||||
} else {
|
||||
std::map<std::string, std::string> data;
|
||||
if (iterator->first == MessageType::CATCH_NETWORK_TRAFFIC) {
|
||||
@ -245,6 +228,8 @@ public:
|
||||
}
|
||||
}
|
||||
spSocket.Sendto(resultfps);
|
||||
} else if (iterator->first == MessageType::GET_CPU_FREQ_LOAD) {
|
||||
FetchCpuStats(spSocket, data);
|
||||
} else {
|
||||
retCode = MapToString(data);
|
||||
spSocket.Sendto(retCode);
|
||||
@ -255,6 +240,58 @@ public:
|
||||
Heartbeat &heartbeat = Heartbeat::GetInstance();
|
||||
heartbeat.UpdatestartTime();
|
||||
}
|
||||
void FetchCpuStats(SpServerSocket &spSocket, std::map<std::string, std::string> data) const
|
||||
{
|
||||
std::string resultCpuFrequency = "";
|
||||
std::string resultCpuUsage = "";
|
||||
std::string resultCpu = "";
|
||||
int cpuFrequencyNum = 0;
|
||||
int cpuUsageNum = 0;
|
||||
int cpuFlag = 1;
|
||||
while (cpuFlag) {
|
||||
resultCpuFrequency = "cpu" + std::to_string(cpuFrequencyNum) + "Frequency";
|
||||
resultCpuUsage = "cpu" + std::to_string(cpuUsageNum) + "Usage";
|
||||
auto iterCpuFrequency = data.find(resultCpuFrequency);
|
||||
auto iterCpuUsage = data.find(resultCpuUsage);
|
||||
if (iterCpuFrequency != data.end()) {
|
||||
resultCpuFrequency += "||" + iterCpuFrequency->second;
|
||||
resultCpu += "$$" + resultCpuFrequency;
|
||||
cpuFrequencyNum++;
|
||||
} else {
|
||||
cpuFlag = 0;
|
||||
}
|
||||
if (iterCpuUsage != data.end()) {
|
||||
resultCpuUsage += "||" + iterCpuUsage->second;
|
||||
resultCpu += "$$" + resultCpuUsage;
|
||||
cpuUsageNum++;
|
||||
} else {
|
||||
cpuFlag = 0;
|
||||
}
|
||||
}
|
||||
spSocket.Sendto(resultCpu);
|
||||
}
|
||||
void HandleNullMsg(SpServerSocket &spSocket, SpProfiler *profiler, std::string retCode, std::string recvBuf,
|
||||
std::unordered_map<MessageType, std::string>::const_iterator iterator) const
|
||||
{
|
||||
if (iterator->first == MessageType::SET_PKG_NAME) {
|
||||
retCode = SplitMsg(recvBuf);
|
||||
SpProfilerFactory::SetProfilerPkg(retCode);
|
||||
spSocket.Sendto(retCode);
|
||||
} else if (iterator->first == MessageType::FPS_STOP) {
|
||||
spSocket.Sendto(resultFPS);
|
||||
resultFPS = "FPS||";
|
||||
} else if (iterator->first == MessageType::CATCH_TRACE_CONFIG || iterator->first == MessageType::CATCH_TRACE_CMD) {
|
||||
SpProfilerFactory::SetByTrace(SplitMsg(recvBuf));
|
||||
} else if (iterator->first == MessageType::GET_CPU_NUM) {
|
||||
retCode = SPUtils::GetCpuNum();
|
||||
spSocket.Sendto(retCode);
|
||||
} else if (iterator->first == MessageType::BACK_TO_DESKTOP) {
|
||||
BackDesktop();
|
||||
} else {
|
||||
retCode = iterator->second;
|
||||
spSocket.Sendto(retCode);
|
||||
}
|
||||
}
|
||||
};
|
||||
bool SpThreadSocket::flagRunning = false;
|
||||
std::string SpThreadSocket::resultFPS = "FPS||";
|
||||
|
@ -136,6 +136,7 @@ bool VerifyValueStr(std::map<std::string, std::string>& mapInfo, std::string& er
|
||||
bool IntegerValueVerification(std::set<std::string> &keys, std::map<std::string, std::string> &mapInfo,
|
||||
std::string &errorInfo);
|
||||
bool IsHmKernel();
|
||||
std::string GetCpuNum();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,7 @@ SpProfiler *SpProfilerFactory::GetProfilerItem(MessageType messageType)
|
||||
{
|
||||
SpProfiler* profiler = nullptr;
|
||||
switch (messageType) {
|
||||
case MessageType::GET_CPU_NUM:
|
||||
case MessageType::GET_CPU_FREQ:
|
||||
case MessageType::GET_CPU_LOAD:
|
||||
case MessageType::GET_CPU_FREQ_LOAD:
|
||||
profiler = &CPU::GetInstance();
|
||||
break;
|
||||
case MessageType::GET_FPS_AND_JITTERS:
|
||||
|
@ -29,7 +29,12 @@
|
||||
#include "include/sp_utils.h"
|
||||
#include "include/sp_log.h"
|
||||
#include "include/common.h"
|
||||
#include "cpu_collector.h"
|
||||
#include "collect_result.h"
|
||||
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::HiviewDFX::UCollectUtil;
|
||||
using namespace OHOS::HiviewDFX::UCollect;
|
||||
|
||||
namespace OHOS {
|
||||
namespace SmartPerf {
|
||||
@ -607,5 +612,20 @@ bool SPUtils::IsHmKernel()
|
||||
}
|
||||
return isHM;
|
||||
}
|
||||
|
||||
std::string SPUtils::GetCpuNum()
|
||||
{
|
||||
std::string cpuCores = "cpuCores||";
|
||||
std::shared_ptr<CpuCollector> collector = CpuCollector::Create();
|
||||
CollectResult<std::vector<CpuFreq>> result = collector->CollectCpuFrequency();
|
||||
std::vector<CpuFreq> &cpufreq = result.data;
|
||||
int cpuNum = cpufreq.size();
|
||||
cpuCores += std::to_string(cpuNum);
|
||||
if (cpuNum == 0) {
|
||||
std::cout << "CPU frequency collection failed." << std::endl;
|
||||
LOGI("CPU frequency collection failed.");
|
||||
}
|
||||
return cpuCores;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user