Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<KRRenderCore>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> KRPerformanceManager::page_record_;

KRPerformanceManager::KRPerformanceManager(std::string page_name, const std::shared_ptr<KRRenderExecuteMode> &mode)
: page_name_(std::move(page_name)), mode_(mode) {
KRPerformanceManager::KRPerformanceManager(std::string page_name, std::string instance_id, const std::shared_ptr<KRRenderExecuteMode> &mode)
: page_name_(std::move(page_name)), instance_id_(std::move(instance_id)), mode_(mode) {
auto launch_monitor = std::make_shared<KRLaunchMonitor>();
monitors_[KRLaunchMonitor::kMonitorName] = launch_monitor;
auto it = std::find(page_record_.begin(), page_record_.end(), page_name_);
Expand Down Expand Up @@ -92,10 +98,29 @@ void KRPerformanceManager::OnPageCreateFinish(KRPageCreateTrace &trace) { // K
auto launch_monitor = std::static_pointer_cast<KRLaunchMonitor>(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);
Expand All @@ -118,4 +143,24 @@ std::shared_ptr<KRMonitor> 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);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<KRRenderExecuteMode> &mode);
KRPerformanceManager(std::string page_name, std::string instance_id, const std::shared_ptr<KRRenderExecuteMode> &mode);
~KRPerformanceManager();
void OnKRRenderViewInit();
void OnInitCoreStart();
Expand All @@ -40,12 +40,24 @@ class KRPerformanceManager {
void OnResume();
void OnPause();
void OnDestroy();
std::string GetInstanceId();
std::string GetLaunchData();
std::string GetPerformanceData();
std::shared_ptr<KRMonitor> 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<KRRenderExecuteMode> mode_;
int64_t init_time_stamps_ = 0;
bool is_cold_launch = false; // 是否是冷启动
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -216,7 +217,7 @@ void KRRenderView::Init(std::shared_ptr<KRRenderContextParams> context, ArkUI_Co
context_ = context;
ui_context_handle_ = ui_context_handle;
native_resources_manager_ = native_resources_manager;
performance_manager_ = std::make_shared<KRPerformanceManager>(context->PageName(), context->ExecuteMode());
performance_manager_ = std::make_shared<KRPerformanceManager>(context->PageName(), context->InstanceId(), context->ExecuteMode());
performance_manager_->SetArkLaunchTime(launch_time);
root_view_width_ = width;
root_view_height_ = height;
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions core-render-ohos/src/main/ets/KRNativeRenderController.ets
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,17 @@ export class KRNativeRenderController {
return true
}

/**
* 回调启动数据
*/
onGetLaunchData(data: Record<string, number>): void {
}

/**
* 回调性能数据
*/
onGetPerformanceData(data: Record<string, number>): void {
}
}

export abstract class IKuiklyViewDelegate extends KRNativeRenderController {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<string, number> = JSON.parse(params as string);
this.controller?.onGetLaunchData(data);
break;
}
case KRPerformanceModule.METHOD_ON_GET_PERFORMANCE_DATA: {
const data: Record<string, number> = JSON.parse(params as string);
this.controller?.onGetPerformanceData(data);
break;
}
default:
Expand Down