From 11701843415e142732c7a7e05804be0c9fb644e7 Mon Sep 17 00:00:00 2001 From: Artur Tynecki <77382963+ATmobica@users.noreply.github.com> Date: Tue, 4 Oct 2022 19:55:13 +0200 Subject: [PATCH] [Feature] Make dispatch event time threshold configurable (#22994) Add CHIP_DISPATCH_EVENT_LONG_DISPATCH_TIME_WARNING_THRESHOLD_MS variable to set the time threshold for events dispatching. Signed-off-by: ATmobica Signed-off-by: ATmobica --- src/include/platform/CHIPDeviceConfig.h | 10 ++++++++++ .../internal/GenericPlatformManagerImpl.ipp | 13 ++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index e960c681596905..99a2da1bd86d91 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -1369,3 +1369,13 @@ #ifndef CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT #define CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT 0 #endif + +/** + * CHIP_DISPATCH_EVENT_LONG_DISPATCH_TIME_WARNING_THRESHOLD_MS + * + * Time threshold for events dispatching + * Set 0 to disable event dispatching time measurement + */ +#ifndef CHIP_DISPATCH_EVENT_LONG_DISPATCH_TIME_WARNING_THRESHOLD_MS +#define CHIP_DISPATCH_EVENT_LONG_DISPATCH_TIME_WARNING_THRESHOLD_MS 100 +#endif diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.ipp b/src/include/platform/internal/GenericPlatformManagerImpl.ipp index 180d94964740ed..7a46248e0eb312 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.ipp +++ b/src/include/platform/internal/GenericPlatformManagerImpl.ipp @@ -193,7 +193,7 @@ void GenericPlatformManagerImpl::_RemoveEventHandler(PlatformManager: template void GenericPlatformManagerImpl::_HandleServerStarted() { - PlatformManagerDelegate * platformManagerDelegate = PlatformMgr().GetDelegate(); + PlatformManagerDelegate * platformManagerDelegate = PlatformMgr().GetDelegate(); if (platformManagerDelegate != nullptr) { @@ -233,9 +233,9 @@ void GenericPlatformManagerImpl::_ScheduleWork(AsyncWorkFunct workFun template void GenericPlatformManagerImpl::_DispatchEvent(const ChipDeviceEvent * event) { -#if CHIP_PROGRESS_LOGGING +#if (CHIP_DISPATCH_EVENT_LONG_DISPATCH_TIME_WARNING_THRESHOLD_MS != 0) System::Clock::Timestamp start = System::SystemClock().GetMonotonicTimestamp(); -#endif // CHIP_PROGRESS_LOGGING +#endif // CHIP_DISPATCH_EVENT_LONG_DISPATCH_TIME_WARNING_THRESHOLD_MS != 0 switch (event->Type) { @@ -266,14 +266,13 @@ void GenericPlatformManagerImpl::_DispatchEvent(const ChipDeviceEvent break; } - // TODO: make this configurable -#if CHIP_PROGRESS_LOGGING +#if (CHIP_DISPATCH_EVENT_LONG_DISPATCH_TIME_WARNING_THRESHOLD_MS != 0) uint32_t deltaMs = System::Clock::Milliseconds32(System::SystemClock().GetMonotonicTimestamp() - start).count(); - if (deltaMs > 100) + if (deltaMs > CHIP_DISPATCH_EVENT_LONG_DISPATCH_TIME_WARNING_THRESHOLD_MS) { ChipLogError(DeviceLayer, "Long dispatch time: %" PRIu32 " ms, for event type %d", deltaMs, event->Type); } -#endif // CHIP_PROGRESS_LOGGING +#endif // CHIP_DISPATCH_EVENT_LONG_DISPATCH_TIME_WARNING_THRESHOLD_MS != 0 } template