From e744c651b8c408a0e42f72e061beea9b656185b2 Mon Sep 17 00:00:00 2001 From: dzf Date: Mon, 15 Jan 2024 21:43:11 +0800 Subject: [PATCH] add the constructor of ILongFrame Signed-off-by: dzf --- ace_config.gni | 8 +++++ adapter/ohos/osal/BUILD.gn | 8 +++-- adapter/ohos/osal/long_frame_report_impl.cpp | 29 +++++++++++++------ adapter/ohos/osal/long_frame_report_impl.h | 6 ++-- adapter/preview/osal/BUILD.gn | 6 +++- .../preview/osal/long_frame_report_impl.cpp | 5 ++++ frameworks/base/longframe/long_frame_report.h | 4 ++- frameworks/base/ressched/ressched_report.cpp | 8 +++++ .../core/pipeline_ng/ui_task_scheduler.cpp | 27 +++++++++++++++-- .../core/pipeline_ng/ui_task_scheduler.h | 3 +- test/mock/base/mock_long_frame_report.cpp | 5 ++++ test/unittest/core/pipeline/BUILD.gn | 6 ++-- 12 files changed, 94 insertions(+), 21 deletions(-) diff --git a/ace_config.gni b/ace_config.gni index 01d2fc97fb5..de8f5754046 100644 --- a/ace_config.gni +++ b/ace_config.gni @@ -234,6 +234,14 @@ if (!defined(global_parts_info) || security_component_enable = false } +if (defined(global_parts_info) && + defined(global_parts_info.resourceschedule_ffrt)) { + ace_common_defines += [ "FFRT_EXISTS" ] + resourceschedule_ffrt_support = true +} else { + resourceschedule_ffrt_support = false +} + ace_platforms = [] _ace_adapter_dir = rebase_path("$ace_root/adapter", root_build_dir) diff --git a/adapter/ohos/osal/BUILD.gn b/adapter/ohos/osal/BUILD.gn index 163be4881c2..019a364a7cb 100644 --- a/adapter/ohos/osal/BUILD.gn +++ b/adapter/ohos/osal/BUILD.gn @@ -69,7 +69,6 @@ template("ace_osal_ohos_source_set") { "image_analyzer_mgr.cpp", "layout_inspector.cpp", "log_wrapper.cpp", - "long_frame_report_impl.cpp", "modal_ui_extension_impl.cpp", "ressched_report.cpp", "socperf_client_impl.cpp", @@ -81,7 +80,6 @@ template("ace_osal_ohos_source_set") { external_deps += [ "ability_runtime:app_manager", - "ffrt:libffrt", "i18n:intl_util", "init:libbegetutil", ] @@ -101,6 +99,12 @@ template("ace_osal_ohos_source_set") { defines += [ "SOC_PERF_ENABLE" ] } + if (defined(resourceschedule_ffrt_support) && + resourceschedule_ffrt_support) { + sources += [ "long_frame_report_impl.cpp" ] + external_deps += [ "ffrt:libffrt" ] + } + external_deps += [ "ability_base:view_data", "ability_base:want", diff --git a/adapter/ohos/osal/long_frame_report_impl.cpp b/adapter/ohos/osal/long_frame_report_impl.cpp index 6d4577fc771..9583e5c66ee 100644 --- a/adapter/ohos/osal/long_frame_report_impl.cpp +++ b/adapter/ohos/osal/long_frame_report_impl.cpp @@ -15,6 +15,8 @@ #include "adapter/ohos/osal/long_frame_report_impl.h" +#include + #include "base/longframe/long_frame_report.h" #include "base/ressched/ressched_report.h" @@ -22,35 +24,44 @@ namespace OHOS::Ace { namespace { constexpr int32_t LONG_FRAME_EVENT_DELAY = 10000; } -LongFrameReportImpl::LongFrameReportImpl() -{ - ffrtTaskQueue = std::make_unique("long_frame_report_ffrt_queue", - ffrt::queue_attr().qos(ffrt::qos_user_initiated)); -} void LongFrameReportImpl::SubmitEvent() { - ffrtTask = ffrtTaskQueue->submit_h([] { + ffrtTask = ffrt::submit_h([] { ResSchedReport::GetInstance().ResSchedDataReport("long_frame_start"); - }, ffrt::task_attr().delay(LONG_FRAME_EVENT_DELAY)); + }, {}, {}, ffrt::task_attr().delay(LONG_FRAME_EVENT_DELAY)); } void LongFrameReportImpl::CancelEvent() { - if (ffrtTaskQueue->cancel(ffrtTask)) { - ffrtTaskQueue->wait(ffrtTask); + if (ffrt::skip(ffrtTask)) { + ffrt::wait({ffrtTask}); ResSchedReport::GetInstance().ResSchedDataReport("long_frame_end"); } } +ILongFrame::ILongFrame() +{ + if (access(LIBFFRT_LIB64_PATH, F_OK) == -1) { + return ; + } + is64BitSystem_ = true; +} + void ILongFrame::ReportStartEvent() { + if (!is64BitSystem_) { + return ; + } reporter = new LongFrameReportImpl(); static_cast(reporter)->SubmitEvent(); } void ILongFrame::ReportEndEvent() { + if (!is64BitSystem_) { + return ; + } static_cast(reporter)->CancelEvent(); delete static_cast(reporter); } diff --git a/adapter/ohos/osal/long_frame_report_impl.h b/adapter/ohos/osal/long_frame_report_impl.h index d8e1c8cd7c0..d1a0948c3c4 100644 --- a/adapter/ohos/osal/long_frame_report_impl.h +++ b/adapter/ohos/osal/long_frame_report_impl.h @@ -17,17 +17,17 @@ #define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_LONG_FRAME_REPORT_IMPL_H #include "base/longframe/long_frame_report.h" -#include "ffrt.h" +#include "ffrt_inner.h" namespace OHOS::Ace { class LongFrameReportImpl { public: - LongFrameReportImpl(); + LongFrameReportImpl() = default; ~LongFrameReportImpl() = default; void SubmitEvent(); void CancelEvent(); - std::unique_ptr ffrtTaskQueue = nullptr; +private: ffrt::task_handle ffrtTask; }; } // namespace OHOS::Ace diff --git a/adapter/preview/osal/BUILD.gn b/adapter/preview/osal/BUILD.gn index 7dac6854427..20691b733ef 100644 --- a/adapter/preview/osal/BUILD.gn +++ b/adapter/preview/osal/BUILD.gn @@ -73,7 +73,6 @@ ohos_source_set("preview_osal_source") { "file_uri_helper_preview.cpp", "frame_report.cpp", "image_source_preview.cpp", - "long_frame_report_impl.cpp", "modal_ui_extension_impl.cpp", "mouse_style_ohos.cpp", "pixel_map_preview.cpp", @@ -88,6 +87,11 @@ ohos_source_set("preview_osal_source") { "view_data_wrap_impl.cpp", ] + if (defined(resourceschedule_ffrt_support) && + resourceschedule_ffrt_support) { + sources += [ "long_frame_report_impl.cpp" ] + } + cflags_cc = [ "-DNAME_MAX=128", "-Wno-inconsistent-dllimport", diff --git a/adapter/preview/osal/long_frame_report_impl.cpp b/adapter/preview/osal/long_frame_report_impl.cpp index 0fb6caf554a..03248fb1824 100644 --- a/adapter/preview/osal/long_frame_report_impl.cpp +++ b/adapter/preview/osal/long_frame_report_impl.cpp @@ -16,8 +16,13 @@ #include "base/longframe/long_frame_report.h" namespace OHOS::Ace { +ILongFrame::ILongFrame() +{ +} + void ILongFrame::ReportStartEvent() { + reporter = nullptr; } void ILongFrame::ReportEndEvent() diff --git a/frameworks/base/longframe/long_frame_report.h b/frameworks/base/longframe/long_frame_report.h index 1fd1e2a7ba3..03aa71959ac 100644 --- a/frameworks/base/longframe/long_frame_report.h +++ b/frameworks/base/longframe/long_frame_report.h @@ -23,10 +23,12 @@ typedef void* EventReport; class ACE_EXPORT ILongFrame final { public: - ILongFrame() = default; + ILongFrame(); ~ILongFrame() = default; void ReportStartEvent(); void ReportEndEvent(); + +private: EventReport reporter = nullptr; }; } // namespace OHOS::Ace diff --git a/frameworks/base/ressched/ressched_report.cpp b/frameworks/base/ressched/ressched_report.cpp index dcd639be212..044d4e8e802 100644 --- a/frameworks/base/ressched/ressched_report.cpp +++ b/frameworks/base/ressched/ressched_report.cpp @@ -27,7 +27,9 @@ constexpr uint32_t RES_TYPE_SLIDE = 11; constexpr uint32_t RES_TYPE_POP_PAGE = 28; constexpr uint32_t RES_TYPE_WEB_GESTURE = 29; constexpr uint32_t RES_TYPE_LOAD_PAGE = 34; +#ifdef FFRT_EXISTS constexpr uint32_t RES_TYPE_LONG_FRAME = 71; +#endif constexpr int32_t TOUCH_EVENT = 1; constexpr int32_t CLICK_EVENT = 2; constexpr int32_t SLIDE_OFF_EVENT = 0; @@ -35,8 +37,10 @@ constexpr int32_t SLIDE_ON_EVENT = 1; constexpr int32_t PUSH_PAGE_START_EVENT = 0; constexpr int32_t PUSH_PAGE_COMPLETE_EVENT = 1; constexpr int32_t POP_PAGE_EVENT = 0; +#ifdef FFRT_EXISTS constexpr int32_t LONG_FRAME_START_EVENT = 0; constexpr int32_t LONG_FRAME_END_EVENT = 1; +#endif constexpr char NAME[] = "name"; constexpr char PID[] = "pid"; constexpr char UID[] = "uid"; @@ -50,8 +54,10 @@ constexpr char SLIDE_OFF[] = "slide_off"; constexpr char TOUCH[] = "touch"; constexpr char WEB_GESTURE[] = "web_gesture"; constexpr char LOAD_PAGE[] = "load_page"; +#ifdef FFRT_EXISTS constexpr char LONG_FRAME_START[] = "long_frame_start"; constexpr char LONG_FRAME_END[] = "long_frame_end"; +#endif void LoadAceApplicationContext(std::unordered_map& payload) { @@ -107,6 +113,7 @@ void ResSchedReport::ResSchedDataReport(const char* name, const std::unordered_m reportDataFunc_(RES_TYPE_WEB_GESTURE, 0, payload); } }, +#ifdef FFRT_EXISTS { LONG_FRAME_START, [this](std::unordered_map& payload) { LoadAceApplicationContext(payload); @@ -119,6 +126,7 @@ void ResSchedReport::ResSchedDataReport(const char* name, const std::unordered_m reportDataFunc_(RES_TYPE_LONG_FRAME, LONG_FRAME_END_EVENT, payload); } }, +#endif }; auto it = functionMap.find(name); if (it == functionMap.end()) { diff --git a/frameworks/core/pipeline_ng/ui_task_scheduler.cpp b/frameworks/core/pipeline_ng/ui_task_scheduler.cpp index 3abdfae6070..b4a74a8a969 100644 --- a/frameworks/core/pipeline_ng/ui_task_scheduler.cpp +++ b/frameworks/core/pipeline_ng/ui_task_scheduler.cpp @@ -15,8 +15,12 @@ #include "core/pipeline_ng/ui_task_scheduler.h" +#include + #include "base/log/frame_report.h" +#ifdef FFRT_EXISTS #include "base/longframe/long_frame_report.h" +#endif #include "base/memory/referenced.h" #include "base/utils/time_util.h" #include "base/utils/utils.h" @@ -27,8 +31,19 @@ #include "core/pipeline_ng/pipeline_context.h" namespace OHOS::Ace::NG { +namespace { + const char* LIBFFRT_LIB64_PATH = "/system/lib64/ndk/libffrt.z.so"; +} uint64_t UITaskScheduler::frameId_ = 0; +UITaskScheduler::UITaskScheduler() +{ + if (access(LIBFFRT_LIB64_PATH, F_OK) == -1) { + return ; + } + is64BitSystem_ = true; +} + UITaskScheduler::~UITaskScheduler() { persistAfterLayoutTasks_.clear(); @@ -90,9 +105,13 @@ void UITaskScheduler::FlushLayoutTask(bool forceUseMainThread) abort(); } +#ifdef FFRT_EXISTS // Pause GC during long frame std::unique_ptr longFrame = std::make_unique(); - longFrame->ReportStartEvent(); + if (is64BitSystem_) { + longFrame->ReportStartEvent(); + } +#endif isLayouting_ = true; auto dirtyLayoutNodes = std::move(dirtyLayoutNodes_); @@ -114,7 +133,11 @@ void UITaskScheduler::FlushLayoutTask(bool forceUseMainThread) } ExpandSafeArea(); - longFrame->ReportEndEvent(); +#ifdef FFRT_EXISTS + if (is64BitSystem_) { + longFrame->ReportEndEvent(); + } +#endif isLayouting_ = false; } diff --git a/frameworks/core/pipeline_ng/ui_task_scheduler.h b/frameworks/core/pipeline_ng/ui_task_scheduler.h index 9043aacefbf..a2ea0e34e9d 100755 --- a/frameworks/core/pipeline_ng/ui_task_scheduler.h +++ b/frameworks/core/pipeline_ng/ui_task_scheduler.h @@ -70,7 +70,7 @@ private: class ACE_EXPORT UITaskScheduler final { public: using PredictTask = std::function; - UITaskScheduler() = default; + UITaskScheduler(); ~UITaskScheduler(); // Called on Main Thread. @@ -163,6 +163,7 @@ private: std::list> persistAfterLayoutTasks_; uint32_t currentPageId_ = 0; + bool is64BitSystem_ = false; bool isLayouting_ = false; FrameInfo* frameInfo_ = nullptr; diff --git a/test/mock/base/mock_long_frame_report.cpp b/test/mock/base/mock_long_frame_report.cpp index 0fb6caf554a..03248fb1824 100644 --- a/test/mock/base/mock_long_frame_report.cpp +++ b/test/mock/base/mock_long_frame_report.cpp @@ -16,8 +16,13 @@ #include "base/longframe/long_frame_report.h" namespace OHOS::Ace { +ILongFrame::ILongFrame() +{ +} + void ILongFrame::ReportStartEvent() { + reporter = nullptr; } void ILongFrame::ReportEndEvent() diff --git a/test/unittest/core/pipeline/BUILD.gn b/test/unittest/core/pipeline/BUILD.gn index 8719b1619b0..7c7dacebf50 100644 --- a/test/unittest/core/pipeline/BUILD.gn +++ b/test/unittest/core/pipeline/BUILD.gn @@ -49,7 +49,6 @@ ace_unittest("pipeline_context_test_ng") { "$ace_root/test/mock/base/mock_image_source.cpp", "$ace_root/test/mock/base/mock_jank_frame_report.cpp", "$ace_root/test/mock/base/mock_localization.cpp", - "$ace_root/test/mock/base/mock_long_frame_report.cpp", "$ace_root/test/mock/base/mock_mouse_style.cpp", "$ace_root/test/mock/base/mock_pixel_map.cpp", "$ace_root/test/mock/base/mock_socperf_client_impl.cpp", @@ -66,7 +65,6 @@ ace_unittest("pipeline_context_test_ng") { "$ace_root/test/mock/core/common/mock_image_analyzer_mgr.cpp", "$ace_root/test/mock/core/common/mock_interaction.cpp", "$ace_root/test/mock/core/common/mock_layout_inspector.cpp", - "$ace_root/test/mock/core/common/mock_raw_recognizer.cpp", "$ace_root/test/mock/core/common/mock_theme_constants.cpp", "$ace_root/test/mock/core/common/mock_udmf.cpp", "$ace_root/test/mock/core/common/mock_window.cpp", @@ -89,4 +87,8 @@ ace_unittest("pipeline_context_test_ng") { "$ace_root/test/unittest/core/pattern/text/mock/mock_text_layout_adapter.cpp", "pipeline_context_test_ng.cpp", ] + + if (defined(resourceschedule_ffrt_support) && resourceschedule_ffrt_support) { + sources += [ "$ace_root/test/mock/base/mock_long_frame_report.cpp" ] + } }