From 987725c23e33f72074d1e31e77ff78f455800e24 Mon Sep 17 00:00:00 2001 From: elixxli Date: Thu, 27 Nov 2025 22:06:55 +0800 Subject: [PATCH 1/2] feat: support ohos performance api arkts callback --- .../cpp/libohos_render/core/KRRenderCore.h | 5 +- .../performance/KRPerformanceManager.cpp | 51 +++++++++++++++++-- .../performance/KRPerformanceManager.h | 14 ++++- .../cpp/libohos_render/view/KRRenderView.cpp | 12 ++++- .../src/main/ets/KRNativeRenderController.ets | 11 ++++ .../ets/modules/KRPerformanceModuleArkTS.ets | 16 +++++- 6 files changed, 101 insertions(+), 8 deletions(-) diff --git a/core-render-ohos/src/main/cpp/libohos_render/core/KRRenderCore.h b/core-render-ohos/src/main/cpp/libohos_render/core/KRRenderCore.h index fecff7ff3..cc832cbd6 100644 --- a/core-render-ohos/src/main/cpp/libohos_render/core/KRRenderCore.h +++ b/core-render-ohos/src/main/cpp/libohos_render/core/KRRenderCore.h @@ -33,7 +33,10 @@ enum class KRInitState { kStateInitContextFinish = 5, kStateCreateInstanceStart = 6, kStateCreateInstanceFinish = 7, - kStateFirstFramePaint = 8 + kStateFirstFramePaint = 8, + kStateResume = 9, + kStatePause = 10, + kStateDestroy = 11, }; class KRRenderCore : public std::enable_shared_from_this, diff --git a/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.cpp b/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.cpp index f0f3e1778..e58e4f2fe 100644 --- a/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.cpp +++ b/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.cpp @@ -15,13 +15,19 @@ #include "KRPerformanceManager.h" +#include "libohos_render/expand/modules/performance/KRPerformanceModule.h" +#include "libohos_render/manager/KRArkTSManager.h" #include "libohos_render/performance/KRPerformanceData.h" +#include "libohos_render/scheduler/KRContextScheduler.h" + +static constexpr char ON_GET_LAUNCH_DATA_DATA[] = "onGetLaunchData"; +static constexpr char ON_GET_PERFORMANCE_DATA_DATA[] = "onGetPerformanceData"; bool KRPerformanceManager::cold_launch_flag = true; std::list KRPerformanceManager::page_record_; -KRPerformanceManager::KRPerformanceManager(std::string page_name, const std::shared_ptr &mode) - : page_name_(std::move(page_name)), mode_(mode) { +KRPerformanceManager::KRPerformanceManager(std::string page_name, std::string instance_id, const std::shared_ptr &mode) + : page_name_(std::move(page_name)), instance_id_(std::move(instance_id)), mode_(mode) { auto launch_monitor = std::make_shared(); monitors_[KRLaunchMonitor::kMonitorName] = launch_monitor; auto it = std::find(page_record_.begin(), page_record_.end(), page_name_); @@ -92,10 +98,29 @@ void KRPerformanceManager::OnPageCreateFinish(KRPageCreateTrace &trace) { // K auto launch_monitor = std::static_pointer_cast(monitor); launch_monitor->OnPageCreateFinish(trace); } + onLaunchResult(); } void KRPerformanceManager::OnResume() {} void KRPerformanceManager::OnPause() {} -void KRPerformanceManager::OnDestroy() {} + +void KRPerformanceManager::OnDestroy() { + for (auto &monitor: monitors_) { + monitor.second->OnDestroy(); + } + onResult(); +} + +std::string KRPerformanceManager::GetInstanceId() { + return instance_id_; +} + +std::string KRPerformanceManager::GetLaunchData() { // 收集启动数据 + auto monitor = GetMonitor(KRLaunchMonitor::kMonitorName); + if (monitor) { + return monitor->GetMonitorData(); + } + return "{}"; +} std::string KRPerformanceManager::GetPerformanceData() { // 收集所有性能数据 auto monitor = GetMonitor(KRLaunchMonitor::kMonitorName); @@ -118,4 +143,24 @@ std::shared_ptr KRPerformanceManager::GetMonitor(std::string monitor_ return monitors_[monitor_name]; } return nullptr; +} + +void KRPerformanceManager::onLaunchResult() { + auto data = GetLaunchData(); + auto instance_id = GetInstanceId(); + KRContextScheduler::ScheduleTaskOnMainThread(false, [instance_id, data] { + KRArkTSManager::GetInstance().CallArkTSMethod(instance_id, KRNativeCallArkTSMethod::CallModuleMethod, + NewKRRenderValue(kuikly::module::kPerformanceModuleName), NewKRRenderValue(ON_GET_LAUNCH_DATA_DATA), + NewKRRenderValue(data), nullptr, nullptr, nullptr); + }); +} + +void KRPerformanceManager::onResult() { + auto data = GetPerformanceData(); + auto instance_id = GetInstanceId(); + KRContextScheduler::ScheduleTaskOnMainThread(false, [instance_id, data] { + KRArkTSManager::GetInstance().CallArkTSMethod(instance_id, KRNativeCallArkTSMethod::CallModuleMethod, + NewKRRenderValue(kuikly::module::kPerformanceModuleName), NewKRRenderValue(ON_GET_PERFORMANCE_DATA_DATA), + NewKRRenderValue(data), nullptr, nullptr, nullptr); + }); } \ No newline at end of file diff --git a/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.h b/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.h index f2c32886f..a9c76689c 100644 --- a/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.h +++ b/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.h @@ -26,7 +26,7 @@ enum class MonitorType { kLaunch = 0, KFrame = 1, KMemory = 2 }; class KRPerformanceManager { public: - KRPerformanceManager(std::string page_name, const std::shared_ptr &mode); + KRPerformanceManager(std::string page_name, std::string instance_id, const std::shared_ptr &mode); ~KRPerformanceManager(); void OnKRRenderViewInit(); void OnInitCoreStart(); @@ -40,12 +40,24 @@ class KRPerformanceManager { void OnResume(); void OnPause(); void OnDestroy(); + std::string GetInstanceId(); + std::string GetLaunchData(); std::string GetPerformanceData(); std::shared_ptr GetMonitor(std::string monitor_name); void SetArkLaunchTime(int64_t launch_time); + /** + * 回调启动数据 + */ + void onLaunchResult(); + /** + * 回调所有性能数据 + */ + void onResult(); + private: std::string page_name_ = ""; + std::string instance_id_ = ""; std::shared_ptr mode_; int64_t init_time_stamps_ = 0; bool is_cold_launch = false; // 是否是冷启动 diff --git a/core-render-ohos/src/main/cpp/libohos_render/view/KRRenderView.cpp b/core-render-ohos/src/main/cpp/libohos_render/view/KRRenderView.cpp index 716b33706..b293c4ba6 100644 --- a/core-render-ohos/src/main/cpp/libohos_render/view/KRRenderView.cpp +++ b/core-render-ohos/src/main/cpp/libohos_render/view/KRRenderView.cpp @@ -101,6 +101,7 @@ void KRRenderView::RemoveRootViewFromContentHandle(bool immediate){ } void KRRenderView::WillDestroy(const std::string &instanceId) { + DispatchInitState(KRInitState::kStateDestroy); core_->WillDealloc(instanceId); // send event to call // delay destroy for core @@ -216,7 +217,7 @@ void KRRenderView::Init(std::shared_ptr context, ArkUI_Co context_ = context; ui_context_handle_ = ui_context_handle; native_resources_manager_ = native_resources_manager; - performance_manager_ = std::make_shared(context->PageName(), context->ExecuteMode()); + performance_manager_ = std::make_shared(context->PageName(), context->InstanceId(), context->ExecuteMode()); performance_manager_->SetArkLaunchTime(launch_time); root_view_width_ = width; root_view_height_ = height; @@ -327,6 +328,15 @@ void KRRenderView::DispatchInitState(KRInitState state) { break; case KRInitState::kStateFirstFramePaint: performance_manager_->OnFirstFramePaint(); + case KRInitState::kStateResume: + // todo + break; + case KRInitState::kStatePause: + // todo + break; + case KRInitState::kStateDestroy: + performance_manager_->OnDestroy(); + break; default: break; } diff --git a/core-render-ohos/src/main/ets/KRNativeRenderController.ets b/core-render-ohos/src/main/ets/KRNativeRenderController.ets index bab3b339b..f2693697d 100644 --- a/core-render-ohos/src/main/ets/KRNativeRenderController.ets +++ b/core-render-ohos/src/main/ets/KRNativeRenderController.ets @@ -710,6 +710,17 @@ export class KRNativeRenderController { return true } + /** + * 回调启动数据 + */ + onGetLaunchData(data: Record): void { + } + + /** + * 回调性能数据 + */ + onGetPerformanceData(data: Record): void { + } } export abstract class IKuiklyViewDelegate extends KRNativeRenderController { diff --git a/core-render-ohos/src/main/ets/modules/KRPerformanceModuleArkTS.ets b/core-render-ohos/src/main/ets/modules/KRPerformanceModuleArkTS.ets index 1aee36046..38f244408 100644 --- a/core-render-ohos/src/main/ets/modules/KRPerformanceModuleArkTS.ets +++ b/core-render-ohos/src/main/ets/modules/KRPerformanceModuleArkTS.ets @@ -1,9 +1,11 @@ -import { KRAny, KuiklyRenderCallback } from '../utils/KRDataTypes' +import { KRAny, KRRecord, KuiklyRenderCallback } from '../utils/KRDataTypes' import { KuiklyRenderBaseModule } from './export' export class KRPerformanceModule extends KuiklyRenderBaseModule { static readonly MODULE_NAME = "KRPerformanceModule" private static readonly METHOD_NOTIFY_INIT_STATE: string = "notifyInitState" + private static readonly METHOD_ON_GET_LAUNCH_DATA: string = "onGetLaunchData" + private static readonly METHOD_ON_GET_PERFORMANCE_DATA: string = "onGetPerformanceData" syncMode(): boolean { return false; @@ -12,7 +14,17 @@ export class KRPerformanceModule extends KuiklyRenderBaseModule { call(method: string, params: KRAny, callback: KuiklyRenderCallback | null): KRAny { switch (method) { case KRPerformanceModule.METHOD_NOTIFY_INIT_STATE: { - this.controller?.dispatchLifecycleStateChanged(params as number) + this.controller?.dispatchLifecycleStateChanged(params as number); + break; + } + case KRPerformanceModule.METHOD_ON_GET_LAUNCH_DATA: { + const data: Record = JSON.parse(params as string); + this.controller?.onGetLaunchData(data); + break; + } + case KRPerformanceModule.METHOD_ON_GET_PERFORMANCE_DATA: { + const data: Record = JSON.parse(params as string); + this.controller?.onGetPerformanceData(data); break; } default: From 6a5a535d7b5b581c0dffc3916d3009883ecfecda Mon Sep 17 00:00:00 2001 From: elixxli Date: Mon, 8 Dec 2025 11:18:34 +0800 Subject: [PATCH 2/2] feat: modify some detail --- core-render-ohos/Index.ets | 2 +- .../components/input/KRTextAreaView.cpp | 2 +- .../components/input/KRTextFieldView.cpp | 2 +- .../cpp/libohos_render/foundation/KRConfig.h | 12 ++++++- .../performance/KRPerformanceManager.cpp | 35 ++++++++++--------- .../performance/KRPerformanceManager.h | 15 ++++++-- .../cpp/libohos_render/view/KRRenderView.cpp | 3 +- .../src/main/ets/KRNativeRenderController.ets | 26 ++++++++++++-- .../ets/modules/KRPerformanceModuleArkTS.ets | 9 +++-- 9 files changed, 78 insertions(+), 28 deletions(-) diff --git a/core-render-ohos/Index.ets b/core-render-ohos/Index.ets index f687c01ac..bb03018d3 100644 --- a/core-render-ohos/Index.ets +++ b/core-render-ohos/Index.ets @@ -37,7 +37,7 @@ export * from './src/main/ets/modules/export'; export { KRNativeRender as Kuikly } from './src/main/ets/KRNativeRender'; -export { IKuiklyViewDelegate, KRNativeRenderController, IKuiklyRenderViewLifecycleCallback } from './src/main/ets/KRNativeRenderController'; +export { IKuiklyViewDelegate, KRNativeRenderController, IKuiklyRenderViewLifecycleCallback, KRMonitorType } from './src/main/ets/KRNativeRenderController'; // 兼容旧版本 export { KRNativeRenderController as KTNativeRenderController } from './src/main/ets/KRNativeRenderController'; diff --git a/core-render-ohos/src/main/cpp/libohos_render/expand/components/input/KRTextAreaView.cpp b/core-render-ohos/src/main/cpp/libohos_render/expand/components/input/KRTextAreaView.cpp index c0852b51f..33f1ba3ca 100644 --- a/core-render-ohos/src/main/cpp/libohos_render/expand/components/input/KRTextAreaView.cpp +++ b/core-render-ohos/src/main/cpp/libohos_render/expand/components/input/KRTextAreaView.cpp @@ -85,7 +85,7 @@ void KRTextAreaView::UpdateInputNodePlaceholderFont(uint32_t font_size, ArkUI_Fo bool fontSizeScaleFollowSystem = true; bool font_size_px = 0; if (rootView) { - fontSizeScaleFollowSystem = rootView->GetContext()->Config()->fontSizeScaleFollowSystem(); + fontSizeScaleFollowSystem = rootView->GetContext()->Config()->GetFontSizeScaleFollowSystem(); font_size_px = rootView->GetContext()->Config()->fp2px(font_size); } float font_size_temp = font_size; diff --git a/core-render-ohos/src/main/cpp/libohos_render/expand/components/input/KRTextFieldView.cpp b/core-render-ohos/src/main/cpp/libohos_render/expand/components/input/KRTextFieldView.cpp index 622c9990c..b990cf985 100644 --- a/core-render-ohos/src/main/cpp/libohos_render/expand/components/input/KRTextFieldView.cpp +++ b/core-render-ohos/src/main/cpp/libohos_render/expand/components/input/KRTextFieldView.cpp @@ -111,7 +111,7 @@ void KRTextFieldView::UpdateInputNodePlaceholderFont(uint32_t font_size, ArkUI_F bool fontSizeScaleFollowSystem = true; float font_size_px = 0; if (rootView) { - fontSizeScaleFollowSystem = rootView->GetContext()->Config()->fontSizeScaleFollowSystem(); + fontSizeScaleFollowSystem = rootView->GetContext()->Config()->GetFontSizeScaleFollowSystem(); font_size_px = rootView->GetContext()->Config()->fp2px(font_size); } kuikly::util::UpdateInputNodePlaceholderFont(GetNode(), font_size, font_weight, fontSizeScaleFollowSystem, font_size_px); diff --git a/core-render-ohos/src/main/cpp/libohos_render/foundation/KRConfig.h b/core-render-ohos/src/main/cpp/libohos_render/foundation/KRConfig.h index 6169fe86c..36fee5f8b 100644 --- a/core-render-ohos/src/main/cpp/libohos_render/foundation/KRConfig.h +++ b/core-render-ohos/src/main/cpp/libohos_render/foundation/KRConfig.h @@ -89,6 +89,11 @@ class KRConfig { if (fontSizeScaleFollowSystem != map.end()) { fontSizeScaleFollowSystem_ = fontSizeScaleFollowSystem->second->toBool(); } + + auto performanceMonitorTypesMask = map.find("performanceMonitorTypesMask"); + if (performanceMonitorTypesMask != map.end()) { + performanceMonitorTypesMask_ = performanceMonitorTypesMask->second->toInt(); + } } /** @@ -161,10 +166,14 @@ class KRConfig { return window_id_; } - const bool fontSizeScaleFollowSystem() { + const bool GetFontSizeScaleFollowSystem() { return fontSizeScaleFollowSystem_; } + const int GetPerformanceMonitorTypesMask() { + return performanceMonitorTypesMask_; + } + private: float vp2px_ = 0; float fontWeightScale_ = 1; @@ -178,6 +187,7 @@ class KRConfig { std::string window_id_; // 页面所在的窗口ID,用于标识页面所在的窗口 bool ime_mode_ = false; bool fontSizeScaleFollowSystem_ = true; + int performanceMonitorTypesMask_ = 0; }; #endif // CORE_RENDER_OHOS_KRCONFIG_H diff --git a/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.cpp b/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.cpp index e58e4f2fe..a371d0c92 100644 --- a/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.cpp +++ b/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.cpp @@ -26,10 +26,12 @@ static constexpr char ON_GET_PERFORMANCE_DATA_DATA[] = "onGetPerformanceData"; bool KRPerformanceManager::cold_launch_flag = true; std::list KRPerformanceManager::page_record_; -KRPerformanceManager::KRPerformanceManager(std::string page_name, std::string instance_id, const std::shared_ptr &mode) - : page_name_(std::move(page_name)), instance_id_(std::move(instance_id)), mode_(mode) { - auto launch_monitor = std::make_shared(); - monitors_[KRLaunchMonitor::kMonitorName] = launch_monitor; +KRPerformanceManager::KRPerformanceManager(int performance_monitor_types_mask, std::string page_name, std::string instance_id, const std::shared_ptr &mode) + : performance_monitor_types_mask_(performance_monitor_types_mask), page_name_(std::move(page_name)), instance_id_(std::move(instance_id)), mode_(mode) { + if (performance_monitor_types_mask_ & kMonitorTypeLaunch) { + auto launch_monitor = std::make_shared(); + monitors_[KRLaunchMonitor::kMonitorName] = launch_monitor; + } auto it = std::find(page_record_.begin(), page_record_.end(), page_name_); if (it == page_record_.end()) { // 页面未曾加载过 is_page_cold_launch = true; @@ -97,8 +99,8 @@ void KRPerformanceManager::OnPageCreateFinish(KRPageCreateTrace &trace) { // K if (monitor) { auto launch_monitor = std::static_pointer_cast(monitor); launch_monitor->OnPageCreateFinish(trace); + OnLaunchResult(); } - onLaunchResult(); } void KRPerformanceManager::OnResume() {} void KRPerformanceManager::OnPause() {} @@ -107,7 +109,9 @@ void KRPerformanceManager::OnDestroy() { for (auto &monitor: monitors_) { monitor.second->OnDestroy(); } - onResult(); + if (!monitors_.empty()) { + OnResult(); + } } std::string KRPerformanceManager::GetInstanceId() { @@ -145,22 +149,21 @@ std::shared_ptr KRPerformanceManager::GetMonitor(std::string monitor_ return nullptr; } -void KRPerformanceManager::onLaunchResult() { +void KRPerformanceManager::OnLaunchResult() { auto data = GetLaunchData(); - auto instance_id = GetInstanceId(); - KRContextScheduler::ScheduleTaskOnMainThread(false, [instance_id, data] { - KRArkTSManager::GetInstance().CallArkTSMethod(instance_id, KRNativeCallArkTSMethod::CallModuleMethod, - NewKRRenderValue(kuikly::module::kPerformanceModuleName), NewKRRenderValue(ON_GET_LAUNCH_DATA_DATA), - NewKRRenderValue(data), nullptr, nullptr, nullptr); - }); + CallArkTsPerformanceModule(ON_GET_LAUNCH_DATA_DATA, data); } -void KRPerformanceManager::onResult() { +void KRPerformanceManager::OnResult() { auto data = GetPerformanceData(); + CallArkTsPerformanceModule(ON_GET_PERFORMANCE_DATA_DATA, data); +} + +void KRPerformanceManager::CallArkTsPerformanceModule(const char* method_name, std::string &data) { auto instance_id = GetInstanceId(); - KRContextScheduler::ScheduleTaskOnMainThread(false, [instance_id, data] { + KRContextScheduler::ScheduleTaskOnMainThread(false, [instance_id, method_name, data] { KRArkTSManager::GetInstance().CallArkTSMethod(instance_id, KRNativeCallArkTSMethod::CallModuleMethod, - NewKRRenderValue(kuikly::module::kPerformanceModuleName), NewKRRenderValue(ON_GET_PERFORMANCE_DATA_DATA), + NewKRRenderValue("KRPerformanceModule"), NewKRRenderValue(method_name), NewKRRenderValue(data), nullptr, nullptr, nullptr); }); } \ No newline at end of file diff --git a/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.h b/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.h index a9c76689c..6c98fbbfc 100644 --- a/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.h +++ b/core-render-ohos/src/main/cpp/libohos_render/performance/KRPerformanceManager.h @@ -26,7 +26,7 @@ enum class MonitorType { kLaunch = 0, KFrame = 1, KMemory = 2 }; class KRPerformanceManager { public: - KRPerformanceManager(std::string page_name, std::string instance_id, const std::shared_ptr &mode); + KRPerformanceManager(int performance_monitor_types_mask, std::string page_name, std::string instance_id, const std::shared_ptr &mode); ~KRPerformanceManager(); void OnKRRenderViewInit(); void OnInitCoreStart(); @@ -49,13 +49,17 @@ class KRPerformanceManager { /** * 回调启动数据 */ - void onLaunchResult(); + void OnLaunchResult(); /** * 回调所有性能数据 */ - void onResult(); + void OnResult(); +private: + void CallArkTsPerformanceModule(const char* module_name, std::string &data); + private: + int performance_monitor_types_mask_ = 0; std::string page_name_ = ""; std::string instance_id_ = ""; std::shared_ptr mode_; @@ -66,4 +70,9 @@ class KRPerformanceManager { static std::list page_record_; // 静态变量,全局记录页面是否曾经加载过 static bool cold_launch_flag; // 静态变量,用于标识进程是否首次启动 }; + +enum MonitorTypeMask { + kMonitorTypeLaunch = 1 << 0, // 1 启动监控 +}; + #endif // CORE_RENDER_OHOS_KRPERFORMANCEMANAGER_H diff --git a/core-render-ohos/src/main/cpp/libohos_render/view/KRRenderView.cpp b/core-render-ohos/src/main/cpp/libohos_render/view/KRRenderView.cpp index b293c4ba6..699dc2cac 100644 --- a/core-render-ohos/src/main/cpp/libohos_render/view/KRRenderView.cpp +++ b/core-render-ohos/src/main/cpp/libohos_render/view/KRRenderView.cpp @@ -217,7 +217,8 @@ void KRRenderView::Init(std::shared_ptr context, ArkUI_Co context_ = context; ui_context_handle_ = ui_context_handle; native_resources_manager_ = native_resources_manager; - performance_manager_ = std::make_shared(context->PageName(), context->InstanceId(), context->ExecuteMode()); + int performanceMonitorTypesMask = context->Config()->GetPerformanceMonitorTypesMask(); + performance_manager_ = std::make_shared(performanceMonitorTypesMask, context->PageName(), context->InstanceId(), context->ExecuteMode()); performance_manager_->SetArkLaunchTime(launch_time); root_view_width_ = width; root_view_height_ = height; diff --git a/core-render-ohos/src/main/ets/KRNativeRenderController.ets b/core-render-ohos/src/main/ets/KRNativeRenderController.ets index f2693697d..580146f9c 100644 --- a/core-render-ohos/src/main/ets/KRNativeRenderController.ets +++ b/core-render-ohos/src/main/ets/KRNativeRenderController.ets @@ -635,8 +635,9 @@ export class KRNativeRenderController { 'fontWeightScale': this.fontWeightScale, 'fontSizeScale': this.fontSizeScale, 'imeMode': this.imeMode ? 1 : 0, - "windowId": this.windowId, - 'fontSizeScaleFollowSystem': this.fontSizeScaleFollowSystem() ? 1 : 0 + 'windowId': this.windowId, + 'fontSizeScaleFollowSystem': this.fontSizeScaleFollowSystem() ? 1 : 0, + 'performanceMonitorTypesMask': this.getMonitorTypeMask(), }; return JSON.stringify(data); @@ -721,6 +722,20 @@ export class KRNativeRenderController { */ onGetPerformanceData(data: Record): void { } + + /** + * Kuikly框架设置性能监控选项,默认只开启动监控 + * @return Array: 需要设置的性能监控选项列表(目前仅支持启动监控) + */ + performanceMonitorTypes(): Array { + return [KRMonitorType.LAUNCH]; + } + + private getMonitorTypeMask(): number { + const mask = this.performanceMonitorTypes().reduce((acc: KRMonitorType, cur: KRMonitorType) => acc | cur, 0); + return mask; + } + } export abstract class IKuiklyViewDelegate extends KRNativeRenderController { @@ -817,4 +832,11 @@ export interface IKuiklyRenderViewLifecycleCallback { */ onFirstFramePaint(): void +} + +/** + * 性能监控类型 + */ +export enum KRMonitorType { + LAUNCH = 1 << 0, // 1 启动监控 } \ No newline at end of file diff --git a/core-render-ohos/src/main/ets/modules/KRPerformanceModuleArkTS.ets b/core-render-ohos/src/main/ets/modules/KRPerformanceModuleArkTS.ets index 38f244408..40a4213f2 100644 --- a/core-render-ohos/src/main/ets/modules/KRPerformanceModuleArkTS.ets +++ b/core-render-ohos/src/main/ets/modules/KRPerformanceModuleArkTS.ets @@ -1,3 +1,4 @@ +import { KRMonitorType } from '../KRNativeRenderController' import { KRAny, KRRecord, KuiklyRenderCallback } from '../utils/KRDataTypes' import { KuiklyRenderBaseModule } from './export' @@ -19,12 +20,16 @@ export class KRPerformanceModule extends KuiklyRenderBaseModule { } case KRPerformanceModule.METHOD_ON_GET_LAUNCH_DATA: { const data: Record = JSON.parse(params as string); - this.controller?.onGetLaunchData(data); + if (this.controller?.performanceMonitorTypes().includes(KRMonitorType.LAUNCH)) { + this.controller?.onGetLaunchData(data); + } break; } case KRPerformanceModule.METHOD_ON_GET_PERFORMANCE_DATA: { const data: Record = JSON.parse(params as string); - this.controller?.onGetPerformanceData(data); + if (this.controller?.performanceMonitorTypes().length != 0) { + this.controller?.onGetPerformanceData(data); + } break; } default: