]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: fix 'heap ...' command
authorSage Weil <sage@redhat.com>
Fri, 11 Oct 2019 00:13:17 +0000 (19:13 -0500)
committerSage Weil <sage@redhat.com>
Sat, 12 Oct 2019 17:05:36 +0000 (12:05 -0500)
Duplicate what the OSD is doing here.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/MonCommands.h
src/mon/Monitor.cc

index e14c9fefbfae909d92c009de1e39d99506fd5890..4534cf3be8130c278f23dd5c3c4ba5dddc79d9b4 100644 (file)
@@ -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", \
index aa1f9b95ffcb3691477cf0ff0d33c0afd4f85088..67779f4b56d41311b51ebe1faee6f67961bd16da 100644 (file)
@@ -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<std::string> 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<string> 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");