From c8ae706394662db5d6a1eb828203cb0057cf7d19 Mon Sep 17 00:00:00 2001 From: zhuleilei Date: Wed, 20 Nov 2024 15:05:27 +0800 Subject: [PATCH] dump gpu info Signed-off-by: zhuleilei --- .../components_ng/pattern/web/web_pattern.cpp | 35 +++++++++++++++++++ .../components_ng/pattern/web/web_pattern.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.cpp b/frameworks/core/components_ng/pattern/web/web_pattern.cpp index 278ae3b4c82..4191dcfe9b8 100644 --- a/frameworks/core/components_ng/pattern/web/web_pattern.cpp +++ b/frameworks/core/components_ng/pattern/web/web_pattern.cpp @@ -17,6 +17,11 @@ #include #include +#include +#include +#include +#include +#include #include #include #include @@ -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" @@ -315,6 +322,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: @@ -7116,4 +7128,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 diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.h b/frameworks/core/components_ng/pattern/web/web_pattern.h index 32e1fc5c3f1..a76511538ce 100644 --- a/frameworks/core/components_ng/pattern/web/web_pattern.h +++ b/frameworks/core/components_ng/pattern/web/web_pattern.h @@ -685,6 +685,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();