Skip to content

Commit 610c114

Browse files
authored
[7.2][ML] Correct outlier peak memory callback and test (elastic#484)
1 parent 0a0860c commit 610c114

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/api/CDataFrameOutliersRunner.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ void CDataFrameOutliersRunner::runImpl(core::CDataFrame& frame) {
118118
m_NumberNeighbours,
119119
m_ComputeFeatureInfluence,
120120
m_OutlierFraction};
121-
maths::COutliers::compute(params, frame, this->progressRecorder(), [](std::uint64_t memory) {
122-
core::CProgramCounters::counter(counter_t::E_DFOPeakMemoryUsage).max(memory);
123-
});
121+
std::atomic<std::int64_t> memory{0};
122+
maths::COutliers::compute(
123+
params, frame, this->progressRecorder(), [&memory](std::int64_t delta) {
124+
std::int64_t memory_{memory.fetch_add(delta)};
125+
core::CProgramCounters::counter(counter_t::E_DFOPeakMemoryUsage).max(memory_);
126+
});
124127
}
125128

126129
std::size_t

lib/api/unittest/CDataFrameAnalyzerTest.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <core/CContainerPrinter.h>
1010
#include <core/CJsonOutputStreamWrapper.h>
11+
#include <core/CProgramCounters.h>
1112
#include <core/CStringUtils.h>
1213

1314
#include <maths/CBasicStatistics.h>
@@ -242,6 +243,13 @@ void CDataFrameAnalyzerTest::testRunOutlierDetection() {
242243
}
243244
CPPUNIT_ASSERT(expectedScore == expectedScores.end());
244245
CPPUNIT_ASSERT(progressCompleted);
246+
247+
LOG_DEBUG(<< "number partitions = "
248+
<< core::CProgramCounters::counter(counter_t::E_DFONumberPartitions));
249+
LOG_DEBUG(<< "peak memory = "
250+
<< core::CProgramCounters::counter(counter_t::E_DFOPeakMemoryUsage));
251+
CPPUNIT_ASSERT(core::CProgramCounters::counter(counter_t::E_DFONumberPartitions) == 1);
252+
CPPUNIT_ASSERT(core::CProgramCounters::counter(counter_t::E_DFOPeakMemoryUsage) < 100000);
245253
}
246254

247255
void CDataFrameAnalyzerTest::testRunOutlierDetectionPartitioned() {
@@ -281,6 +289,13 @@ void CDataFrameAnalyzerTest::testRunOutlierDetectionPartitioned() {
281289
}
282290
}
283291
CPPUNIT_ASSERT(expectedScore == expectedScores.end());
292+
293+
LOG_DEBUG(<< "number partitions = "
294+
<< core::CProgramCounters::counter(counter_t::E_DFONumberPartitions));
295+
LOG_DEBUG(<< "peak memory = "
296+
<< core::CProgramCounters::counter(counter_t::E_DFOPeakMemoryUsage));
297+
CPPUNIT_ASSERT(core::CProgramCounters::counter(counter_t::E_DFONumberPartitions) > 1);
298+
CPPUNIT_ASSERT(core::CProgramCounters::counter(counter_t::E_DFOPeakMemoryUsage) < 110000); // + 10%
284299
}
285300

286301
void CDataFrameAnalyzerTest::testRunOutlierFeatureInfluences() {

0 commit comments

Comments
 (0)