aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/dynamic_counters/counters.cpp
diff options
context:
space:
mode:
authorAlexander Rutkovsky <alexvru@mail.ru>2022-02-10 16:47:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:39 +0300
commitf3646f91e0de459836a7800b9ce3e8dc57a2ab3a (patch)
tree25c1423200152570c1f8307e5b8304b9bc3840c5 /library/cpp/monlib/dynamic_counters/counters.cpp
parentfccc62e9bfdce9be2fe7e0f23479da3a5512211a (diff)
downloadydb-f3646f91e0de459836a7800b9ce3e8dc57a2ab3a.tar.gz
Restoring authorship annotation for Alexander Rutkovsky <alexvru@mail.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/monlib/dynamic_counters/counters.cpp')
-rw-r--r--library/cpp/monlib/dynamic_counters/counters.cpp152
1 files changed, 76 insertions, 76 deletions
diff --git a/library/cpp/monlib/dynamic_counters/counters.cpp b/library/cpp/monlib/dynamic_counters/counters.cpp
index 3635d87d0d..04003d28a5 100644
--- a/library/cpp/monlib/dynamic_counters/counters.cpp
+++ b/library/cpp/monlib/dynamic_counters/counters.cpp
@@ -107,66 +107,66 @@ void TDynamicCounters::RemoveCounter(const TString &value) {
}
void TDynamicCounters::RemoveNamedCounter(const TString& name, const TString &value) {
- auto g = LockForUpdate("RemoveNamedCounter", name, value);
- if (const auto it = Counters.find({name, value}); it != Counters.end() && AsCounter(it->second)) {
+ auto g = LockForUpdate("RemoveNamedCounter", name, value);
+ if (const auto it = Counters.find({name, value}); it != Counters.end() && AsCounter(it->second)) {
Counters.erase(it);
}
}
TIntrusivePtr<TDynamicCounters> TDynamicCounters::GetSubgroup(const TString& name, const TString& value) {
- auto res = FindSubgroup(name, value);
- if (!res) {
- auto g = LockForUpdate("GetSubgroup", name, value);
- const TChildId key(name, value);
- if (const auto it = Counters.lower_bound(key); it != Counters.end() && it->first == key) {
- res = AsGroupRef(it->second);
- } else {
- res = MakeIntrusive<TDynamicCounters>(this);
- Counters.emplace_hint(it, key, res);
- }
+ auto res = FindSubgroup(name, value);
+ if (!res) {
+ auto g = LockForUpdate("GetSubgroup", name, value);
+ const TChildId key(name, value);
+ if (const auto it = Counters.lower_bound(key); it != Counters.end() && it->first == key) {
+ res = AsGroupRef(it->second);
+ } else {
+ res = MakeIntrusive<TDynamicCounters>(this);
+ Counters.emplace_hint(it, key, res);
+ }
}
- return res;
+ return res;
}
TIntrusivePtr<TDynamicCounters> TDynamicCounters::FindSubgroup(const TString& name, const TString& value) const {
- TReadGuard g(Lock);
- const auto it = Counters.find({name, value});
- return it != Counters.end() ? AsDynamicCounters(it->second) : nullptr;
+ TReadGuard g(Lock);
+ const auto it = Counters.find({name, value});
+ return it != Counters.end() ? AsDynamicCounters(it->second) : nullptr;
}
void TDynamicCounters::RemoveSubgroup(const TString& name, const TString& value) {
- auto g = LockForUpdate("RemoveSubgroup", name, value);
- if (const auto it = Counters.find({name, value}); it != Counters.end() && AsDynamicCounters(it->second)) {
+ auto g = LockForUpdate("RemoveSubgroup", name, value);
+ if (const auto it = Counters.find({name, value}); it != Counters.end() && AsDynamicCounters(it->second)) {
Counters.erase(it);
}
}
-void TDynamicCounters::ReplaceSubgroup(const TString& name, const TString& value, TIntrusivePtr<TDynamicCounters> subgroup) {
- auto g = LockForUpdate("ReplaceSubgroup", name, value);
- const auto it = Counters.find({name, value});
- Y_VERIFY(it != Counters.end() && AsDynamicCounters(it->second));
- it->second = std::move(subgroup);
+void TDynamicCounters::ReplaceSubgroup(const TString& name, const TString& value, TIntrusivePtr<TDynamicCounters> subgroup) {
+ auto g = LockForUpdate("ReplaceSubgroup", name, value);
+ const auto it = Counters.find({name, value});
+ Y_VERIFY(it != Counters.end() && AsDynamicCounters(it->second));
+ it->second = std::move(subgroup);
}
void TDynamicCounters::MergeWithSubgroup(const TString& name, const TString& value) {
- auto g = LockForUpdate("MergeWithSubgroup", name, value);
- auto it = Counters.find({name, value});
- Y_VERIFY(it != Counters.end());
- TIntrusivePtr<TDynamicCounters> subgroup = AsDynamicCounters(it->second);
+ auto g = LockForUpdate("MergeWithSubgroup", name, value);
+ auto it = Counters.find({name, value});
+ Y_VERIFY(it != Counters.end());
+ TIntrusivePtr<TDynamicCounters> subgroup = AsDynamicCounters(it->second);
Y_VERIFY(subgroup);
- Counters.erase(it);
- Counters.merge(subgroup->Resign());
- AtomicAdd(ExpiringCount, AtomicSwap(&subgroup->ExpiringCount, 0));
+ Counters.erase(it);
+ Counters.merge(subgroup->Resign());
+ AtomicAdd(ExpiringCount, AtomicSwap(&subgroup->ExpiringCount, 0));
}
void TDynamicCounters::ResetCounters(bool derivOnly) {
- TReadGuard g(Lock);
- for (auto& [key, value] : Counters) {
- if (auto counter = AsCounter(value)) {
- if (!derivOnly || counter->ForDerivative()) {
+ TReadGuard g(Lock);
+ for (auto& [key, value] : Counters) {
+ if (auto counter = AsCounter(value)) {
+ if (!derivOnly || counter->ForDerivative()) {
*counter = 0;
- }
- } else if (auto subgroup = AsDynamicCounters(value)) {
+ }
+ } else if (auto subgroup = AsDynamicCounters(value)) {
subgroup->ResetCounters(derivOnly);
}
}
@@ -174,9 +174,9 @@ void TDynamicCounters::ResetCounters(bool derivOnly) {
void TDynamicCounters::RegisterCountable(const TString& name, const TString& value, TCountablePtr countable) {
Y_VERIFY(countable);
- auto g = LockForUpdate("RegisterCountable", name, value);
- const bool inserted = Counters.emplace(TChildId(name, value), std::move(countable)).second;
- Y_VERIFY(inserted);
+ auto g = LockForUpdate("RegisterCountable", name, value);
+ const bool inserted = Counters.emplace(TChildId(name, value), std::move(countable)).second;
+ Y_VERIFY(inserted);
}
void TDynamicCounters::RegisterSubgroup(const TString& name, const TString& value, TIntrusivePtr<TDynamicCounters> subgroup) {
@@ -192,31 +192,31 @@ void TDynamicCounters::OutputHtml(IOutputStream& os) const {
}
void TDynamicCounters::EnumerateSubgroups(const std::function<void(const TString& name, const TString& value)>& output) const {
- TReadGuard g(Lock);
- for (const auto& [key, value] : Counters) {
- if (AsDynamicCounters(value)) {
- output(key.LabelName, key.LabelValue);
- }
- }
+ TReadGuard g(Lock);
+ for (const auto& [key, value] : Counters) {
+ if (AsDynamicCounters(value)) {
+ output(key.LabelName, key.LabelValue);
+ }
+ }
}
void TDynamicCounters::OutputPlainText(IOutputStream& os, const TString& indent) const {
- auto snap = ReadSnapshot();
+ auto snap = ReadSnapshot();
// mark private records in plain text output
auto outputVisibilityMarker = [] (EVisibility vis) {
return vis == EVisibility::Private ? "\t[PRIVATE]" : "";
};
- for (const auto& [key, value] : snap) {
- if (const auto counter = AsCounter(value)) {
+ for (const auto& [key, value] : snap) {
+ if (const auto counter = AsCounter(value)) {
os << indent
- << key.LabelName << '=' << key.LabelValue
+ << key.LabelName << '=' << key.LabelValue
<< ": " << counter->Val()
<< outputVisibilityMarker(counter->Visibility())
<< '\n';
- } else if (const auto histogram = AsHistogram(value)) {
+ } else if (const auto histogram = AsHistogram(value)) {
os << indent
- << key.LabelName << '=' << key.LabelValue
+ << key.LabelName << '=' << key.LabelValue
<< ":"
<< outputVisibilityMarker(histogram->Visibility())
<< "\n";
@@ -235,10 +235,10 @@ void TDynamicCounters::OutputPlainText(IOutputStream& os, const TString& indent)
}
}
- for (const auto& [key, value] : snap) {
- if (const auto subgroup = AsDynamicCounters(value)) {
+ for (const auto& [key, value] : snap) {
+ if (const auto subgroup = AsDynamicCounters(value)) {
os << "\n";
- os << indent << key.LabelName << "=" << key.LabelValue << ":\n";
+ os << indent << key.LabelName << "=" << key.LabelValue << ":\n";
subgroup->OutputPlainText(os, indent + INDENT);
}
}
@@ -250,50 +250,50 @@ void TDynamicCounters::Accept(const TString& labelName, const TString& labelValu
}
consumer.OnGroupBegin(labelName, labelValue, this);
- for (auto& [key, value] : ReadSnapshot()) {
- value->Accept(key.LabelName, key.LabelValue, consumer);
+ for (auto& [key, value] : ReadSnapshot()) {
+ value->Accept(key.LabelName, key.LabelValue, consumer);
}
consumer.OnGroupEnd(labelName, labelValue, this);
}
void TDynamicCounters::RemoveExpired() const {
- if (AtomicGet(ExpiringCount) == 0) {
+ if (AtomicGet(ExpiringCount) == 0) {
return;
}
- TWriteGuard g(Lock);
- TAtomicBase count = 0;
-
+ TWriteGuard g(Lock);
+ TAtomicBase count = 0;
+
for (auto it = Counters.begin(); it != Counters.end();) {
if (IsExpiringCounter(it->second) && it->second->RefCount() == 1) {
it = Counters.erase(it);
- ++count;
+ ++count;
} else {
++it;
}
}
-
- AtomicSub(ExpiringCount, count);
+
+ AtomicSub(ExpiringCount, count);
}
template <bool expiring, class TCounterType, class... TArgs>
TDynamicCounters::TCountablePtr TDynamicCounters::GetNamedCounterImpl(const TString& name, const TString& value, TArgs&&... args) {
- {
- TReadGuard g(Lock);
- auto it = Counters.find({name, value});
- if (it != Counters.end()) {
- return it->second;
- }
+ {
+ TReadGuard g(Lock);
+ auto it = Counters.find({name, value});
+ if (it != Counters.end()) {
+ return it->second;
+ }
}
- auto g = LockForUpdate("GetNamedCounterImpl", name, value);
- const TChildId key(name, value);
- auto it = Counters.lower_bound(key);
- if (it == Counters.end() || it->first != key) {
- auto value = MakeIntrusive<TCounterType>(std::forward<TArgs>(args)...);
- it = Counters.emplace_hint(it, key, value);
+ auto g = LockForUpdate("GetNamedCounterImpl", name, value);
+ const TChildId key(name, value);
+ auto it = Counters.lower_bound(key);
+ if (it == Counters.end() || it->first != key) {
+ auto value = MakeIntrusive<TCounterType>(std::forward<TArgs>(args)...);
+ it = Counters.emplace_hint(it, key, value);
if constexpr (expiring) {
- AtomicIncrement(ExpiringCount);
+ AtomicIncrement(ExpiringCount);
}
}
return it->second;