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)
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)