From: Mykola Golub Date: Thu, 15 Jan 2015 21:51:50 +0000 (+0200) Subject: osd: use TextTable for osd tree command output X-Git-Tag: v0.93~227^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9e22f6179b61cf712c5e16d85cda33cd9b0aef3f;p=ceph.git osd: use TextTable for osd tree command output Signed-off-by: Mykola Golub --- diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 2789bf5a6455..7cc896a5be95 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -19,8 +19,10 @@ #include "common/config.h" #include "common/Formatter.h" +#include "common/TextTable.h" #include "include/ceph_features.h" #include "include/str_map.h" +#include "include/stringify.h" #include "common/code_environment.h" @@ -2447,47 +2449,56 @@ void OSDMap::print(ostream& out) const // ignore pg_swap_primary } -class OSDTreePlainDumper : public CrushTreeDumper::Dumper { +class OSDTreePlainDumper : public CrushTreeDumper::Dumper { public: - typedef CrushTreeDumper::Dumper Parent; + typedef CrushTreeDumper::Dumper Parent; OSDTreePlainDumper(const CrushWrapper *crush, const OSDMap *osdmap_) : Parent(crush), osdmap(osdmap_) {} - void dump(ostream *out) { - *out << "# id\tweight\ttype name\tup/down\treweight\tprimary-affinity\n"; - Parent::dump(out); + void dump(TextTable *tbl) { + tbl->define_column("# id", TextTable::LEFT, TextTable::RIGHT); + tbl->define_column("weight", TextTable::LEFT, TextTable::RIGHT); + tbl->define_column("type name", TextTable::LEFT, TextTable::LEFT); + tbl->define_column("up/down", TextTable::LEFT, TextTable::RIGHT); + tbl->define_column("reweight", TextTable::LEFT, TextTable::RIGHT); + tbl->define_column("primary-affinity", TextTable::LEFT, TextTable::RIGHT); + + Parent::dump(tbl); + for (int i = 0; i <= osdmap->get_max_osd(); i++) { if (osdmap->exists(i) && !is_touched(i)) - dump_item(CrushTreeDumper::Item(i, 0, 0), out); + dump_item(CrushTreeDumper::Item(i, 0, 0), tbl); } } protected: - virtual void dump_item(const CrushTreeDumper::Item &qi, ostream *out) { - std::streamsize p = out->precision(); - - *out << qi.id << "\t" - << weightf_t(qi.weight) << "\t"; + virtual void dump_item(const CrushTreeDumper::Item &qi, TextTable *tbl) { - for (int k=0; k < qi.depth; k++) - *out << "\t"; + *tbl << qi.id + << stringify(weightf_t(qi.weight)); - if (qi.is_bucket()) - { - *out << crush->get_type_name(crush->get_bucket_type(qi.id)) << " " + ostringstream name; + for (int k = 0; k < qi.depth; k++) + name << " "; + if (qi.is_bucket()) { + name << crush->get_type_name(crush->get_bucket_type(qi.id)) << " " << crush->get_item_name(qi.id); + } else { + name << "osd." << qi.id; } - else - { - *out << "osd." << qi.id << "\t"; - if (!osdmap->exists(qi.id)) - *out << "DNE\t\t"; - else - *out << (osdmap->is_up(qi.id) ? "up" : "down") << "\t"; - *out << weightf_t(osdmap->exists(qi.id) ? osdmap->get_weightf(qi.id) : 0) << "\t" - << (osdmap->exists(qi.id) ? osdmap->get_primary_affinityf(qi.id) : 0); + *tbl << name.str(); + + if (!qi.is_bucket()) { + if (!osdmap->exists(qi.id)) { + *tbl << "DNE" + << 0; + } else { + *tbl << (osdmap->is_up(qi.id) ? "up" : "down") + << stringify(weightf_t(osdmap->get_weightf(qi.id))) + << osdmap->get_primary_affinityf(qi.id); + } } - *out << std::setprecision(p) << "\n"; + *tbl << TextTable::endrow; } private: @@ -2531,8 +2542,11 @@ private: void OSDMap::print_tree(ostream *out, Formatter *f) const { - if (out) - OSDTreePlainDumper(crush.get(), this).dump(out); + if (out) { + TextTable tbl; + OSDTreePlainDumper(crush.get(), this).dump(&tbl); + *out << tbl; + } if (f) OSDTreeFormattingDumper(crush.get(), this).dump(f); }