Skip to content

Commit

Permalink
Merge pull request #13335 from ovh/wip-clang-compilation-fix
Browse files Browse the repository at this point in the history
common: Fix clang compilation

Reviewed-by: Willem Jan Withagen <wjw@digiware.nl>
Reviewed-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Feb 18, 2017
2 parents 6dcd79c + 1869982 commit 2a05daa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/common/perf_histogram.h
Expand Up @@ -19,6 +19,7 @@
#include "include/atomic.h"
#include "include/int_types.h"

#include <array>
#include <memory>

class PerfHistogramCommon {
Expand Down Expand Up @@ -133,7 +134,7 @@ class PerfHistogram : public PerfHistogramCommon {
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 {
Expand All @@ -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;
}
Expand Down
41 changes: 41 additions & 0 deletions src/test/common/test_perf_histogram.cc
Expand Up @@ -33,6 +33,10 @@ class PerfHistogramAccessor : public PerfHistogram<DIM> {
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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 2a05daa

Please sign in to comment.