]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mempool: fix lack of pool names in mempool:dump output for JSON formatter. 18329/head
authorIgor Fedotov <ifed@mail.ru>
Mon, 16 Oct 2017 14:18:48 +0000 (07:18 -0700)
committerIgor Fedotov <ifed@mail.ru>
Wed, 25 Oct 2017 16:05:39 +0000 (09:05 -0700)
Signed-off-by: Igor Fedotov <ifed@mail.ru>
src/common/mempool.cc
src/test/test_mempool.cc

index 3a9cdba4fcc22cc9cb2b9548bfe6962e497412a8..02ed3c6558e97d5e14015066a1dc59406f3fd237 100644 (file)
@@ -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)
index a9c6fc88b75fe83f41b6d2abecc67d053b718108..ceda676c41c7c0855262924e8ee52c6c26b07339 100644 (file)
@@ -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)