Skip to content

Commit

Permalink
移动 g_user_metric_label_count位置,避免循环引用 (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
20083017 authored Oct 28, 2024
1 parent cc10dbb commit 8ae2183
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 4 additions & 1 deletion include/ylt/metric/dynamic_metric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
#include <thread>

#include "metric.hpp"
#include "thread_local_value.hpp"
#include "ylt/util/map_sharded.hpp"

namespace ylt::metric {

class dynamic_metric : public metric_t {
public:
static inline auto g_user_metric_label_count =
new thread_local_value<int64_t>(std::thread::hardware_concurrency());
using metric_t::metric_t;
};

Expand Down Expand Up @@ -124,4 +127,4 @@ class dynamic_metric_impl : public dynamic_metric {
my_hash<137>>
map_{std::min<unsigned>(128u, std::thread::hardware_concurrency())};
};
} // namespace ylt::metric
} // namespace ylt::metric
4 changes: 1 addition & 3 deletions include/ylt/metric/metric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "async_simple/coro/Lazy.h"
#include "async_simple/coro/SyncAwait.h"
#include "cinatra/cinatra_log_wrapper.hpp"
#include "thread_local_value.hpp"
#if __has_include("ylt/coro_io/coro_io.hpp")
#include "ylt/coro_io/coro_io.hpp"
#else
Expand Down Expand Up @@ -52,8 +51,7 @@ struct metric_filter_options {
class metric_t {
public:
static inline std::atomic<int64_t> g_user_metric_count = 0;
static inline auto g_user_metric_label_count =
new thread_local_value<int64_t>(std::thread::hardware_concurrency());

metric_t() = default;
metric_t(MetricType type, std::string name, std::string help)
: type_(type),
Expand Down
5 changes: 3 additions & 2 deletions include/ylt/metric/system_metric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ inline void stat_metric() {
static auto user_metric_label_count =
system_metric_manager::instance().get_metric_static<gauge_t>(
"ylt_user_metric_labels");
user_metric_label_count->update(metric_t::g_user_metric_label_count->value());
user_metric_label_count->update(
dynamic_metric::g_user_metric_label_count->value());
}

inline void ylt_stat() {
Expand Down Expand Up @@ -451,4 +452,4 @@ inline bool start_system_metric() {
return true;
}
} // namespace ylt::metric
#endif
#endif

0 comments on commit 8ae2183

Please sign in to comment.