diff options
author | k-vukolov <k-vukolov@yandex-team.ru> | 2022-03-29 16:44:31 +0300 |
---|---|---|
committer | k-vukolov <k-vukolov@yandex-team.ru> | 2022-03-29 16:44:31 +0300 |
commit | 8346d1d110370353c7585db281fb3016b988791e (patch) | |
tree | a3fd235b0f65b3d5b1fd8af2d64d41f644d3b705 | |
parent | f5e0c92bca2eea631a3261806192e1144bd9ab77 (diff) | |
download | ydb-8346d1d110370353c7585db281fb3016b988791e.tar.gz |
Copy metrics while accept
ref:e23a9eb7d1d1bc875bdf136ed30b9605db304bb8
-rw-r--r-- | library/cpp/monlib/metrics/fake.cpp | 2 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/labels.h | 10 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/metric.h | 4 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/metric_registry.cpp | 19 |
4 files changed, 21 insertions, 14 deletions
diff --git a/library/cpp/monlib/metrics/fake.cpp b/library/cpp/monlib/metrics/fake.cpp index d7b21339c3..cbfa1dc031 100644 --- a/library/cpp/monlib/metrics/fake.cpp +++ b/library/cpp/monlib/metrics/fake.cpp @@ -89,7 +89,7 @@ namespace NMonitoring { { TWriteGuard g{Lock_}; - IMetricPtr metric = MakeHolder<TMetric>(std::forward<Args>(args)...); + IMetricPtr metric = MakeIntrusive<TMetric>(std::forward<Args>(args)...); // decltype(Metrics_)::iterator breaks build on windows THashMap<ILabelsPtr, IMetricPtr>::iterator it; diff --git a/library/cpp/monlib/metrics/labels.h b/library/cpp/monlib/metrics/labels.h index 63dc997c28..d841ea666c 100644 --- a/library/cpp/monlib/metrics/labels.h +++ b/library/cpp/monlib/metrics/labels.h @@ -114,7 +114,7 @@ namespace NMonitoring { using TLabel = TLabelImpl<TString>; - struct ILabels { + struct ILabels : public TThrRefBase { struct TIterator { TIterator() = default; TIterator(const ILabels* labels, size_t idx = 0) @@ -394,20 +394,20 @@ namespace NMonitoring { }; using TLabels = TLabelsImpl<TString>; - using ILabelsPtr = THolder<ILabels>; + using ILabelsPtr = TIntrusivePtr<ILabels>; template <typename T> ILabelsPtr MakeLabels() { - return MakeHolder<TLabelsImpl<T>>(); + return MakeIntrusive<TLabelsImpl<T>>(); } template <typename T> ILabelsPtr MakeLabels(std::initializer_list<TLabelImpl<T>> labels) { - return MakeHolder<TLabelsImpl<T>>(labels); + return MakeIntrusive<TLabelsImpl<T>>(labels); } inline ILabelsPtr MakeLabels(TLabels&& labels) { - return MakeHolder<TLabels>(std::move(labels)); + return MakeIntrusive<TLabels>(std::move(labels)); } } diff --git a/library/cpp/monlib/metrics/metric.h b/library/cpp/monlib/metrics/metric.h index b8ce12d753..d655ba44ec 100644 --- a/library/cpp/monlib/metrics/metric.h +++ b/library/cpp/monlib/metrics/metric.h @@ -9,7 +9,7 @@ namespace NMonitoring { /////////////////////////////////////////////////////////////////////////////// // IMetric /////////////////////////////////////////////////////////////////////////////// - class IMetric { + class IMetric : public TThrRefBase { public: virtual ~IMetric() = default; @@ -17,7 +17,7 @@ namespace NMonitoring { virtual void Accept(TInstant time, IMetricConsumer* consumer) const = 0; }; - using IMetricPtr = THolder<IMetric>; + using IMetricPtr = TIntrusivePtr<IMetric>; class IGauge: public IMetric { public: diff --git a/library/cpp/monlib/metrics/metric_registry.cpp b/library/cpp/monlib/metrics/metric_registry.cpp index 3d7ffd40cf..2c64a23ead 100644 --- a/library/cpp/monlib/metrics/metric_registry.cpp +++ b/library/cpp/monlib/metrics/metric_registry.cpp @@ -180,7 +180,7 @@ namespace NMonitoring { } { - IMetricPtr metric = MakeHolder<TMetric>(std::forward<Args>(args)...); + IMetricPtr metric = MakeIntrusive<TMetric>(std::forward<Args>(args)...); TWriteGuard g{*Lock_}; // decltype(Metrics_)::iterator breaks build on windows @@ -215,17 +215,24 @@ namespace NMonitoring { consumer->OnLabelsEnd(); } + TVector<std::pair<ILabelsPtr, IMetricPtr>> tmpMetrics; + { TReadGuard g{*Lock_}; + tmpMetrics.reserve(Metrics_.size()); for (const auto& it: Metrics_) { - ILabels* labels = it.first.Get(); - IMetric* metric = it.second.Get(); - ConsumeMetric(time, consumer, metric, [&]() { - ConsumeLabels(consumer, *labels); - }); + tmpMetrics.push_back(it); } } + for (const auto& it: tmpMetrics) { + ILabels* labels = it.first.Get(); + IMetric* metric = it.second.Get(); + ConsumeMetric(time, consumer, metric, [&]() { + ConsumeLabels(consumer, *labels); + }); + } + consumer->OnStreamEnd(); } |