From 2aeb7b85c8d793e2b36680deeeb62bd0d785bf18 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Mon, 16 Oct 2017 07:18:48 -0700 Subject: [PATCH] mempool: fix lack of pool names in mempool:dump output for JSON formatter. Signed-off-by: Igor Fedotov --- src/common/mempool.cc | 5 +++++ src/test/test_mempool.cc | 43 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/common/mempool.cc b/src/common/mempool.cc index 3a9cdba4fcc..02ed3c6558e 100644 --- a/src/common/mempool.cc +++ b/src/common/mempool.cc @@ -42,13 +42,18 @@ const char *mempool::get_pool_name(mempool::pool_index_t ix) { void mempool::dump(ceph::Formatter *f) { stats_t total; + f->open_object_section("mempool"); // we need (dummy?) topmost section for + // JSON Formatter to print pool names. It omits them otherwise. + f->open_object_section("by_pool"); for (size_t i = 0; i < num_pools; ++i) { const pool_t &pool = mempool::get_pool((pool_index_t)i); f->open_object_section(get_pool_name((pool_index_t)i)); pool.dump(f, &total); f->close_section(); } + f->close_section(); f->dump_object("total", total); + f->close_section(); } void mempool::set_debug_mode(bool d) diff --git a/src/test/test_mempool.cc b/src/test/test_mempool.cc index a9c6fc88b75..ceda676c41c 100644 --- a/src/test/test_mempool.cc +++ b/src/test/test_mempool.cc @@ -256,6 +256,49 @@ TEST(mempool, list) v.push_back(obj()); v.push_back(obj(1)); } + +} + +TEST(mempool, dump) +{ + ostringstream ostr; + + Formatter* f = Formatter::create("xml-pretty", "xml-pretty", "xml-pretty"); + mempool::dump(f); + f->flush(ostr); + + delete f; + ASSERT_NE(ostr.str().find(mempool::get_pool_name((mempool::pool_index_t)0)), + std::string::npos); + + ostr.str(""); + + f = Formatter::create("html-pretty", "html-pretty", "html-pretty"); + mempool::dump(f); + f->flush(ostr); + + delete f; + ASSERT_NE(ostr.str().find(mempool::get_pool_name((mempool::pool_index_t)0)), + std::string::npos); + + ostr.str(""); + f = Formatter::create("table", "table", "table"); + mempool::dump(f); + f->flush(ostr); + + delete f; + ASSERT_NE(ostr.str().find(mempool::get_pool_name((mempool::pool_index_t)0)), + std::string::npos); + + ostr.str(""); + + f = Formatter::create("json-pretty", "json-pretty", "json-pretty"); + mempool::dump(f); + f->flush(ostr); + delete f; + + ASSERT_NE(ostr.str().find(mempool::get_pool_name((mempool::pool_index_t)0)), + std::string::npos); } TEST(mempool, unordered_map)