Skip to content

Commit 395375d

Browse files
authored
Skip SetCurrentHeapHighWatermark if GetCurrentHeapUsed is not impleme… (#18130)
* Skip SetCurrentHeapHighWatermark if GetCurrentHeapUsed is not implemented * Address review comment
1 parent 831211b commit 395375d

File tree

6 files changed

+29
-33
lines changed

6 files changed

+29
-33
lines changed

src/app/clusters/software-diagnostics-server/software-diagnostics-server.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,13 @@ bool emberAfSoftwareDiagnosticsClusterResetWatermarksCallback(app::CommandHandle
156156
{
157157
EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
158158

159-
uint64_t currentHeapUsed;
160-
CHIP_ERROR err = DeviceLayer::GetDiagnosticDataProvider().GetCurrentHeapUsed(currentHeapUsed);
161-
VerifyOrExit(err == CHIP_NO_ERROR, status = EMBER_ZCL_STATUS_FAILURE);
162-
163-
err = DeviceLayer::GetDiagnosticDataProvider().SetCurrentHeapHighWatermark(currentHeapUsed);
164-
VerifyOrExit(err == CHIP_NO_ERROR, status = EMBER_ZCL_STATUS_FAILURE);
159+
// If implemented, the server SHALL set the value of the CurrentHeapHighWatermark attribute to the
160+
// value of the CurrentHeapUsed.
161+
if (DeviceLayer::GetDiagnosticDataProvider().ResetWatermarks() != CHIP_NO_ERROR)
162+
{
163+
status = EMBER_ZCL_STATUS_FAILURE;
164+
}
165165

166-
exit:
167166
emberAfSendImmediateDefaultResponse(status);
168167

169168
return true;

src/include/platform/DiagnosticDataProvider.h

+6
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class DiagnosticDataProvider
180180
virtual CHIP_ERROR GetCurrentHeapUsed(uint64_t & currentHeapUsed);
181181
virtual CHIP_ERROR GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark);
182182
virtual CHIP_ERROR SetCurrentHeapHighWatermark(uint64_t heapHighWatermark);
183+
virtual CHIP_ERROR ResetWatermarks();
183184

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

276+
inline CHIP_ERROR DiagnosticDataProvider::ResetWatermarks()
277+
{
278+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
279+
}
280+
275281
inline CHIP_ERROR DiagnosticDataProvider::GetThreadMetrics(ThreadMetrics ** threadMetricsOut)
276282
{
277283
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;

src/platform/Darwin/DiagnosticDataProviderImpl.cpp

+4-22
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,12 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetTotalOperationalHours(uint32_t & total
6868
return CHIP_ERROR_INVALID_TIME;
6969
}
7070

71-
CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapFree(uint64_t & currentHeapFree)
71+
CHIP_ERROR DiagnosticDataProviderImpl::ResetWatermarks()
7272
{
73-
// Overide with dummy value to pass CI
74-
currentHeapFree = 0;
75-
return CHIP_NO_ERROR;
76-
}
77-
78-
CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapUsed(uint64_t & currentHeapUsed)
79-
{
80-
// Overide with dummy value to pass CI
81-
currentHeapUsed = 0;
82-
return CHIP_NO_ERROR;
83-
}
73+
// If implemented, the server SHALL set the value of the CurrentHeapHighWatermark attribute to the
74+
// value of the CurrentHeapUsed.
75+
// On Darwin, overide with non-op to pass CI.
8476

85-
CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark)
86-
{
87-
// Overide with dummy value to pass CI
88-
currentHeapHighWatermark = 0;
89-
return CHIP_NO_ERROR;
90-
}
91-
92-
CHIP_ERROR DiagnosticDataProviderImpl::SetCurrentHeapHighWatermark(uint64_t heapHighWatermark)
93-
{
94-
// Overide to pass CI
9577
return CHIP_NO_ERROR;
9678
}
9779

src/platform/Darwin/DiagnosticDataProviderImpl.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
4040
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override;
4141

4242
// ===== Methods that implement the DiagnosticDataProvider abstract interface.
43-
CHIP_ERROR GetCurrentHeapFree(uint64_t & currentHeapFree) override;
44-
CHIP_ERROR GetCurrentHeapUsed(uint64_t & currentHeapUsed) override;
45-
CHIP_ERROR GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark) override;
46-
CHIP_ERROR SetCurrentHeapHighWatermark(uint64_t heapHighWatermark) override;
43+
CHIP_ERROR ResetWatermarks() override;
4744
};
4845

4946
} // namespace DeviceLayer

src/platform/Linux/DiagnosticDataProviderImpl.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,17 @@ CHIP_ERROR DiagnosticDataProviderImpl::SetCurrentHeapHighWatermark(uint64_t heap
274274
return CHIP_NO_ERROR;
275275
}
276276

277+
CHIP_ERROR DiagnosticDataProviderImpl::ResetWatermarks()
278+
{
279+
// If implemented, the server SHALL set the value of the CurrentHeapHighWatermark attribute to the
280+
// value of the CurrentHeapUsed.
281+
282+
// On Linux, the write operation is non-op since we always rely on the mallinfo system
283+
// function to get the current heap memory.
284+
285+
return CHIP_NO_ERROR;
286+
}
287+
277288
CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadMetricsOut)
278289
{
279290
CHIP_ERROR err = CHIP_ERROR_READ_FAILED;

src/platform/Linux/DiagnosticDataProviderImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class DiagnosticDataProviderImpl : public DiagnosticDataProvider
4444
CHIP_ERROR GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark) override;
4545
CHIP_ERROR GetThreadMetrics(ThreadMetrics ** threadMetricsOut) override;
4646
CHIP_ERROR SetCurrentHeapHighWatermark(uint64_t heapHighWatermark) override;
47+
CHIP_ERROR ResetWatermarks() override;
4748
void ReleaseThreadMetrics(ThreadMetrics * threadMetrics) override;
4849

4950
CHIP_ERROR GetRebootCount(uint16_t & rebootCount) override;

0 commit comments

Comments
 (0)