Skip to content

Commit

Permalink
metrics: expose metric impl handle to internal api
Browse files Browse the repository at this point in the history
This patch extends the metrics internal apis to use a specific
metrics::impl::impl object identified by its integer handle.
  • Loading branch information
Vlad Lazar committed Jun 1, 2022
1 parent 585a8af commit 6ee4af7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions include/seastar/core/metrics_api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class registered_metric {
metric_function _f;
shared_ptr<impl> _impl;
public:
registered_metric(metric_id id, metric_function f, bool enabled=true);
registered_metric(metric_id id, metric_function f, bool enabled=true, int handle=default_handle());
virtual ~registered_metric() {}
virtual metric_value operator()() const {
return _f();
Expand Down Expand Up @@ -365,14 +365,15 @@ public:
}
};

const value_map& get_value_map();
const value_map& get_value_map(int handle = default_handle());
using values_reference = shared_ptr<values_copy>;

foreign_ptr<values_reference> get_values();
foreign_ptr<values_reference> get_values(int handle = default_handle());

shared_ptr<impl> get_local_impl(int handle = default_handle());

void unregister_metric(const metric_id & id);

void unregister_metric(const metric_id & id, int handle = default_handle());

/*!
* \brief initialize metric group
Expand Down
18 changes: 9 additions & 9 deletions src/core/metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ bool label_instance::operator!=(const label_instance& id2) const {
label shard_label("shard");
namespace impl {

registered_metric::registered_metric(metric_id id, metric_function f, bool enabled) :
_f(f), _impl(get_local_impl()) {
registered_metric::registered_metric(metric_id id, metric_function f, bool enabled, int handle) :
_f(f), _impl(get_local_impl(handle)) {
_info.enabled = enabled;
_info.id = id;
}
Expand Down Expand Up @@ -262,20 +262,20 @@ void impl::remove_registration(const metric_id& id) {
}
}

void unregister_metric(const metric_id & id) {
get_local_impl()->remove_registration(id);
void unregister_metric(const metric_id & id, int handle) {
get_local_impl(handle)->remove_registration(id);
}

const value_map& get_value_map() {
return get_local_impl()->get_value_map();
const value_map& get_value_map(int handle) {
return get_local_impl(handle)->get_value_map();
}

foreign_ptr<values_reference> get_values() {
foreign_ptr<values_reference> get_values(int handle) {
shared_ptr<values_copy> res_ref = ::seastar::make_shared<values_copy>();
auto& res = *(res_ref.get());
auto& mv = res.values;
res.metadata = get_local_impl()->metadata();
auto & functions = get_local_impl()->functions();
res.metadata = get_local_impl(handle)->metadata();
auto & functions = get_local_impl(handle)->functions();
mv.reserve(functions.size());
for (auto&& i : functions) {
value_vector values;
Expand Down

0 comments on commit 6ee4af7

Please sign in to comment.