Skip to content

Commit

Permalink
[Ameba] SoftwareDiagnostic update (#19147)
Browse files Browse the repository at this point in the history
* [DGSW] Implement GetThreadMetrics and ResetWaterMark

* [DGSW] Align ThreadMetrics struct with spec
  • Loading branch information
pankore authored and pull[bot] committed Oct 30, 2023
1 parent 1dc3243 commit 044fc7c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
65 changes: 64 additions & 1 deletion src/platform/Ameba/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <crypto/CHIPCryptoPAL.h>
#include <platform/Ameba/DiagnosticDataProviderImpl.h>
#include <platform/DiagnosticDataProvider.h>

#include <lwip_netconf.h>

Expand Down Expand Up @@ -56,6 +55,70 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapHighWatermark(uint64_t & cu
return CHIP_NO_ERROR;
}

CHIP_ERROR DiagnosticDataProviderImpl::ResetWatermarks()
{
// If implemented, the server SHALL set the value of the CurrentHeapHighWatermark attribute to the
// value of the CurrentHeapUsed.

xPortResetHeapMinimumEverFreeHeapSize();

return CHIP_NO_ERROR;
}

CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadMetricsOut)
{
/* Obtain all available task information */
TaskStatus_t * taskStatusArray;
ThreadMetrics * head = nullptr;
unsigned long arraySize, x, dummy;

arraySize = uxTaskGetNumberOfTasks();

taskStatusArray = (TaskStatus_t *) pvPortMalloc(arraySize * sizeof(TaskStatus_t));

if (taskStatusArray != NULL)
{
/* Generate raw status information about each task. */
arraySize = uxTaskGetSystemState(taskStatusArray, arraySize, &dummy);
/* For each populated position in the taskStatusArray array,
format the raw data as human readable ASCII data. */

for (x = 0; x < arraySize; x++)
{
ThreadMetrics * thread = (ThreadMetrics *) pvPortMalloc(sizeof(ThreadMetrics));

strncpy(thread->NameBuf, taskStatusArray[x].pcTaskName, kMaxThreadNameLength - 1);
thread->NameBuf[kMaxThreadNameLength] = '\0';
thread->name.Emplace(CharSpan::fromCharString(thread->NameBuf));
thread->id = taskStatusArray[x].xTaskNumber;

thread->stackFreeMinimum.Emplace(taskStatusArray[x].usStackHighWaterMark);
/* Unsupported metrics */
// thread->stackSize;
// thread->stackFreeCurrent;

thread->Next = head;
head = thread;
}

*threadMetricsOut = head;
/* The array is no longer needed, free the memory it consumes. */
vPortFree(taskStatusArray);
}

return CHIP_NO_ERROR;
}

void DiagnosticDataProviderImpl::ReleaseThreadMetrics(ThreadMetrics * threadMetrics)
{
while (threadMetrics)
{
ThreadMetrics * del = threadMetrics;
threadMetrics = threadMetrics->Next;
vPortFree(del);
}
}

CHIP_ERROR DiagnosticDataProviderImpl::GetRebootCount(uint16_t & rebootCount)
{
uint32_t count = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/platform/Ameba/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
CHIP_ERROR GetCurrentHeapFree(uint64_t & currentHeapFree) override;
CHIP_ERROR GetCurrentHeapUsed(uint64_t & currentHeapUsed) override;
CHIP_ERROR GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark) override;
CHIP_ERROR ResetWatermarks() override;
CHIP_ERROR GetThreadMetrics(ThreadMetrics ** threadMetricsOut) override;
void ReleaseThreadMetrics(ThreadMetrics * threadMetrics) override;

CHIP_ERROR GetRebootCount(uint16_t & rebootCount) override;
CHIP_ERROR GetUpTime(uint64_t & upTime) override;
Expand Down

0 comments on commit 044fc7c

Please sign in to comment.