diff --git a/hisysevent.yaml b/hisysevent.yaml index b55daa79c4..def0e0e251 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -40,7 +40,7 @@ domain: WINDOWMANAGER NO_FOCUS_WINDOW: - __BASE: {type: FAULT, level: CRITICAL, desc: The event is not consumed } + __BASE: {type: FAULT, level: CRITICAL, desc: The event is not consumed} PID: {type: INT32, desc: session pid} UID: {type: INT32, desc: session uid} PACKAGE_NAME: {type: STRING, desc: package name} @@ -48,11 +48,19 @@ NO_FOCUS_WINDOW: MSG: {type: STRING, desc: windowmanager event message} WINDOW_LIFE_CYCLE_EXCEPTION: - __BASE: {type: FAULT, level: CRITICAL, desc: The window life cycle is abnormal } + __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 + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: Boot animation done} + MSG: {type: STRING, desc: windowmanager event message} + +SHOW_WINDOW_TIME: + __BASE: {type: STATISTIC, level: MINOR, desc: Sow window time performance} + MSG: {type: STRING, desc: windowmanager event message} + +GET_SNAPSHOT_TIME: + __BASE: {type: STATISTIC, level: MINOR, desc: Get snapshot time performance} + MSG: {type: STRING, desc: windowmanager event message} diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index 31da48b5f0..a9fad635ea 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -80,6 +80,23 @@ enum class PropertyChangeAction : uint32_t { ACTION_UPDATE_PRIVACY_MODE = 1 << 15, }; +struct ShowWindowTimeConfig { + std::atomic showWindowTimes_; + std::atomic below20msTimes_; + std::atomic below35msTimes_; + std::atomic below50msTimes_; + std::atomic above50msTimes_; +}; + +struct GetSnapshotTimeConfig { + std::atomic getSnapshotTimes_; + std::atomic below25msTimes_; + std::atomic below35msTimes_; + std::atomic below50msTimes_; + std::atomic below200msTimes_; + std::atomic above200msTimes_; +}; + struct ModeChangeHotZonesConfig { bool isModeChangeHotZoneConfigured_; uint32_t fullscreenRange_; diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index e1c5520f90..4686465b5b 100755 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -549,12 +549,12 @@ ColorSpace WindowImpl::GetColorSpace() std::shared_ptr WindowImpl::Snapshot() { - WLOGFI("WMS-Clinet Snapshot"); + WLOGFI("WMS-Client Snapshot"); std::shared_ptr callback = std::make_shared(); RSInterfaces::GetInstance().TakeSurfaceCapture(surfaceNode_, callback); std::shared_ptr pixelMap = callback->GetResult(2000); // wait for <= 2000ms if (pixelMap != nullptr) { - WLOGFI("WMS-Clinet Save WxH = %{public}dx%{public}d", pixelMap->GetWidth(), pixelMap->GetHeight()); + WLOGFI("WMS-Client Save WxH = %{public}dx%{public}d", pixelMap->GetWidth(), pixelMap->GetHeight()); } else { WLOGFE("Failed to get pixelmap, return nullptr!"); } diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index c39e0ac3fe..31a3b1d3a3 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -30,6 +30,7 @@ #include "drag_controller.h" #include "freeze_controller.h" #include "singleton_delegator.h" +#include "wm_common_inner.h" #include "wm_single_instance.h" #include "window_common_event.h" #include "window_controller.h" @@ -153,6 +154,7 @@ private: void ConfigWindowAnimation(const std::map& animeMap); void ConfigKeyboardAnimation(const std::map& animeMap); RSAnimationTimingCurve CreateCurve(const std::map& timingMap); + void RecordShowTimeEvent(int64_t costTime); static inline SingletonDelegator delegator; AtomicMap accessTokenIdMaps_; @@ -172,6 +174,7 @@ private: RSInterfaces& rsInterface_; bool startingOpen_ = true; std::shared_ptr rsUiDirector_; + ShowWindowTimeConfig showWindowTimeConfig_ = { 0, 0, 0, 0, 0 }; }; } // namespace Rosen } // namespace OHOS diff --git a/wmserver/include/window_snapshot/snapshot_controller.h b/wmserver/include/window_snapshot/snapshot_controller.h index 3632538b47..2233f9fbf5 100644 --- a/wmserver/include/window_snapshot/snapshot_controller.h +++ b/wmserver/include/window_snapshot/snapshot_controller.h @@ -22,6 +22,7 @@ #include "event_handler.h" #include "future.h" #include "snapshot_stub.h" +#include "wm_common_inner.h" #include "window_root.h" #include "window_manager_hilog.h" @@ -38,6 +39,7 @@ public: private: WMError TakeSnapshot(const std::shared_ptr& surfaceNode, AAFwk::Snapshot& snapshot); + void RecordGetSnapshotEvent(int64_t costTime); private: float scaleW = 0.5f; // width scaling ratio(0.5) @@ -45,6 +47,7 @@ private: sptr windowRoot_; std::shared_ptr handler_; RSInterfaces& rsInterface_; + GetSnapshotTimeConfig getSnapshotTimeConfig_ = { 0, 0, 0, 0, 0, 0 }; }; } // Rosen } // OHOS diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 8add0aa6cb..ceecfbadf7 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -576,7 +576,7 @@ void WindowController::RecordBootAnimationEvent() const { uint64_t time = std::chrono::time_point_cast(std::chrono::steady_clock::now()). time_since_epoch().count(); - WLOGFI("boot animation done duration(s): %{public}" PRIu64"", static_cast(time)); + WLOGFI("boot animation done duration(s): %{public}" PRIu64"", time); std::ostringstream os; os << "boot animation done duration(s): " << time <<";"; int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 8c5648b2f6..9510ef5654 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -19,11 +19,14 @@ #include #include +#include +#include #include #include #include #include #include +#include #include "xcollie/watchdog.h" #include "display_manager_service_inner.h" @@ -44,6 +47,7 @@ namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManagerService"}; + constexpr int REPORT_SHOW_WINDOW_TIMES = 50; } WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerService) @@ -543,6 +547,7 @@ WMError WindowManagerService::CreateWindow(sptr& window, sptr& property) { return PostSyncTask([this, &property]() { + auto startTime = std::chrono::steady_clock::now(); if (property == nullptr) { WLOGFE("property is nullptr"); return WMError::WM_ERROR_NULLPTR; @@ -557,6 +562,12 @@ WMError WindowManagerService::AddWindow(sptr& property) if (property->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { dragController_->StartDrag(windowId); } + if (res == WMError::WM_OK) { + showWindowTimeConfig_.showWindowTimes_++; + auto currentTime = std::chrono::steady_clock::now(); + int64_t costTime = std::chrono::duration_cast(currentTime - startTime).count(); + RecordShowTimeEvent(costTime); + } return res; }); } @@ -893,5 +904,41 @@ void WindowInfoQueriedListener::HasPrivateWindow(DisplayId displayId, bool& hasP WLOGFI("called"); WindowManagerService::GetInstance().HasPrivateWindow(displayId, hasPrivateWindow); } + +void WindowManagerService::RecordShowTimeEvent(int64_t costTime) +{ + WLOGFI("show window cost time(ms): %{public}" PRIu64", show window times: %{public}u", costTime, + showWindowTimeConfig_.showWindowTimes_.load()); + if (costTime <= 20) { // 20: means cost time is 20ms + showWindowTimeConfig_.below20msTimes_++; + } else if (costTime <= 35) { // 35: means cost time is 35ms + showWindowTimeConfig_.below35msTimes_++; + } else if (costTime <= 50) { // 50: means cost time is 50ms + showWindowTimeConfig_.below50msTimes_++; + } else { + showWindowTimeConfig_.above50msTimes_++; + } + if (showWindowTimeConfig_.showWindowTimes_ >= REPORT_SHOW_WINDOW_TIMES) { + std::ostringstream oss; + oss << "show window: " << "BELOW20(ms): " << showWindowTimeConfig_.below20msTimes_ + << ", BELOW35(ms):" << showWindowTimeConfig_.below35msTimes_ + << ", BELOW50(ms): " << showWindowTimeConfig_.below50msTimes_ + << ", ABOVE50(ms): " << showWindowTimeConfig_.above50msTimes_ << ";"; + int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER, + "SHOW_WINDOW_TIME", + OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, + "MSG", oss.str()); + if (ret != 0) { + WLOGFE("Write HiSysEvent error, ret:%{public}d", ret); + } else { + showWindowTimeConfig_.showWindowTimes_ = 0; + showWindowTimeConfig_.below20msTimes_ = 0; + showWindowTimeConfig_.below35msTimes_ = 0; + showWindowTimeConfig_.below50msTimes_ = 0; + showWindowTimeConfig_.above50msTimes_ = 0; + } + } +} } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/window_snapshot/snapshot_controller.cpp b/wmserver/src/window_snapshot/snapshot_controller.cpp index 3851ebd0df..b8e54f265b 100644 --- a/wmserver/src/window_snapshot/snapshot_controller.cpp +++ b/wmserver/src/window_snapshot/snapshot_controller.cpp @@ -15,7 +15,10 @@ #include "snapshot_controller.h" +#include +#include #include +#include #include "surface_capture_future.h" #include "window_manager_hilog.h" @@ -25,6 +28,7 @@ namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SnapshotController"}; + constexpr int REPORT_SHOW_WINDOW_TIMES = 50; } void SnapshotController::Init(sptr& root) @@ -48,6 +52,7 @@ WMError SnapshotController::TakeSnapshot(const std::shared_ptr& s int32_t SnapshotController::GetSnapshot(const sptr &token, Snapshot& snapshot) { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "wms:GetSnapshot"); + auto startTime = std::chrono::steady_clock::now(); if (token == nullptr) { WLOGFE("Get snapshot failed, because token is null."); return static_cast(WMError::WM_ERROR_NULLPTR); @@ -71,7 +76,54 @@ int32_t SnapshotController::GetSnapshot(const sptr &token, Snapsh WLOGFE("Get surfaceNode failed, because surfaceNode is null"); return static_cast(WMError::WM_ERROR_NULLPTR); } - return static_cast(TakeSnapshot(surfaceNode, snapshot)); + WMError res = TakeSnapshot(surfaceNode, snapshot); + if (res == WMError::WM_OK) { + getSnapshotTimeConfig_.getSnapshotTimes_++; + auto currentTime = std::chrono::steady_clock::now(); + int64_t costTime = std::chrono::duration_cast(currentTime - startTime).count(); + RecordGetSnapshotEvent(costTime); + } + return static_cast(res); +} + +void SnapshotController::RecordGetSnapshotEvent(int64_t costTime) +{ + WLOGFI("get snapshot cost time(ms): %{public}" PRIu64", get snapshot times: %{public}u", costTime, + getSnapshotTimeConfig_.getSnapshotTimes_.load()); + if (costTime <= 25) { // 20: means cost time is 25ms + getSnapshotTimeConfig_.below25msTimes_++; + } else if (costTime <= 35) { // 35: means cost time is 35ms + getSnapshotTimeConfig_.below35msTimes_++; + } else if (costTime <= 50) { // 50: means cost time is 50ms + getSnapshotTimeConfig_.below50msTimes_++; + } else if (costTime <= 200) { // 200: means cost time is 200ms + getSnapshotTimeConfig_.below200msTimes_++; + } else { + getSnapshotTimeConfig_.above200msTimes_++; + } + if (getSnapshotTimeConfig_.getSnapshotTimes_ >= REPORT_SHOW_WINDOW_TIMES) { + std::ostringstream oss; + oss << "show window: " << "BELOW25(ms): " << getSnapshotTimeConfig_.below25msTimes_ + << ", BELOW35(ms):" << getSnapshotTimeConfig_.below35msTimes_ + << ", BELOW50(ms): " << getSnapshotTimeConfig_.below50msTimes_ + << ", BELOW200(ms): " << getSnapshotTimeConfig_.below200msTimes_ + << ", ABOVE50(ms): " << getSnapshotTimeConfig_.above200msTimes_ << ";"; + int32_t ret = OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::WINDOW_MANAGER, + "GET_SNAPSHOT_TIME", + OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, + "MSG", oss.str()); + if (ret != 0) { + WLOGFE("Write HiSysEvent error, ret:%{public}d", ret); + } else { + getSnapshotTimeConfig_.getSnapshotTimes_ = 0; + getSnapshotTimeConfig_.below25msTimes_ = 0; + getSnapshotTimeConfig_.below35msTimes_ = 0; + getSnapshotTimeConfig_.below50msTimes_ = 0; + getSnapshotTimeConfig_.below200msTimes_ = 0; + getSnapshotTimeConfig_.above200msTimes_ = 0; + } + } } } // namespace Rosen } // namespace OHOS \ No newline at end of file