!47792 获取gpu内存大小

Merge pull request !47792 from zhuleilei/master
This commit is contained in:
openharmony_ci 2024-11-21 15:43:21 +00:00 committed by Gitee
commit b6be188051
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 37 additions and 0 deletions

View File

@ -17,6 +17,11 @@
#include <securec.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <sstream>
#include <string_ex.h>
#include <unordered_map>
#include <vector>
@ -37,6 +42,8 @@
#include "base/geometry/ng/offset_t.h"
#include "base/geometry/rect.h"
#include "base/image/file_uri_helper.h"
#include "base/log/dump_log.h"
#include "base/utils/utils.h"
#include "base/mousestyle/mouse_style.h"
#include "base/utils/date_util.h"
#include "base/utils/linear_map.h"
@ -318,6 +325,11 @@ const std::string IS_HINT_TYPE = "{\"isHint2Type\": true}";
const std::string STRING_LF = "\n";
#define WEB_ACCESSIBILITY_DELAY_TIME 100
#define GPU_ABNORMAL_VALUE (32 * 1024)
#define GPU_SERIOUS_ABNORMAL_VALUE (32 * 1024 * 1024)
#define SIZE_UNIT 1024
#define FLOAT_UNIT 100.0F
#define DECIMAL_POINTS 2
class WebAccessibilityChildTreeCallback : public AccessibilityChildTreeCallback {
public:
@ -7179,4 +7191,27 @@ bool WebPattern::GetAccessibilityVisible(int64_t accessibilityId)
}
return true;
}
void WebPattern::DumpInfo()
{
float totalSize = DumpGpuInfo();
if (totalSize > GPU_SERIOUS_ABNORMAL_VALUE) {
totalSize = totalSize / SIZE_UNIT / SIZE_UNIT; // 转换成MB
} else if (totalSize > GPU_ABNORMAL_VALUE) {
totalSize = totalSize / SIZE_UNIT;
}
totalSize = std::round(totalSize * FLOAT_UNIT) / FLOAT_UNIT; // 变为浮点数
// 使用ostringstream来格式化数字为字符串
std::ostringstream oss;
oss << std::fixed << std::setprecision(DECIMAL_POINTS) << totalSize; // 转换成保留两位小数的字符串
std::string formattedSize = oss.str(); // 获取格式化后的字符串
DumpLog::GetInstance().Print("------------GpuMemoryInfo-----------");
DumpLog::GetInstance().Print("Total Gpu Memory size: " + formattedSize + "(MB)");
}
float WebPattern::DumpGpuInfo()
{
float totalSize = delegate_->GetNweb()->DumpGpuInfo();
return totalSize;
}
} // namespace OHOS::Ace::NG

View File

@ -688,6 +688,8 @@ public:
void RegisterWebComponentClickCallback(WebComponentClickCallback&& callback);
void UnregisterWebComponentClickCallback();
WebComponentClickCallback GetWebComponentClickCallback() const { return webComponentClickCallback_; }
void DumpInfo() override;
float DumpGpuInfo();
void OnSetAccessibilityChildTree(int32_t childWindowId, int32_t childTreeId);
bool OnAccessibilityChildTreeRegister();
bool OnAccessibilityChildTreeDeregister();