From: Jesse Williamson Date: Thu, 1 Dec 2016 20:10:04 +0000 (-0800) Subject: osd: Extends admin console with a "heap" memory profiling command. X-Git-Tag: v12.0.2~120^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=75b5749c47456a373d4dca86f5b5005de0cc8ea1;p=ceph.git osd: Extends admin console with a "heap" memory profiling command. Fixes: http://tracker.ceph.com/issues/15475 Signed-off-by: Jesse Williamson --- diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 4e3afa6e1741..05bee9f4893e 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -40,6 +40,7 @@ #include "Watch.h" #include "osdc/Objecter.h" +#include "common/errno.h" #include "common/ceph_argparse.h" #include "common/version.h" #include "common/io_priority.h" @@ -1986,6 +1987,14 @@ bool OSD::asok_command(string command, cmdmap_t& cmdmap, string format, f->close_section(); } else if (command == "get_latest_osdmap") { get_latest_osdmap(); + } else if (command == "heap") { + auto result = ceph::osd_cmds::admin::heap(*cct, cmdmap, *f, ss); + + // Note: Failed heap profile commands won't necessarily trigger an error: + f->open_object_section("result"); + f->dump_string("error", cpp_strerror(result)); + f->dump_bool("success", result >= 0); + f->close_section(); } else if (command == "set_heap_property") { string property; int64_t value = 0; @@ -2485,6 +2494,14 @@ void OSD::final_init() "the mon"); assert(r == 0); + r = admin_socket->register_command( "heap", + "heap " \ + "name=heapcmd,type=CephString", + asok_hook, + "show heap usage info (available only if " + "compiled with tcmalloc)"); + assert(r == 0); + r = admin_socket->register_command("set_heap_property", "set_heap_property " \ "name=property,type=CephString " \ @@ -9175,8 +9192,6 @@ void OSD::PeeringWQ::_dequeue(list *out) { in_use.insert(out->begin(), out->end()); } - - // ============================================================= #undef dout_context @@ -9542,3 +9557,32 @@ void OSD::ShardedOpWQ::_enqueue_front(pair item) sdata->sdata_cond.SignalOne(); sdata->sdata_lock.Unlock(); } + +namespace ceph { +namespace osd_cmds { +namespace admin { + +int heap(CephContext& cct, cmdmap_t& cmdmap, Formatter& f, std::ostream& os) +{ + if (!ceph_using_tcmalloc()) { + os << "could not issue heap profiler command -- not using tcmalloc!"; + return -EOPNOTSUPP; + } + + string cmd; + std::vector cmd_vec; + + if (false == cmd_getval(&cct, cmdmap, "heapcmd", cmd)) { + os << "unable to get value for command \"" << cmd << "\""; + return -EINVAL; + } + + get_str_vec(cmd, cmd_vec); + + ceph_heap_profiler_handle_command(cmd_vec, os); + + return 0; +} + +}}} // namespace ceph::osd::admin_commands + diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 7efcd376cb4a..0076526a4bd2 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -2452,4 +2452,13 @@ extern const CompatSet::Feature ceph_osd_feature_compat[]; extern const CompatSet::Feature ceph_osd_feature_ro_compat[]; extern const CompatSet::Feature ceph_osd_feature_incompat[]; +namespace ceph { +namespace osd_cmds { +namespace admin { + +int heap(CephContext& cct, cmdmap_t& cmdmap, Formatter& f, std::ostream& os); + +}}} // namespace ceph::osd_cmds::admin + + #endif