]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: dump each shard seastar metrics 49325/head
authorchunmei-liu <chunmei.liu@intel.com>
Thu, 8 Dec 2022 07:48:33 +0000 (23:48 -0800)
committerchunmei-liu <chunmei.liu@intel.com>
Fri, 9 Dec 2022 00:27:10 +0000 (16:27 -0800)
Signed-off-by: chunmei-liu <chunmei.liu@intel.com>
Signed-off-by: Samuel Just <sjust@redhat.com>
src/crimson/admin/osd_admin.cc
src/crimson/common/smp_helpers.h

index d93e294d28dd2b5293959939b516c557fcc19ab6..4f7e149ea0f6680fc379a4ad3adcbbfaf21e8a81 100644 (file)
@@ -226,22 +226,30 @@ public:
                                       std::string_view format,
                                       ceph::bufferlist&& input) const final
   {
-    std::unique_ptr<Formatter> f{Formatter::create(format, "json-pretty", "json-pretty")};
+    std::unique_ptr<Formatter> fref{Formatter::create(format, "json-pretty", "json-pretty")};
+    auto *f = fref.get();
     std::string prefix;
     cmd_getval(cmdmap, "group", prefix);
     f->open_object_section("metrics");
-    for (const auto& [full_name, metric_family]: seastar::scollectd::get_value_map()) {
-      if (!prefix.empty() && full_name.compare(0, prefix.size(), prefix) != 0) {
-        continue;
-      }
-      for (const auto& [labels, metric] : metric_family) {
-        if (metric && metric->is_enabled()) {
-          dump_metric_value(f.get(), full_name, *metric, labels);
+    f->open_array_section("metrics");
+    return seastar::do_with(std::move(prefix), [f](auto &prefix) {
+      return crimson::reactor_map_seq([f, &prefix] {
+        for (const auto& [full_name, metric_family]: seastar::scollectd::get_value_map()) {
+          if (!prefix.empty() && full_name.compare(0, prefix.size(), prefix) != 0) {
+            continue;
+          }
+          for (const auto& [labels, metric] : metric_family) {
+            if (metric && metric->is_enabled()) {
+              DumpMetricsHook::dump_metric_value(f, full_name, *metric, labels);
+            }
+          }
         }
-      }
-    }
-    f->close_section();
-    return seastar::make_ready_future<tell_result_t>(std::move(f));
+      });
+    }).then([fref = std::move(fref)]() mutable {
+      fref->close_section();
+      fref->close_section();
+      return seastar::make_ready_future<tell_result_t>(std::move(fref));
+    });
   }
 private:
   using registered_metric = seastar::metrics::impl::registered_metric;
index 165f110b6e8b5cfeb04f0594b209601120519461..c2b7bd9641a77d33390f50b991c24d536370d38d 100644 (file)
@@ -41,25 +41,23 @@ auto proxy_method_on_core(
 }
 
 /**
- * sharded_map_seq
+ * reactor_map_seq
  *
- * Invokes f on each shard of t sequentially.  Caller may assume that
+ * Invokes f on each reactor sequentially, Caller may assume that
  * f will not be invoked concurrently on multiple cores.
  */
-template <typename T, typename F>
-auto sharded_map_seq(T &t, F &&f) {
-  using ret_type = decltype(f(t.local()));
-  // seastar::smp::submit_to because sharded::invoke_on doesn't have
-  // a const overload.
+template <typename F>
+auto reactor_map_seq(F &&f) {
+  using ret_type = decltype(f());
   if constexpr (is_errorated_future_v<ret_type>) {
     auto ret = crimson::do_for_each(
       seastar::smp::all_cpus().begin(),
       seastar::smp::all_cpus().end(),
-      [&t, f=std::move(f)](auto core) mutable {
+      [f=std::move(f)](auto core) mutable {
        return seastar::smp::submit_to(
          core,
-         [&t, &f] {
-           return std::invoke(f, t.local());
+         [&f] {
+           return std::invoke(f);
          });
       });
     return ret_type(ret);
@@ -67,14 +65,28 @@ auto sharded_map_seq(T &t, F &&f) {
     return seastar::do_for_each(
       seastar::smp::all_cpus().begin(),
       seastar::smp::all_cpus().end(),
-      [&t, f=std::move(f)](auto core) mutable {
+      [f=std::move(f)](auto core) mutable {
        return seastar::smp::submit_to(
          core,
-         [&t, &f] {
-           return std::invoke(f, t.local());
+         [&f] {
+           return std::invoke(f);
          });
       });
   }
 }
 
+/**
+ * sharded_map_seq
+ *
+ * Invokes f on each shard of t sequentially.  Caller may assume that
+ * f will not be invoked concurrently on multiple cores.
+ */
+template <typename T, typename F>
+auto sharded_map_seq(T &t, F &&f) {
+  return reactor_map_seq(
+    [&t, f=std::forward<F>(f)]() mutable {
+      return std::invoke(f, t.local());
+    });
+}
+
 }