common/perf_counters: make 'perf schema' more friendly

The raw bits are pretty hard to interpret and the documentation isn't
super easy to find.  Expose a string description instead.

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2017-05-03 08:24:45 -05:00
parent caf3367aab
commit 76211dc146
3 changed files with 36 additions and 11 deletions

View File

@ -370,14 +370,38 @@ void PerfCounters::dump_formatted_generic(Formatter *f, bool schema,
if (schema) {
f->open_object_section(d->name);
// we probably should not have exposed this raw field (with bit
// values), but existing plugins rely on it so we're stuck with
// it.
f->dump_int("type", d->type);
if (d->description) {
f->dump_string("description", d->description);
if (d->type & PERFCOUNTER_COUNTER) {
f->dump_string("metric_type", "counter");
} else {
f->dump_string("description", "");
f->dump_string("metric_type", "gauge");
}
if (d->type & PERFCOUNTER_LONGRUNAVG) {
if (d->type & PERFCOUNTER_TIME) {
f->dump_string("value_type", "real-integer-pair");
} else {
f->dump_string("value_type", "integer-integer-pair");
}
} else if (d->type & PERFCOUNTER_HISTOGRAM) {
if (d->type & PERFCOUNTER_TIME) {
f->dump_string("value_type", "real-2d-histogram");
} else {
f->dump_string("value_type", "integer-2d-histogram");
}
} else {
if (d->type & PERFCOUNTER_TIME) {
f->dump_string("value_type", "real");
} else {
f->dump_string("value_type", "integer");
}
}
f->dump_string("description", d->description ? d->description : "");
if (d->nick != NULL) {
f->dump_string("nick", d->nick);
} else {
@ -535,8 +559,10 @@ PerfCounters *PerfCountersBuilder::create_perf_counters()
{
PerfCounters::perf_counter_data_vec_t::const_iterator d = m_perf_counters->m_data.begin();
PerfCounters::perf_counter_data_vec_t::const_iterator d_end = m_perf_counters->m_data.end();
for (; d != d_end; ++d)
for (; d != d_end; ++d) {
assert(d->type != PERFCOUNTER_NONE);
assert(d->type & (PERFCOUNTER_U64 | PERFCOUNTER_TIME));
}
PerfCounters *ret = m_perf_counters;
m_perf_counters = NULL;

View File

@ -37,11 +37,11 @@ class PerfCountersBuilder;
enum perfcounter_type_d : uint8_t
{
PERFCOUNTER_NONE = 0,
PERFCOUNTER_TIME = 0x1,
PERFCOUNTER_U64 = 0x2,
PERFCOUNTER_LONGRUNAVG = 0x4,
PERFCOUNTER_COUNTER = 0x8,
PERFCOUNTER_HISTOGRAM = 0x10,
PERFCOUNTER_TIME = 0x1, // float (measuring seconds)
PERFCOUNTER_U64 = 0x2, // integer (note: either TIME or U64 *must* be set)
PERFCOUNTER_LONGRUNAVG = 0x4, // paired counter + sum (time)
PERFCOUNTER_COUNTER = 0x8, // counter (vs guage)
PERFCOUNTER_HISTOGRAM = 0x10, // histogram (vector) of values
};

View File

@ -182,8 +182,7 @@ TEST(PerfCounters, MultiplePerfCounters) {
ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":13,\"element2\":0.000000000,"
"\"element3\":{\"avgcount\":0,\"sum\":0.000000000}}}"), msg);
ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf schema\", \"format\": \"json\" }", &msg));
ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":{\"type\":2,\"description\":\"\",\"nick\":\"\"},"
"\"element2\":{\"type\":1,\"description\":\"\",\"nick\":\"\"},\"element3\":{\"type\":5,\"description\":\"\",\"nick\":\"\"}}}"), msg);
ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":{\"type\":2,\"metric_type\":\"gauge\",\"value_type\":\"integer\",\"description\":\"\",\"nick\":\"\"},\"element2\":{\"type\":1,\"metric_type\":\"gauge\",\"value_type\":\"real\",\"description\":\"\",\"nick\":\"\"},\"element3\":{\"type\":5,\"metric_type\":\"gauge\",\"value_type\":\"real-integer-pair\",\"description\":\"\",\"nick\":\"\"}}}"), msg);
coll->clear();
ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
ASSERT_EQ("{}", msg);