Skip to content

Commit

Permalink
[Feature] Make dispatch event time threshold configurable (#22994)
Browse files Browse the repository at this point in the history
Add CHIP_DISPATCH_EVENT_LONG_DISPATCH_TIME_WARNING_THRESHOLD_MS
variable to set the time threshold for events dispatching.

Signed-off-by: ATmobica <[email protected]>

Signed-off-by: ATmobica <[email protected]>
  • Loading branch information
ATmobica authored and pull[bot] committed Jul 24, 2023
1 parent 657cb62 commit 1170184
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/include/platform/CHIPDeviceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 6 additions & 7 deletions src/include/platform/internal/GenericPlatformManagerImpl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void GenericPlatformManagerImpl<ImplClass>::_RemoveEventHandler(PlatformManager:
template <class ImplClass>
void GenericPlatformManagerImpl<ImplClass>::_HandleServerStarted()
{
PlatformManagerDelegate * platformManagerDelegate = PlatformMgr().GetDelegate();
PlatformManagerDelegate * platformManagerDelegate = PlatformMgr().GetDelegate();

if (platformManagerDelegate != nullptr)
{
Expand Down Expand Up @@ -233,9 +233,9 @@ void GenericPlatformManagerImpl<ImplClass>::_ScheduleWork(AsyncWorkFunct workFun
template <class ImplClass>
void GenericPlatformManagerImpl<ImplClass>::_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)
{
Expand Down Expand Up @@ -266,14 +266,13 @@ void GenericPlatformManagerImpl<ImplClass>::_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 <class ImplClass>
Expand Down

0 comments on commit 1170184

Please sign in to comment.