common: Fix clang compilation

Signed-off-by: Bartłomiej Święcki <bartlomiej.swiecki@corp.ovh.com>
This commit is contained in:
Bartłomiej Święcki 2017-02-15 11:13:50 +01:00
parent 15dc6c23b2
commit 186998277f
2 changed files with 45 additions and 3 deletions

View File

@ -19,6 +19,7 @@
#include "include/atomic.h"
#include "include/int_types.h"
#include <array>
#include <memory>
class PerfHistogramCommon {
@ -133,7 +134,7 @@ protected:
std::unique_ptr<atomic64_t[]> m_rawData;
/// Configuration of axes
axis_config_d m_axes_config[DIM];
std::array<axis_config_d, DIM> 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;
}

View File

@ -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 <typename F1, typename F2, typename F3>
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));