From 982bd2aa70ed515595341c874e77a4d5d04fc0a0 Mon Sep 17 00:00:00 2001 From: YouZijun97 Date: Thu, 3 Jul 2025 14:10:21 +0000 Subject: [PATCH 1/4] send framereport Signed-off-by: YouZijun97 --- .../eventhandler/src/deamon_io_waiter.cpp | 17 +++++++++++++++++ frameworks/eventhandler/src/event_queue.cpp | 7 +++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/frameworks/eventhandler/src/deamon_io_waiter.cpp b/frameworks/eventhandler/src/deamon_io_waiter.cpp index 2ac5c9e..ac0822a 100644 --- a/frameworks/eventhandler/src/deamon_io_waiter.cpp +++ b/frameworks/eventhandler/src/deamon_io_waiter.cpp @@ -148,6 +148,18 @@ void DeamonIoWaiter::StopEpollIoWaiter() running_.store(false); } +static void PostTaskForVsync(const std::shared_ptr &handler) +{ + auto runner = handler->GetEventRunner(); + if (!runner) { + return; + } + + if (runner == EventRunner::GetMainEventRunner()) { + FrameReport::GetInstance().ReportSchedEvent(FrameSchedEvent::UI_EVENT_HANDLE_BEGIN, {}); + } +} + void DeamonIoWaiter::HandleFileDescriptorEvent(int32_t fileDescriptor, uint32_t events) __attribute__((no_sanitize("cfi"))) { @@ -159,6 +171,11 @@ void DeamonIoWaiter::HandleFileDescriptorEvent(int32_t fileDescriptor, uint32_t return; } + if (fileDescriptorInfo->taskName_ == "vSyncTask") { + PostTaskForVsync(handler); + return; + } + std::weak_ptr wp = fileDescriptorInfo->listener_; auto f = [fileDescriptor, events, wp]() { auto listener = wp.lock(); diff --git a/frameworks/eventhandler/src/event_queue.cpp b/frameworks/eventhandler/src/event_queue.cpp index 2c360ad..e6e2079 100644 --- a/frameworks/eventhandler/src/event_queue.cpp +++ b/frameworks/eventhandler/src/event_queue.cpp @@ -121,6 +121,9 @@ bool EventQueue::AddFileDescriptorByFd(int32_t fileDescriptor, uint32_t events, listener, priority); } if (ioWaiter_) { + if (taskName == "vSyncTask") { + DeamonIoWaiter::GetInstance().AddFileDescriptor(fileDescriptor, events, taskName, listener, priority); + } return ioWaiter_->AddFileDescriptor(fileDescriptor, events, taskName, listener, priority); } return false; @@ -207,7 +210,6 @@ static void PostTaskForVsync(const InnerEvent::Callback &cb, const std::string & handler->RemoveTask("BarrierEvent"); queue->SetBarrierMode(false); } - FrameReport::GetInstance().ReportSchedEvent(FrameSchedEvent::UI_EVENT_HANDLE_BEGIN, {}); } std::shared_ptr EventQueue::GetListenerByfd(int32_t fileDescriptor) @@ -278,9 +280,6 @@ void EventQueue::HandleFileDescriptorEvent(int32_t fileDescriptor, uint32_t even } else { handler->PostTask(f, taskName, 0, priority); } - if (taskName == "vSyncTask" && handler->GetEventRunner() == EventRunner::GetMainEventRunner()) { - FrameReport::GetInstance().ReportSchedEvent(FrameSchedEvent::UI_FLUSH_BEGIN, {}); - } } void EventQueue::RemoveListenerByOwner(const std::shared_ptr &owner) -- Gitee From 0a9a8feb13471b91162c21201cc589e1532b150f Mon Sep 17 00:00:00 2001 From: YouZijun97 Date: Fri, 4 Jul 2025 06:13:45 +0000 Subject: [PATCH 2/4] add vsyncTask 2 eventpoll Signed-off-by: YouZijun97 --- .../eventhandler/include/deamon_io_waiter.h | 1 + .../eventhandler/src/deamon_io_waiter.cpp | 4 +- frameworks/eventhandler/src/event_queue.cpp | 3 +- frameworks/eventhandler/test/BUILD.gn | 5 +++ .../lib_event_epoll_io_waiter_test.cpp | 41 +++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/frameworks/eventhandler/include/deamon_io_waiter.h b/frameworks/eventhandler/include/deamon_io_waiter.h index d52315d..3edae18 100644 --- a/frameworks/eventhandler/include/deamon_io_waiter.h +++ b/frameworks/eventhandler/include/deamon_io_waiter.h @@ -61,6 +61,7 @@ public: LOCAL_API void EraseFileDescriptorMap(int32_t fileDescriptor); LOCAL_API std::shared_ptr GetFileDescriptorMap(int32_t fileDescriptor); LOCAL_API void HandleFileDescriptorEvent(int32_t fileDescriptor, uint32_t events); + LOCAL_API void VsyncReport(const std::shared_ptr &handler); private: LOCAL_API void EpollWaitFor(); LOCAL_API void DrainAwakenPipe() const; diff --git a/frameworks/eventhandler/src/deamon_io_waiter.cpp b/frameworks/eventhandler/src/deamon_io_waiter.cpp index ac0822a..737111e 100644 --- a/frameworks/eventhandler/src/deamon_io_waiter.cpp +++ b/frameworks/eventhandler/src/deamon_io_waiter.cpp @@ -148,7 +148,7 @@ void DeamonIoWaiter::StopEpollIoWaiter() running_.store(false); } -static void PostTaskForVsync(const std::shared_ptr &handler) +void DeamonIoWaiter::VsyncReport(const std::shared_ptr &handler) { auto runner = handler->GetEventRunner(); if (!runner) { @@ -172,7 +172,7 @@ void DeamonIoWaiter::HandleFileDescriptorEvent(int32_t fileDescriptor, uint32_t } if (fileDescriptorInfo->taskName_ == "vSyncTask") { - PostTaskForVsync(handler); + VsyncReport(handler); return; } diff --git a/frameworks/eventhandler/src/event_queue.cpp b/frameworks/eventhandler/src/event_queue.cpp index e6e2079..2388946 100644 --- a/frameworks/eventhandler/src/event_queue.cpp +++ b/frameworks/eventhandler/src/event_queue.cpp @@ -121,7 +121,8 @@ bool EventQueue::AddFileDescriptorByFd(int32_t fileDescriptor, uint32_t events, listener, priority); } if (ioWaiter_) { - if (taskName == "vSyncTask") { + auto handler = listener->GetOwner(); + if (taskName == "vSyncTask" && handler->GetEventRunner() == EventRunner::GetMainEventRunner()) { DeamonIoWaiter::GetInstance().AddFileDescriptor(fileDescriptor, events, taskName, listener, priority); } return ioWaiter_->AddFileDescriptor(fileDescriptor, events, taskName, listener, priority); diff --git a/frameworks/eventhandler/test/BUILD.gn b/frameworks/eventhandler/test/BUILD.gn index 6be5974..6a50d65 100644 --- a/frameworks/eventhandler/test/BUILD.gn +++ b/frameworks/eventhandler/test/BUILD.gn @@ -38,6 +38,11 @@ ohos_unittest("LibEventHandlerEpollIoWaiterTest") { "init:libbegetutil", ] + cflags_cc = [ + "-DFFRT_USAGE_ENABLE", + "-Dprivate=public", + ] + cflags_cc = [ "-DFFRT_USAGE_ENABLE" ] if (has_hichecker_native_part) { external_deps += [ "hichecker:libhichecker" ] diff --git a/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp b/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp index 18429e7..c5ee57b 100644 --- a/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp +++ b/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp @@ -155,6 +155,34 @@ HWTEST_F(LibEventHandlerEpollIoWaiterTest, AddFileDescriptor003, TestSize.Level1 EXPECT_EQ(result, false); } +HWTEST_F(LibEventHandlerEpollIoWaiterTest, VsyncReport001, TestSize.Level1) +{ + /** + * @tc.steps: step1. get event with event id and param, then get event id and param from event. + * @tc.expected: step1. the event id and param is the same as we set. + */ + + DeamonIoWaiter::GetInstance().Init(); + auto runner1 = EventRunner::Create(false); + auto handler1 = std::make_shared(runner1); + DeamonIoWaiter::GetInstance().VsyncReport(handler1); + EXPECT_NE(handler1->GetEventRunner(), nullptr); + usleep(500); + + auto runner2 = EventRunner::Create(true); + auto handler2 = std::make_shared(runner2); + handler2->eventRunner_ = nullptr; + DeamonIoWaiter::GetInstance().VsyncReport(handler2); + EXPECT_EQ(handler2->GetEventRunner(), nullptr); + usleep(500); + + auto runner3 = EventRunner::Create(true); + auto handler3 = std::make_shared(runner3); + DeamonIoWaiter::GetInstance().VsyncReport(handler3); + EXPECT_NE(handler3->GetEventRunner(), nullptr); + usleep(500); +} + HWTEST_F(LibEventHandlerEpollIoWaiterTest, PostTaskForVsync001, TestSize.Level1) { /** @@ -185,6 +213,19 @@ HWTEST_F(LibEventHandlerEpollIoWaiterTest, PostTaskForVsync001, TestSize.Level1) FILE_DESCRIPTOR_SHUTDOWN_EVENT | FILE_DESCRIPTOR_EXCEPTION_EVENT; DeamonIoWaiter::GetInstance().HandleFileDescriptorEvent(fileDescriptor, events); usleep(500); + + int32_t fileDescriptor2 = 2; + uint32_t events2 = 2; + auto runner2 = EventRunner::Create(true); + auto handler2 = std::make_shared(runner2); + auto listener2 = std::make_shared(); + handler2->AddFileDescriptorListener(fileDescriptor2, events2, + listener2, "vSyncTask", EventQueue::Priority::VIP); + bool result2 = DeamonIoWaiter::GetInstance().AddFileDescriptor(fileDescriptor2, + events2, "vSyncTask", listener2, EventQueue::Priority::VIP); + EXPECT_EQ(result2, false); + DeamonIoWaiter::GetInstance().HandleFileDescriptorEvent(fileDescriptor2, events2); + usleep(500); } /* -- Gitee From d9121e0fcd403759872288a3e03c28ce48604fb7 Mon Sep 17 00:00:00 2001 From: YouZijun97 Date: Fri, 4 Jul 2025 07:27:03 +0000 Subject: [PATCH 3/4] add vsyncTask 2 eventpoll v2 Signed-off-by: YouZijun97 --- frameworks/eventhandler/src/event_queue.cpp | 3 ++ frameworks/eventhandler/test/BUILD.gn | 5 +--- .../lib_event_epoll_io_waiter_test.cpp | 28 ------------------- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/frameworks/eventhandler/src/event_queue.cpp b/frameworks/eventhandler/src/event_queue.cpp index 2388946..517eb22 100644 --- a/frameworks/eventhandler/src/event_queue.cpp +++ b/frameworks/eventhandler/src/event_queue.cpp @@ -281,6 +281,9 @@ void EventQueue::HandleFileDescriptorEvent(int32_t fileDescriptor, uint32_t even } else { handler->PostTask(f, taskName, 0, priority); } + if (taskName == "vSyncTask" && handler->GetEventRunner() == EventRunner::GetMainEventRunner()) { + FrameReport::GetInstance().ReportSchedEvent(FrameSchedEvent::UI_EVENT_HANDLE_BEGIN, {}); + } } void EventQueue::RemoveListenerByOwner(const std::shared_ptr &owner) diff --git a/frameworks/eventhandler/test/BUILD.gn b/frameworks/eventhandler/test/BUILD.gn index 6a50d65..7696c75 100644 --- a/frameworks/eventhandler/test/BUILD.gn +++ b/frameworks/eventhandler/test/BUILD.gn @@ -38,10 +38,7 @@ ohos_unittest("LibEventHandlerEpollIoWaiterTest") { "init:libbegetutil", ] - cflags_cc = [ - "-DFFRT_USAGE_ENABLE", - "-Dprivate=public", - ] + cflags_cc = [ "-DFFRT_USAGE_ENABLE" ] cflags_cc = [ "-DFFRT_USAGE_ENABLE" ] if (has_hichecker_native_part) { diff --git a/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp b/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp index c5ee57b..49641ca 100644 --- a/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp +++ b/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp @@ -155,34 +155,6 @@ HWTEST_F(LibEventHandlerEpollIoWaiterTest, AddFileDescriptor003, TestSize.Level1 EXPECT_EQ(result, false); } -HWTEST_F(LibEventHandlerEpollIoWaiterTest, VsyncReport001, TestSize.Level1) -{ - /** - * @tc.steps: step1. get event with event id and param, then get event id and param from event. - * @tc.expected: step1. the event id and param is the same as we set. - */ - - DeamonIoWaiter::GetInstance().Init(); - auto runner1 = EventRunner::Create(false); - auto handler1 = std::make_shared(runner1); - DeamonIoWaiter::GetInstance().VsyncReport(handler1); - EXPECT_NE(handler1->GetEventRunner(), nullptr); - usleep(500); - - auto runner2 = EventRunner::Create(true); - auto handler2 = std::make_shared(runner2); - handler2->eventRunner_ = nullptr; - DeamonIoWaiter::GetInstance().VsyncReport(handler2); - EXPECT_EQ(handler2->GetEventRunner(), nullptr); - usleep(500); - - auto runner3 = EventRunner::Create(true); - auto handler3 = std::make_shared(runner3); - DeamonIoWaiter::GetInstance().VsyncReport(handler3); - EXPECT_NE(handler3->GetEventRunner(), nullptr); - usleep(500); -} - HWTEST_F(LibEventHandlerEpollIoWaiterTest, PostTaskForVsync001, TestSize.Level1) { /** -- Gitee From ef80955f54875cb1f105ed237c16519afca39130 Mon Sep 17 00:00:00 2001 From: YouZijun97 Date: Fri, 4 Jul 2025 07:44:13 +0000 Subject: [PATCH 4/4] add vsyncTask 2 eventpoll v3 Signed-off-by: YouZijun97 --- frameworks/eventhandler/src/event_queue.cpp | 3 -- frameworks/eventhandler/test/BUILD.gn | 6 ++-- .../lib_event_epoll_io_waiter_test.cpp | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/frameworks/eventhandler/src/event_queue.cpp b/frameworks/eventhandler/src/event_queue.cpp index 517eb22..2388946 100644 --- a/frameworks/eventhandler/src/event_queue.cpp +++ b/frameworks/eventhandler/src/event_queue.cpp @@ -281,9 +281,6 @@ void EventQueue::HandleFileDescriptorEvent(int32_t fileDescriptor, uint32_t even } else { handler->PostTask(f, taskName, 0, priority); } - if (taskName == "vSyncTask" && handler->GetEventRunner() == EventRunner::GetMainEventRunner()) { - FrameReport::GetInstance().ReportSchedEvent(FrameSchedEvent::UI_EVENT_HANDLE_BEGIN, {}); - } } void EventQueue::RemoveListenerByOwner(const std::shared_ptr &owner) diff --git a/frameworks/eventhandler/test/BUILD.gn b/frameworks/eventhandler/test/BUILD.gn index 7696c75..38728eb 100644 --- a/frameworks/eventhandler/test/BUILD.gn +++ b/frameworks/eventhandler/test/BUILD.gn @@ -38,9 +38,11 @@ ohos_unittest("LibEventHandlerEpollIoWaiterTest") { "init:libbegetutil", ] - cflags_cc = [ "-DFFRT_USAGE_ENABLE" ] + cflags_cc = [ + "-DFFRT_USAGE_ENABLE", + "-Dprivate=public", + ] - cflags_cc = [ "-DFFRT_USAGE_ENABLE" ] if (has_hichecker_native_part) { external_deps += [ "hichecker:libhichecker" ] } diff --git a/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp b/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp index 49641ca..c5ee57b 100644 --- a/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp +++ b/frameworks/eventhandler/test/unittest/lib_event_epoll_io_waiter_test.cpp @@ -155,6 +155,34 @@ HWTEST_F(LibEventHandlerEpollIoWaiterTest, AddFileDescriptor003, TestSize.Level1 EXPECT_EQ(result, false); } +HWTEST_F(LibEventHandlerEpollIoWaiterTest, VsyncReport001, TestSize.Level1) +{ + /** + * @tc.steps: step1. get event with event id and param, then get event id and param from event. + * @tc.expected: step1. the event id and param is the same as we set. + */ + + DeamonIoWaiter::GetInstance().Init(); + auto runner1 = EventRunner::Create(false); + auto handler1 = std::make_shared(runner1); + DeamonIoWaiter::GetInstance().VsyncReport(handler1); + EXPECT_NE(handler1->GetEventRunner(), nullptr); + usleep(500); + + auto runner2 = EventRunner::Create(true); + auto handler2 = std::make_shared(runner2); + handler2->eventRunner_ = nullptr; + DeamonIoWaiter::GetInstance().VsyncReport(handler2); + EXPECT_EQ(handler2->GetEventRunner(), nullptr); + usleep(500); + + auto runner3 = EventRunner::Create(true); + auto handler3 = std::make_shared(runner3); + DeamonIoWaiter::GetInstance().VsyncReport(handler3); + EXPECT_NE(handler3->GetEventRunner(), nullptr); + usleep(500); +} + HWTEST_F(LibEventHandlerEpollIoWaiterTest, PostTaskForVsync001, TestSize.Level1) { /** -- Gitee