Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: Fix clang compilation #13335

Merged
merged 1 commit into from Feb 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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