From 6661fe0dd7f1dd73cefd1d10a4f70da7cbfee5b7 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 10 Oct 2019 19:13:17 -0500 Subject: [PATCH] mon: fix 'heap ...' command Duplicate what the OSD is doing here. Signed-off-by: Sage Weil --- src/mon/MonCommands.h | 4 ---- src/mon/Monitor.cc | 44 ++++++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index e14c9fefbfa..4534cf3be81 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -242,10 +242,6 @@ COMMAND("mon ok-to-rm " \ "check whether removing the specified mon would break quorum", "mon", "r") -COMMAND_WITH_FLAG("heap " \ - "name=heapcmd,type=CephChoices,strings=dump|start_profiler|stop_profiler|release|stats", \ - "show heap usage info (available only if compiled with tcmalloc)", \ - "mon", "rw", FLAG(NOFORWARD)) COMMAND("tell " \ "name=target,type=CephName " \ "name=args,type=CephString,n=N", \ diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index aa1f9b95ffc..67779f4b56d 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -399,6 +399,25 @@ int Monitor::do_admin_command( json_map[devid] = smart_json; } json_spirit::write(json_map, out, json_spirit::pretty_print); + } else if (command == "heap") { + if (!ceph_using_tcmalloc()) { + err << "could not issue heap profiler command -- not using tcmalloc!"; + r = -EOPNOTSUPP; + goto abort; + } + string cmd; + if (!cmd_getval(cct, cmdmap, "heapcmd", cmd)) { + err << "unable to get value for command \"" << cmd << "\""; + r = -EINVAL; + goto abort; + } + std::vector cmd_vec; + get_str_vec(cmd, cmd_vec); + string val; + if (cmd_getval(cct, cmdmap, "value", val)) { + cmd_vec.push_back(val); + } + ceph_heap_profiler_handle_command(cmd_vec, out); } else { ceph_abort_msg("bad AdminSocket command binding"); } @@ -879,6 +898,14 @@ int Monitor::preinit() admin_hook, "probe OSD devices for SMART data."); ceph_assert(r == 0); + r = admin_socket->register_command( + "heap " \ + "name=heapcmd,type=CephChoices,strings=" \ + "dump|start_profiler|stop_profiler|release|get_release_rate|set_release_rate|stats " \ + "name=value,type=CephString,req=false", + admin_hook, + "show heap usage info (available only if compiled with tcmalloc)"); + ceph_assert(r == 0); l.lock(); @@ -3733,23 +3760,6 @@ void Monitor::handle_command(MonOpRequestRef op) } r = 0; rs = "safe to remove mon." + id; - } else if (prefix == "heap") { - if (!ceph_using_tcmalloc()) - rs = "tcmalloc not enabled, can't use heap profiler commands\n"; - else { - string heapcmd; - cmd_getval(g_ceph_context, cmdmap, "heapcmd", heapcmd); - // XXX 1-element vector, change at callee or make vector here? - vector heapcmd_vec; - get_str_vec(heapcmd, heapcmd_vec); - string value; - if (cmd_getval(g_ceph_context, cmdmap, "value", value)) - heapcmd_vec.push_back(value); - ceph_heap_profiler_handle_command(heapcmd_vec, ds); - rdata.append(ds); - rs = ""; - r = 0; - } } else if (prefix == "version") { if (f) { f->open_object_section("version"); -- 2.39.5