Skip to content

Commit

Permalink
Skip SetCurrentHeapHighWatermark if GetCurrentHeapUsed is not impleme… (
Browse files Browse the repository at this point in the history
#18130)

* Skip SetCurrentHeapHighWatermark if GetCurrentHeapUsed is not implemented

* Address review comment
  • Loading branch information
yufengwangca authored and pull[bot] committed Oct 12, 2023
1 parent 93d4d4a commit 4c691ee
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,13 @@ bool emberAfSoftwareDiagnosticsClusterResetWatermarksCallback(app::CommandHandle
{
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;

uint64_t currentHeapUsed;
CHIP_ERROR err = DeviceLayer::GetDiagnosticDataProvider().GetCurrentHeapUsed(currentHeapUsed);
VerifyOrExit(err == CHIP_NO_ERROR, status = EMBER_ZCL_STATUS_FAILURE);

err = DeviceLayer::GetDiagnosticDataProvider().SetCurrentHeapHighWatermark(currentHeapUsed);
VerifyOrExit(err == CHIP_NO_ERROR, status = EMBER_ZCL_STATUS_FAILURE);
// If implemented, the server SHALL set the value of the CurrentHeapHighWatermark attribute to the
// value of the CurrentHeapUsed.
if (DeviceLayer::GetDiagnosticDataProvider().ResetWatermarks() != CHIP_NO_ERROR)
{
status = EMBER_ZCL_STATUS_FAILURE;
}

exit:
emberAfSendImmediateDefaultResponse(status);

return true;
Expand Down
6 changes: 6 additions & 0 deletions src/include/platform/DiagnosticDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class DiagnosticDataProvider
virtual CHIP_ERROR GetCurrentHeapUsed(uint64_t & currentHeapUsed);
virtual CHIP_ERROR GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark);
virtual CHIP_ERROR SetCurrentHeapHighWatermark(uint64_t heapHighWatermark);
virtual CHIP_ERROR ResetWatermarks();

/*
* Get the linked list of thread metrics of the current plaform. After usage, each caller of GetThreadMetrics
Expand Down Expand Up @@ -272,6 +273,11 @@ inline CHIP_ERROR DiagnosticDataProvider::SetCurrentHeapHighWatermark(uint64_t h
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

inline CHIP_ERROR DiagnosticDataProvider::ResetWatermarks()
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

inline CHIP_ERROR DiagnosticDataProvider::GetThreadMetrics(ThreadMetrics ** threadMetricsOut)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
Expand Down
26 changes: 4 additions & 22 deletions src/platform/Darwin/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,12 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetTotalOperationalHours(uint32_t & total
return CHIP_ERROR_INVALID_TIME;
}

CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapFree(uint64_t & currentHeapFree)
CHIP_ERROR DiagnosticDataProviderImpl::ResetWatermarks()
{
// Overide with dummy value to pass CI
currentHeapFree = 0;
return CHIP_NO_ERROR;
}

CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapUsed(uint64_t & currentHeapUsed)
{
// Overide with dummy value to pass CI
currentHeapUsed = 0;
return CHIP_NO_ERROR;
}
// If implemented, the server SHALL set the value of the CurrentHeapHighWatermark attribute to the
// value of the CurrentHeapUsed.
// On Darwin, overide with non-op to pass CI.

CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark)
{
// Overide with dummy value to pass CI
currentHeapHighWatermark = 0;
return CHIP_NO_ERROR;
}

CHIP_ERROR DiagnosticDataProviderImpl::SetCurrentHeapHighWatermark(uint64_t heapHighWatermark)
{
// Overide to pass CI
return CHIP_NO_ERROR;
}

Expand Down
5 changes: 1 addition & 4 deletions src/platform/Darwin/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override;

// ===== Methods that implement the DiagnosticDataProvider abstract interface.
CHIP_ERROR GetCurrentHeapFree(uint64_t & currentHeapFree) override;
CHIP_ERROR GetCurrentHeapUsed(uint64_t & currentHeapUsed) override;
CHIP_ERROR GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark) override;
CHIP_ERROR SetCurrentHeapHighWatermark(uint64_t heapHighWatermark) override;
CHIP_ERROR ResetWatermarks() override;
};

} // namespace DeviceLayer
Expand Down
11 changes: 11 additions & 0 deletions src/platform/Linux/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ CHIP_ERROR DiagnosticDataProviderImpl::SetCurrentHeapHighWatermark(uint64_t heap
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.

// On Linux, the write operation is non-op since we always rely on the mallinfo system
// function to get the current heap memory.

return CHIP_NO_ERROR;
}

CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadMetricsOut)
{
CHIP_ERROR err = CHIP_ERROR_READ_FAILED;
Expand Down
1 change: 1 addition & 0 deletions src/platform/Linux/DiagnosticDataProviderImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
CHIP_ERROR GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark) override;
CHIP_ERROR GetThreadMetrics(ThreadMetrics ** threadMetricsOut) override;
CHIP_ERROR SetCurrentHeapHighWatermark(uint64_t heapHighWatermark) override;
CHIP_ERROR ResetWatermarks() override;
void ReleaseThreadMetrics(ThreadMetrics * threadMetrics) override;

CHIP_ERROR GetRebootCount(uint16_t & rebootCount) override;
Expand Down

0 comments on commit 4c691ee

Please sign in to comment.