Merge pull request #49325 from liu-chunmei/crimson-reactor_utilization

crimson/osd: dump each shard seastar metrics

Reviewed-by: Samuel Just <sjust@redhat.com>
Reviewed-by: Kefu Chai <tchaikov@gmail.com>
Reviewed-by: Yingxin Cheng <yingxin.cheng@intel.com>
This commit is contained in:
Yingxin 2022-12-12 15:43:12 +08:00 committed by GitHub
commit 388e45d345
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 25 deletions

View 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;

View 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());
});
}
}