From: Bartłomiej Święcki Date: Wed, 15 Feb 2017 10:13:50 +0000 (+0100) Subject: common: Fix clang compilation X-Git-Tag: v12.0.1~354^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F13335%2Fhead;p=ceph.git common: Fix clang compilation Signed-off-by: Bartłomiej Święcki --- diff --git a/src/common/perf_histogram.h b/src/common/perf_histogram.h index 6d315905db3..f6095875b62 100644 --- a/src/common/perf_histogram.h +++ b/src/common/perf_histogram.h @@ -19,6 +19,7 @@ #include "include/atomic.h" #include "include/int_types.h" +#include #include class PerfHistogramCommon { @@ -133,7 +134,7 @@ protected: std::unique_ptr m_rawData; /// Configuration of axes - axis_config_d m_axes_config[DIM]; + std::array m_axes_config; /// Dump histogram counters to a formatter void dump_formatted_values(ceph::Formatter *f) const { @@ -145,8 +146,8 @@ protected: /// Get number of all histogram counters int64_t get_raw_size() { int64_t ret = 1; - for (int i = 0; i < DIM; ++i) { - ret *= m_axes_config[i].m_buckets; + for (const auto &ac : m_axes_config) { + ret *= ac.m_buckets; } return ret; } diff --git a/src/test/common/test_perf_histogram.cc b/src/test/common/test_perf_histogram.cc index a6bf8c488ae..4ca8d687af8 100644 --- a/src/test/common/test_perf_histogram.cc +++ b/src/test/common/test_perf_histogram.cc @@ -33,6 +33,10 @@ public: return Base::get_axis_bucket_ranges(axis_config); } + const typename Base::axis_config_d& get_axis_config(int num) { + return Base::m_axes_config[num]; + } + template void visit_values(F1 f1, F2 f2, F3 f3) { Base::visit_values(f1, f2, f3); @@ -99,6 +103,43 @@ TEST(PerfHistogram, ZeroedInitially) { } } +TEST(PerfHistogram, Copy) { + PerfHistogramAccessor<2> h1{x_axis, y_axis}; + h1.inc_bucket(1, 1); + h1.inc_bucket(2, 3); + h1.inc_bucket(4, 5); + + PerfHistogramAccessor<2> h2 = h1; + + const int cx = 1; + const int cy = 2; + + h1.inc_bucket(cx, cy); + + // Axes configuration must be equal + for (int i = 0; i < 2; i++) { + const auto& ac1 = h1.get_axis_config(i); + const auto& ac2 = h2.get_axis_config(i); + ASSERT_EQ(ac1.m_name, ac2.m_name); + ASSERT_EQ(ac1.m_scale_type, ac2.m_scale_type); + ASSERT_EQ(ac1.m_min, ac2.m_min); + ASSERT_EQ(ac1.m_quant_size, ac2.m_quant_size); + ASSERT_EQ(ac1.m_buckets, ac2.m_buckets); + } + + // second histogram must have histogram values equal to the first + // one at the time of copy + for (int x = 0; x < XS; x++) { + for (int y = 0; y < YS; y++) { + if (x == cx && y == cy) { + ASSERT_NE(h1.read_bucket(x, y), h2.read_bucket(x, y)); + } else { + ASSERT_EQ(h1.read_bucket(x, y), h2.read_bucket(x, y)); + } + } + } +} + TEST(PerfHistogram, SimpleValues) { PerfHistogramAccessor<2> h{x_axis, y_axis}; ASSERT_EQ(0UL, h.read_bucket(1, 1));