diff --git a/source/common/stats/heap_stat_data.cc b/source/common/stats/heap_stat_data.cc index 1ea8768e6f1b..2bb3d7646db8 100644 --- a/source/common/stats/heap_stat_data.cc +++ b/source/common/stats/heap_stat_data.cc @@ -86,11 +86,9 @@ template class StatsSharedImpl : public MetricImpl protected: HeapStatDataAllocator& alloc_; - // Holds backing store for both CounterImpl and GaugeImpl. This provides a level - // of indirection needed to enable stats created with the same name from - // different scopes to share the same value. + // Holds backing store shared by both CounterImpl and GaugeImpl. CounterImpl + // adds another field, pending_increment_, that is not used in Gauge. std::atomic value_{0}; - std::atomic pending_increment_{0}; std::atomic flags_{0}; std::atomic ref_count_{0}; }; @@ -113,8 +111,10 @@ class CounterImpl : public StatsSharedImpl { void inc() override { add(1); } uint64_t latch() override { return pending_increment_.exchange(0); } void reset() override { value_ = 0; } - bool used() const override { return flags_ & Flags::Used; } uint64_t value() const override { return value_; } + +private: + std::atomic pending_increment_{0}; }; class GaugeImpl : public StatsSharedImpl { diff --git a/test/integration/stats_integration_test.cc b/test/integration/stats_integration_test.cc index 112475f923cf..a404e8de89d5 100644 --- a/test/integration/stats_integration_test.cc +++ b/test/integration/stats_integration_test.cc @@ -209,6 +209,7 @@ TEST_P(ClusterMemoryTestRunner, MemoryLargeClusterSizeWithStats) { // 2019/06/17 7243 49412 49700 macros for exact/upper-bound memory checks // 2019/06/29 7364 45685 46000 combine 2 levels of stat ref-counting into 1 // 2019/06/30 7428 42742 43000 remove stats multiple inheritance, inline HeapStatData + // 2019/07/06 7477 42742 43000 fork gauge representation to drop pending_increment_ // Note: when adjusting this value: EXPECT_MEMORY_EQ is active only in CI // 'release' builds, where we control the platform and tool-chain. So you @@ -218,7 +219,7 @@ TEST_P(ClusterMemoryTestRunner, MemoryLargeClusterSizeWithStats) { // On a local clang8/libstdc++/linux flow, the memory usage was observed in // June 2019 to be 64 bytes higher than it is in CI/release. Your mileage may // vary. - EXPECT_MEMORY_EQ(m_per_cluster, 42742); + EXPECT_MEMORY_EQ(m_per_cluster, 42742); // 104 bytes higher than a debug build. EXPECT_MEMORY_LE(m_per_cluster, 43000); }