From 044fc7c950ed5339b85c8785ffc8ce1d6d1b6aa6 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Thu, 16 Jun 2022 21:25:16 +0800 Subject: [PATCH] [Ameba] SoftwareDiagnostic update (#19147) * [DGSW] Implement GetThreadMetrics and ResetWaterMark * [DGSW] Align ThreadMetrics struct with spec --- .../Ameba/DiagnosticDataProviderImpl.cpp | 65 ++++++++++++++++++- .../Ameba/DiagnosticDataProviderImpl.h | 3 + 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/platform/Ameba/DiagnosticDataProviderImpl.cpp b/src/platform/Ameba/DiagnosticDataProviderImpl.cpp index f1d99265ea5698..58f7a41cb326c9 100644 --- a/src/platform/Ameba/DiagnosticDataProviderImpl.cpp +++ b/src/platform/Ameba/DiagnosticDataProviderImpl.cpp @@ -25,7 +25,6 @@ #include #include -#include #include @@ -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; diff --git a/src/platform/Ameba/DiagnosticDataProviderImpl.h b/src/platform/Ameba/DiagnosticDataProviderImpl.h index c599b109645a7c..ae060e037c15b9 100644 --- a/src/platform/Ameba/DiagnosticDataProviderImpl.h +++ b/src/platform/Ameba/DiagnosticDataProviderImpl.h @@ -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;