From 5826e94a657170fec97df98a8a06963c4b96abb7 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Wed, 31 Jul 2024 21:42:56 +0800 Subject: [PATCH] improve counter --- include/ylt/metric/counter.hpp | 10 ++++++++++ include/ylt/metric/gauge.hpp | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/ylt/metric/counter.hpp b/include/ylt/metric/counter.hpp index b3bfb75a7..8990f6ba0 100644 --- a/include/ylt/metric/counter.hpp +++ b/include/ylt/metric/counter.hpp @@ -289,6 +289,16 @@ class basic_counter : public metric_t { } } + template + void set_value_static(T &label_val, value_type value, op_type_t type) { + set_value(label_val, value, type); + } + + template + void set_value_dynamic(T &label_val, value_type value, op_type_t type) { + set_value(label_val, value, type); + } + template void set_value(T &label_val, value_type value, op_type_t type) { switch (type) { diff --git a/include/ylt/metric/gauge.hpp b/include/ylt/metric/gauge.hpp index 7793ff567..af9265ed6 100644 --- a/include/ylt/metric/gauge.hpp +++ b/include/ylt/metric/gauge.hpp @@ -16,6 +16,8 @@ class basic_gauge : public basic_counter { using basic_counter::value_map_; using basic_counter::mtx_; using basic_counter::stat_metric; + using basic_counter::set_value_static; + using basic_counter::set_value_dynamic; public: basic_gauge(std::string name, std::string help, size_t dupli_count = 2) @@ -56,14 +58,14 @@ class basic_gauge : public basic_counter { throw std::invalid_argument( "the given labels_value is not match with origin labels_value"); } - set_value(atomic_value_map_[labels_value].local_value(), value, - op_type_t::DEC); + set_value_static(atomic_value_map_[labels_value].local_value(), value, + op_type_t::DEC); } else { std::lock_guard lock(mtx_); stat_metric(labels_value); - set_value(value_map_[labels_value].local_value(), value, - op_type_t::DEC); + set_value_dynamic(value_map_[labels_value].local_value(), value, + op_type_t::DEC); } } };