截图优化

Signed-off-by: 钱玉英 <qianyuying@huawei.com>
This commit is contained in:
钱玉英 2024-08-02 16:37:25 +08:00
parent c8552eacb8
commit ae6939653e
4 changed files with 33 additions and 39 deletions

View File

@ -91,18 +91,18 @@ void CPU::SetPackageName(const std::string &pName)
std::vector<CpuFreqs> CPU::GetCpuFreq()
{
OHOS::SmartPerf::CpuFreqs cpuFreqs;
std::vector<CpuFreqs> cpuFreqs2;
std::vector<CpuFreqs> cpuFrequency;
std::shared_ptr<CpuCollector> collector = CpuCollector::Create();
CollectResult<std::vector<CpuFreq>> result = collector->CollectCpuFrequency();
std::vector<CpuFreq> &cpufreq = result.data;
for (size_t i = 0; i < cpufreq.size(); i++) {
cpuFreqs.cpuId = cpufreq[i].cpuId;
cpuFreqs.curFreq = cpufreq[i].curFreq;
cpuFreqs2.push_back(cpuFreqs);
cpuFrequency.push_back(cpuFreqs);
LOGI("cpuFreqs.cpuId: %s", std::to_string(cpufreq[i].cpuId).c_str());
LOGI("cpuFreqs.curFreq: %s", std::to_string(cpufreq[i].curFreq).c_str());
}
return cpuFreqs2;
return cpuFrequency;
}
std::vector<CpuUsageInfos> CPU::GetCpuUsage()

View File

@ -44,7 +44,7 @@ std::map<std::string, std::string> Capture::ItemData()
} else {
std::string path = "data/local/tmp/capture/screenCap_" + std::to_string(curTime) + ".png";
result["capture"] = path;
Capture::TriggerGetCatch(curTime);
Capture::TriggerGetCatch();
if (result.find("capture") != result.end() && result["capture"].empty()) {
result["capture"] = "NA";
}
@ -61,36 +61,31 @@ void Capture::SocketMessage()
isSocketMessage = true;
}
void Capture::ThreadGetCatch(const std::string &curTime) const
void Capture::ThreadGetCatch() const
{
auto savePath = "/data/local/tmp/capture/screenCap_" + curTime + ".png";
if (!SPUtils::FileAccess("/data/local/tmp/capture")) {
std::string cmdResult;
SPUtils::LoadCmd("mkdir /data/local/tmp/capture", cmdResult);
printf("/data/local/tmp/capture created! \n");
LOGI("/data/local/tmp/capture created!");
};
std::stringstream errorRecv;
char realPath[PATH_MAX] = {0x00};
if (realpath(savePath.c_str(), realPath) == nullptr) {
std::cout << "" << std::endl;
return;
} else {
struct stat st;
if (stat(realPath, &st) != 0) {
std::cout << "stat error: " << strerror(errno) << std::endl;
LOGE("open realPath failed: %s", strerror(errno));
} else if (!S_ISDIR(st.st_mode)) {
LOGE("capture savePath is not a directory: %s", realPath);
const std::string curTime = std::to_string(SPUtils::GetCurTime());
const std::string captureDir = "/data/local/tmp/capture";
const std::string savePath = captureDir + "/screenCap_" + curTime + ".jpeg";
std::string cmdResult;
if (!SPUtils::FileAccess(captureDir)) {
if (!SPUtils::LoadCmd("mkdir -p " + captureDir, cmdResult)) {
LOGI("%s capture not be created!", captureDir.c_str());
return;
} else {
auto fd = open(realPath, O_RDWR | O_CREAT, 0666);
if (!TakeScreenCap(savePath)) {
std::cout << "Screen Capture Failed:---" << errorRecv.str() << std::endl;
LOGE("Screen Capture Failed!");
}
close(fd);
LOGI("%s created successfully!", captureDir.c_str());
}
};
std::ostringstream errorRecv;
auto fd = open(savePath.c_str(), O_RDWR | O_CREAT, 0666);
if (fd == -1) {
printf("Failed to open file: %s\n", savePath.c_str());
LOGI("Failed to open file: %s", savePath.c_str());
}
if (!TakeScreenCap(savePath)) {
std::cout << "Screen Capture Failed:---" << errorRecv.str() << std::endl;
LOGE("Screen Capture Failed!");
}
close(fd);
}
@ -126,11 +121,10 @@ void Capture::ThreadGetCatchSocket(const std::string &curTime) const
close(fd);
}
void Capture::TriggerGetCatch(long long curTime) const
void Capture::TriggerGetCatch() const
{
std::string curTimeStr = std::to_string(curTime);
auto tStart = std::thread([this, curTimeStr]() {
this->ThreadGetCatch(curTimeStr);
auto tStart = std::thread([this]() {
this->ThreadGetCatch();
});
tStart.detach();
}

View File

@ -26,10 +26,10 @@ public:
return instance;
}
// 截图线程
void ThreadGetCatch(const std::string &curTime) const;
void ThreadGetCatch() const;
void ThreadGetCatchSocket(const std::string &curTime) const;
// 触发线程
void TriggerGetCatch(long long curTime) const;
void TriggerGetCatch() const;
void TriggerGetCatchSocket(long long curTime) const;
bool TakeScreenCap(const std::string &savePath) const;
void SocketMessage();

View File

@ -209,10 +209,10 @@ void ProfilerFPS::GetSectionsFps(FpsInfoProfiler &fpsInfoResult, int nums) const
long long currLastTime = lastCurrTime;
long long harTime = msJiange / 1000000;
int printCount = 0;
uint32_t count = 0;
size_t count = 0;
long long currTimeStart = 0;
long long currTimeLast = 0;
for (uint32_t i = 0; i < fpsInfoResult.currTimeStamps.size(); i++) {
for (size_t i = 0; i < fpsInfoResult.currTimeStamps.size(); i++) {
long long currTime = fpsInfoResult.currTimeStamps[i];
if (currTime <= msStartTime) {
if (msCount == 0) {
@ -239,7 +239,7 @@ void ProfilerFPS::GetSectionsFps(FpsInfoProfiler &fpsInfoResult, int nums) const
currTimeLast = currTime;
count--;
}
if (i == (static_cast<uint32_t>(fpsInfoResult.currTimeStamps.size()) - 1)) {
if (i == (static_cast<size_t>(fpsInfoResult.currTimeStamps.size()) - 1)) {
PrintSections(msCount, currTimeLast, currTimeStart, currLastTime);
currTimeLast = currTime;
printCount++;