Skip to content

Commit

Permalink
[Zephyr] Fix ThreadMetrics diagnostic cluster implementation (project…
Browse files Browse the repository at this point in the history
…-chip#36765)

Addressing review comments from project-chip#36749

Signed-off-by: Axel Le Bourhis <[email protected]>
  • Loading branch information
axelnxp authored Dec 9, 2024
1 parent a30f346 commit 72dbbcf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
4 changes: 0 additions & 4 deletions src/include/platform/DiagnosticDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ namespace DeviceLayer {

// Maximum length of vendor defined name or prefix of the software thread that is
// static for the duration of the thread.
#if defined(CONFIG_THREAD_MAX_NAME_LEN)
static constexpr size_t kMaxThreadNameLength = CONFIG_THREAD_MAX_NAME_LEN - 1;
#else
static constexpr size_t kMaxThreadNameLength = 8;
#endif
// 48-bit IEEE MAC Address or a 64-bit IEEE MAC Address (e.g. EUI-64).
inline constexpr size_t kMaxHardwareAddrSize = 8;

Expand Down
21 changes: 10 additions & 11 deletions src/platform/Zephyr/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ namespace {
static void GetThreadInfo(const struct k_thread * thread, void * user_data)
{
size_t unusedStackSize;
ThreadMetrics ** threadMetricsListHead = (ThreadMetrics **) user_data;
ThreadMetrics * threadMetrics = (ThreadMetrics *) malloc(sizeof(ThreadMetrics));
ThreadMetrics ** threadMetricsListHead = static_cast<ThreadMetrics **>(user_data);
ThreadMetrics * threadMetrics = Platform::New<ThreadMetrics>();

VerifyOrReturn(threadMetrics != NULL, ChipLogError(DeviceLayer, "Failed to allocate ThreadMetrics"));

#if defined(CONFIG_THREAD_NAME)
Platform::CopyString(threadMetrics->NameBuf, k_thread_name_get((k_tid_t) thread));
threadMetrics->name.Emplace(CharSpan::fromCharString(threadMetrics->NameBuf));
#endif

threadMetrics->id = (uint64_t) thread;
threadMetrics->stackFreeCurrent.ClearValue(); // unsupported metric
threadMetrics->stackFreeMinimum.ClearValue();
Expand All @@ -81,14 +86,7 @@ static void GetThreadInfo(const struct k_thread * thread, void * user_data)
(void) unusedStackSize;
#endif

if (*threadMetricsListHead)
{
threadMetrics->Next = *threadMetricsListHead;
}
else
{
threadMetrics->Next = NULL;
}
threadMetrics->Next = *threadMetricsListHead;
*threadMetricsListHead = threadMetrics;
}

Expand Down Expand Up @@ -224,6 +222,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::ResetWatermarks()
CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadMetricsOut)
{
#if defined(CONFIG_THREAD_MONITOR)
*threadMetricsOut = NULL;
k_thread_foreach((k_thread_user_cb_t) GetThreadInfo, threadMetricsOut);
return CHIP_NO_ERROR;
#else
Expand All @@ -237,7 +236,7 @@ void DiagnosticDataProviderImpl::ReleaseThreadMetrics(ThreadMetrics * threadMetr
{
ThreadMetrics * thread = threadMetrics;
threadMetrics = threadMetrics->Next;
free(thread);
Platform::Delete<ThreadMetrics>(thread);
}
}

Expand Down

0 comments on commit 72dbbcf

Please sign in to comment.