移动 g_user_metric_label_count位置,避免循环引用 (#800)

This commit is contained in:
20083017 2024-10-28 14:54:33 +08:00 committed by GitHub
parent cc10dbbe5b
commit 8ae2183ebe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View File

@ -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;
};
@ -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

View File

@ -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
@ -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),

View File

@ -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() {
@ -451,4 +452,4 @@ inline bool start_system_metric() {
return true;
}
} // namespace ylt::metric
#endif
#endif