From 549e5ff561faea5bfd6d1aeba7ca371fe76170ed Mon Sep 17 00:00:00 2001 From: xiahaiqin Date: Sat, 18 Jun 2022 16:28:39 +0800 Subject: [PATCH] add system event for window, event include: - WINDOW_LIFE_CYCLE_EXCEPTION - WINDOW_BOOT_ANIMATION_DONE Signed-off-by: xiahaiqin Change-Id: I0268e77ce474262b1879d41af61957aa26ff5933 --- hisysevent.yaml | 10 +++++ utils/include/wm_common_inner.h | 7 ++++ wm/BUILD.gn | 2 +- wm/include/window_impl.h | 2 + wm/src/window_impl.cpp | 55 ++++++++++++++++++++++++++++ wmserver/include/window_controller.h | 1 + wmserver/src/window_controller.cpp | 23 +++++++++++- 7 files changed, 98 insertions(+), 2 deletions(-) diff --git a/hisysevent.yaml b/hisysevent.yaml index 147fbfde..6a8fe294 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -45,4 +45,14 @@ NO_FOCUS_WINDOW: UID: {type: INT32, desc: session uid} PACKAGE_NAME: {type: STRING, desc: package name} PROCESS_NAME: {type: STRING, desc: process name} + MSG: {type: STRING, desc: windowmanager event message} + +WINDOW_LIFE_CYCLE_EXCEPTION: + __BASE: {type: FAULT, level: CRITICAL, desc: The window life cycle is abnormal } + PID: {type: INT32, desc: session pid} + UID: {type: INT32, desc: session uid} + MSG: {type: STRING, desc: windowmanager event message} + +WINDOW_BOOT_ANIMATION_DONE: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: Boot animation done } MSG: {type: STRING, desc: windowmanager event message} \ No newline at end of file diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index ab6b15ad..0e181d19 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -21,6 +21,13 @@ namespace OHOS { namespace Rosen { +enum class LifeCycleEvent : uint32_t { + CREATE_EVENT, + SHOW_EVENT, + HIDE_EVENT, + DESTROY_EVENT, +}; + enum class WindowState : uint32_t { STATE_INITIAL, STATE_CREATED, diff --git a/wm/BUILD.gn b/wm/BUILD.gn index eb74ce04..e57dcb7f 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -79,7 +79,7 @@ ohos_shared_library("libwm") { "graphic_standard:surface", "graphic_standard:window_animation", "hilog_native:libhilog", - "hitrace_native:hitrace_meter", + "hisysevent_native:libhisysevent", "input:libmmi-client", "inputmethod_native:inputmethod_client", "ipc:ipc_core", diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 68628e15..eb5bd26d 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -273,6 +273,8 @@ private: WMError Destroy(bool needNotifyServer); WMError SetBackgroundColor(uint32_t color); uint32_t GetBackgroundColor() const; + void RecordLifeCycleExceptionEvent(LifeCycleEvent event, WMError errCode) const; + std::string TransferLifeCycleEventToString(LifeCycleEvent type) const; Rect GetSystemAlarmWindowDefaultSize(Rect defaultRect); void HandleModeChangeHotZones(int32_t posX, int32_t posY); WMError NotifyWindowTransition(TransitionReason reason); diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 16b6e1a2..44ac2248 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -18,6 +18,8 @@ #include #include +#include +#include #include "color_parser.h" #include "display_manager.h" @@ -709,6 +711,7 @@ WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr< } WMError ret = SingletonContainer::Get().CreateWindow(windowAgent, property_, surfaceNode_, windowId, token); + RecordLifeCycleExceptionEvent(LifeCycleEvent::CREATE_EVENT, ret); if (ret != WMError::WM_OK) { WLOGFE("create window failed with errCode:%{public}d", static_cast(ret)); return ret; @@ -803,6 +806,7 @@ WMError WindowImpl::Destroy(bool needNotifyServer) } } ret = SingletonContainer::Get().DestroyWindow(property_->GetWindowId()); + RecordLifeCycleExceptionEvent(LifeCycleEvent::DESTROY_EVENT, ret); if (ret != WMError::WM_OK) { WLOGFE("destroy window failed with errCode:%{public}d", static_cast(ret)); return ret; @@ -863,6 +867,7 @@ WMError WindowImpl::Show(uint32_t reason) } SetDefaultOption(); WMError ret = SingletonContainer::Get().AddWindow(property_); + RecordLifeCycleExceptionEvent(LifeCycleEvent::SHOW_EVENT, ret); if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) { state_ = WindowState::STATE_SHOWN; NotifyAfterForeground(); @@ -890,6 +895,7 @@ WMError WindowImpl::Hide(uint32_t reason) return WMError::WM_OK; } WMError ret = SingletonContainer::Get().RemoveWindow(property_->GetWindowId()); + RecordLifeCycleExceptionEvent(LifeCycleEvent::HIDE_EVENT, ret); if (ret != WMError::WM_OK) { WLOGFE("hide errCode:%{public}d for winId:%{public}u", static_cast(ret), property_->GetWindowId()); return ret; @@ -1077,6 +1083,55 @@ WMError WindowImpl::SetCallingWindow(uint32_t windowId) return UpdateProperty(PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW); } +void WindowImpl::RecordLifeCycleExceptionEvent(LifeCycleEvent event, WMError errCode) const +{ + if (!(errCode == WMError::WM_ERROR_NULLPTR || errCode == WMError::WM_ERROR_INVALID_TYPE || + errCode == WMError::WM_ERROR_INVALID_PARAM || errCode == WMError::WM_ERROR_SAMGR || + errCode == WMError::WM_ERROR_IPC_FAILED)) { + WLOGFI("do not record, %{public}u", static_cast(errCode)); + return; + } + std::ostringstream oss; + oss << "life cycle is abnormal: " << "window_name: " << name_ + << ", id:" << GetWindowId() << ", event: " << TransferLifeCycleEventToString(event) + << ", errCode: " << static_cast(errCode) << ";"; + std::string info = oss.str(); + WLOGFI("window life cycle exception: %{public}s", info.c_str()); + int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER, + "WINDOW_LIFE_CYCLE_EXCEPTION", + OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, + "PID", getpid(), + "UID", getuid(), + "MSG", info); + if (ret != 0) { + WLOGFE("Write HiSysEvent error, ret:%{public}d", ret); + } +} + +std::string WindowImpl::TransferLifeCycleEventToString(LifeCycleEvent type) const +{ + std::string event; + switch (type) { + case LifeCycleEvent::CREATE_EVENT: + event = "CREATE"; + break; + case LifeCycleEvent::SHOW_EVENT: + event = "SHOW"; + break; + case LifeCycleEvent::HIDE_EVENT: + event = "HIDE"; + break; + case LifeCycleEvent::DESTROY_EVENT: + event = "DESTROY"; + break; + default: + event = "UNDEFINE"; + break; + } + return event; +} + void WindowImpl::SetPrivacyMode(bool isPrivacyMode) { property_->SetPrivacyMode(isPrivacyMode); diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 615c1db7..41a465f9 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -71,6 +71,7 @@ private: void ProcessDisplayChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type); void StopBootAnimationIfNeed(WindowType type) const; + void RecordBootAnimationEvent() const; WMError SetWindowType(uint32_t windowId, WindowType type); WMError SetWindowFlags(uint32_t windowId, uint32_t flags); WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index bb962140..85101999 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -15,10 +15,13 @@ #include "window_controller.h" #include +#include +#include #include #include #include #include +#include #include "minimize_app.h" #include "remote_animation.h" @@ -512,8 +515,26 @@ void WindowController::ProcessDisplayChange(DisplayId defaultDisplayId, sptr(std::chrono::steady_clock::now()). + time_since_epoch().count(); + WLOGFI("boot animation done duration(s): %{public}" PRIu64"", static_cast(time)); + std::ostringstream os; + os << "boot animation done duration(s): " << time <<";"; + int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER, + "WINDOW_BOOT_ANIMATION_DONE", + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "MSG", os.str()); + if (ret != 0) { + WLOGFE("Write HiSysEvent error, ret:%{public}d", ret); } }