aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.com>2023-07-05 18:44:16 +0300
committerivanmorozov <ivanmorozov@yandex-team.com>2023-07-05 18:44:16 +0300
commit003a5eca9b0eb9003f2e7e51a1d0626177327534 (patch)
tree37feb8a49063aff463999d196c46d77ed4f72c17 /library/cpp
parent586b53c49dc7b17dc97b2110528f81ec4e081438 (diff)
downloadydb-003a5eca9b0eb9003f2e7e51a1d0626177327534.tar.gz
Revert commit rXXXXXX,use profile tags for any method actor name generation
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/actors/core/actor.h21
-rw-r--r--library/cpp/actors/core/actorsystem.cpp2
-rw-r--r--library/cpp/actors/core/actorsystem.h4
-rw-r--r--library/cpp/actors/core/executor_thread.cpp2
-rw-r--r--library/cpp/actors/util/local_process_key.h67
5 files changed, 50 insertions, 46 deletions
diff --git a/library/cpp/actors/core/actor.h b/library/cpp/actors/core/actor.h
index 794369179f4..32d9d0c6aff 100644
--- a/library/cpp/actors/core/actor.h
+++ b/library/cpp/actors/core/actor.h
@@ -11,18 +11,6 @@
#include <util/generic/noncopyable.h>
namespace NActors {
-struct TActorActivityTag {};
-}
-
-template <>
-class TLocalProcessKeyStateIndexConstructor<NActors::TActorActivityTag> {
-public:
- static ui32 BuildCurrentIndex(const TStringBuf name, const ui32 /*currentNamesCount*/) {
- return NProfiling::MakeTag(name.data());
- }
-};
-
-namespace NActors {
class TActorSystem;
class TMailboxTable;
struct TMailboxHeader;
@@ -599,6 +587,8 @@ namespace NActors {
}
};
+ struct TActorActivityTag {};
+
inline size_t GetActivityTypeCount() {
return TLocalProcessKeyState<TActorActivityTag>::GetInstance().GetCount();
}
@@ -648,7 +638,7 @@ namespace NActors {
template <typename T>
struct HasActorActivityType<T, decltype((void)T::ActorActivityType, (const char*)nullptr)>: std::true_type {};
- static ui32 GetActivityTypeIndexImpl() {
+ static ui32 GetActivityTypeIndex() {
if constexpr(HasActorName<TDerived>::value) {
return TLocalProcessKey<TActorActivityTag, TDerived::ActorName>::GetIndex();
} else if constexpr (HasActorActivityType<TDerived>::value) {
@@ -660,11 +650,6 @@ namespace NActors {
}
}
- static ui32 GetActivityTypeIndex() {
- static const ui32 result = GetActivityTypeIndexImpl();
- return result;
- }
-
protected:
// static constexpr char ActorName[] = "UNNAMED";
diff --git a/library/cpp/actors/core/actorsystem.cpp b/library/cpp/actors/core/actorsystem.cpp
index 9207e3407e2..81a2dd6446e 100644
--- a/library/cpp/actors/core/actorsystem.cpp
+++ b/library/cpp/actors/core/actorsystem.cpp
@@ -320,4 +320,6 @@ namespace NActors {
CpuManager->Cleanup();
Scheduler.Destroy();
}
+
+ ui32 TActorSystem::MemProfActivityBase;
}
diff --git a/library/cpp/actors/core/actorsystem.h b/library/cpp/actors/core/actorsystem.h
index 9cb8940223d..0740c70b137 100644
--- a/library/cpp/actors/core/actorsystem.h
+++ b/library/cpp/actors/core/actorsystem.h
@@ -309,5 +309,9 @@ namespace NActors {
DeferredPreStop.push_back(std::move(fn));
}
+ /* This is the base for memory profiling tags.
+ System sets memory profiling tag for debug version of lfalloc.
+ The tag is set as "base_tag + actor_activity_type". */
+ static ui32 MemProfActivityBase;
};
}
diff --git a/library/cpp/actors/core/executor_thread.cpp b/library/cpp/actors/core/executor_thread.cpp
index 2efbfd01f09..226108a9c8b 100644
--- a/library/cpp/actors/core/executor_thread.cpp
+++ b/library/cpp/actors/core/executor_thread.cpp
@@ -190,7 +190,7 @@ namespace NActors {
ui32 activityType = actor->GetActivityType();
if (activityType != prevActivityType) {
prevActivityType = activityType;
- NProfiling::TMemoryTagScope::Reset(activityType);
+ NProfiling::TMemoryTagScope::Reset(ActorSystem->MemProfActivityBase + activityType);
}
actor->Receive(ev);
diff --git a/library/cpp/actors/util/local_process_key.h b/library/cpp/actors/util/local_process_key.h
index 28fd590d379..4d000db1980 100644
--- a/library/cpp/actors/util/local_process_key.h
+++ b/library/cpp/actors/util/local_process_key.h
@@ -1,18 +1,11 @@
#pragma once
#include <util/string/builder.h>
-#include <util/system/mutex.h>
#include <util/generic/strbuf.h>
#include <util/generic/vector.h>
#include <util/generic/hash.h>
#include <util/generic/singleton.h>
#include <util/generic/serialized_enum.h>
-#include <library/cpp/actors/prof/tag.h>
-
-template <class T>
-class TLocalProcessKeyStateIndexConstructor {
-public:
-};
template <typename T>
class TLocalProcessKeyState {
@@ -29,46 +22,59 @@ public:
return *Singleton<TLocalProcessKeyState<T>>();
}
- ui32 GetCount() const {
- return MaxKeysCount;
+ size_t GetCount() const {
+ return StartIndex + Names.size();
}
TStringBuf GetNameByIndex(size_t index) const {
- Y_VERIFY(index < Names.size());
- return Names[index];
+ if (index < StartIndex) {
+ return StaticNames[index];
+ } else {
+ index -= StartIndex;
+ Y_ENSURE(index < Names.size());
+ return Names[index];
+ }
}
size_t GetIndexByName(TStringBuf name) const {
- TGuard<TMutex> g(Mutex);
auto it = Map.find(name);
Y_ENSURE(it != Map.end());
return it->second;
}
- TLocalProcessKeyState() {
- Names.resize(MaxKeysCount);
- }
-
private:
-
- static constexpr ui32 MaxKeysCount = 1000000;
-
size_t Register(TStringBuf name) {
- TGuard<TMutex> g(Mutex);
- const ui32 index = TLocalProcessKeyStateIndexConstructor<T>::BuildCurrentIndex(name, Names.size());
- auto x = Map.emplace(name, index);
+ auto x = Map.emplace(name, Names.size()+StartIndex);
if (x.second) {
- Y_VERIFY(index < Names.size(), "a lot of actors or tags for memory monitoring");
- Names[index] = name;
+ Names.emplace_back(name);
}
return x.first->second;
}
+ size_t Register(TStringBuf name, ui32 index) {
+ Y_VERIFY(index < StartIndex);
+ auto x = Map.emplace(name, index);
+ Y_VERIFY(x.second || x.first->second == index);
+ StaticNames[index] = name;
+ return x.first->second;
+ }
+
private:
+ static constexpr ui32 StartIndex = 2000;
+
+ TVector<TString> FillStaticNames() {
+ TVector<TString> staticNames;
+ staticNames.reserve(StartIndex);
+ for (ui32 i = 0; i < StartIndex; i++) {
+ staticNames.push_back(TStringBuilder() << "Activity_" << i);
+ }
+ return staticNames;
+ }
+
+ TVector<TString> StaticNames = FillStaticNames();
TVector<TString> Names;
THashMap<TString, size_t> Map;
- TMutex Mutex;
};
template <typename T, const char* Name>
@@ -121,6 +127,9 @@ public:
static size_t GetIndex(EnumT key) {
ui32 index = static_cast<ui32>(key);
+ if (index < TLocalProcessKeyState<T>::StartIndex) {
+ return index;
+ }
Y_VERIFY(index < Enum2Index.size());
return Enum2Index[index];
}
@@ -135,10 +144,14 @@ private:
for (const auto& [k, v] : names) {
maxId = Max(maxId, static_cast<ui32>(k));
}
- enum2Index.resize(maxId + 1);
+ enum2Index.resize(maxId+1);
+ for (ui32 i = 0; i <= maxId && i < TLocalProcessKeyState<T>::StartIndex; i++) {
+ enum2Index[i] = i;
+ }
+
for (const auto& [k, v] : names) {
ui32 enumId = static_cast<ui32>(k);
- enum2Index[enumId] = TLocalProcessKeyState<T>::GetInstance().Register(v);
+ enum2Index[enumId] = TLocalProcessKeyState<T>::GetInstance().Register(v, enumId);
}
return enum2Index;
}