Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip SetCurrentHeapHighWatermark if GetCurrentHeapUsed is not impleme… #18130

Merged
merged 2 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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