From 186998277f1317fbe1d69b1542b9615c91620907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20=C5=9Awi=C4=99cki?= Date: Wed, 15 Feb 2017 11:13:50 +0100 Subject: [PATCH] common: Fix clang compilation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bartłomiej Święcki --- src/common/perf_histogram.h | 7 +++-- src/test/common/test_perf_histogram.cc | 41 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/common/perf_histogram.h b/src/common/perf_histogram.h index 6d315905db3e3..f6095875b62bc 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 @@ class PerfHistogram : public PerfHistogramCommon { 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 @@ class PerfHistogram : public PerfHistogramCommon { /// 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 a6bf8c488ae60..4ca8d687af872 100644 --- a/src/test/common/test_perf_histogram.cc +++ b/src/test/common/test_perf_histogram.cc @@ -33,6 +33,10 @@ class PerfHistogramAccessor : public PerfHistogram { 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));