diff options
author | ivanmorozov <ivanmorozov@yandex-team.com> | 2023-07-05 18:21:29 +0300 |
---|---|---|
committer | ivanmorozov <ivanmorozov@yandex-team.com> | 2023-07-05 18:21:29 +0300 |
commit | d5fc94311c69dd2566760a0f129b91d2411c2b3c (patch) | |
tree | 5e1c9baab68fedad02a5dc207df6e046a3316952 /library/cpp | |
parent | c2266c0415584094db8d6ba404b0dbfc74d57824 (diff) | |
download | ydb-d5fc94311c69dd2566760a0f129b91d2411c2b3c.tar.gz |
use profile tags for any method actor name generation
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/actors/core/actor.h | 21 | ||||
-rw-r--r-- | library/cpp/actors/core/actorsystem.cpp | 2 | ||||
-rw-r--r-- | library/cpp/actors/core/actorsystem.h | 4 | ||||
-rw-r--r-- | library/cpp/actors/core/executor_thread.cpp | 2 | ||||
-rw-r--r-- | library/cpp/actors/util/local_process_key.h | 67 |
5 files changed, 46 insertions, 50 deletions
diff --git a/library/cpp/actors/core/actor.h b/library/cpp/actors/core/actor.h index 32d9d0c6af..794369179f 100644 --- a/library/cpp/actors/core/actor.h +++ b/library/cpp/actors/core/actor.h @@ -11,6 +11,18 @@ #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; @@ -587,8 +599,6 @@ namespace NActors { } }; - struct TActorActivityTag {}; - inline size_t GetActivityTypeCount() { return TLocalProcessKeyState<TActorActivityTag>::GetInstance().GetCount(); } @@ -638,7 +648,7 @@ namespace NActors { template <typename T> struct HasActorActivityType<T, decltype((void)T::ActorActivityType, (const char*)nullptr)>: std::true_type {}; - static ui32 GetActivityTypeIndex() { + static ui32 GetActivityTypeIndexImpl() { if constexpr(HasActorName<TDerived>::value) { return TLocalProcessKey<TActorActivityTag, TDerived::ActorName>::GetIndex(); } else if constexpr (HasActorActivityType<TDerived>::value) { @@ -650,6 +660,11 @@ 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 81a2dd6446..9207e3407e 100644 --- a/library/cpp/actors/core/actorsystem.cpp +++ b/library/cpp/actors/core/actorsystem.cpp @@ -320,6 +320,4 @@ 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 0740c70b13..9cb8940223 100644 --- a/library/cpp/actors/core/actorsystem.h +++ b/library/cpp/actors/core/actorsystem.h @@ -309,9 +309,5 @@ 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 226108a9c8..2efbfd01f0 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(ActorSystem->MemProfActivityBase + activityType); + NProfiling::TMemoryTagScope::Reset(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 4d000db198..28fd590d37 100644 --- a/library/cpp/actors/util/local_process_key.h +++ b/library/cpp/actors/util/local_process_key.h @@ -1,11 +1,18 @@ #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 { @@ -22,59 +29,46 @@ public: return *Singleton<TLocalProcessKeyState<T>>(); } - size_t GetCount() const { - return StartIndex + Names.size(); + ui32 GetCount() const { + return MaxKeysCount; } TStringBuf GetNameByIndex(size_t index) const { - if (index < StartIndex) { - return StaticNames[index]; - } else { - index -= StartIndex; - Y_ENSURE(index < Names.size()); - return Names[index]; - } + Y_VERIFY(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) { - auto x = Map.emplace(name, Names.size()+StartIndex); + TGuard<TMutex> g(Mutex); + const ui32 index = TLocalProcessKeyStateIndexConstructor<T>::BuildCurrentIndex(name, Names.size()); + auto x = Map.emplace(name, index); if (x.second) { - Names.emplace_back(name); + Y_VERIFY(index < Names.size(), "a lot of actors or tags for memory monitoring"); + Names[index] = 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> @@ -127,9 +121,6 @@ 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]; } @@ -144,14 +135,10 @@ private: for (const auto& [k, v] : names) { maxId = Max(maxId, static_cast<ui32>(k)); } - enum2Index.resize(maxId+1); - for (ui32 i = 0; i <= maxId && i < TLocalProcessKeyState<T>::StartIndex; i++) { - enum2Index[i] = i; - } - + enum2Index.resize(maxId + 1); for (const auto& [k, v] : names) { ui32 enumId = static_cast<ui32>(k); - enum2Index[enumId] = TLocalProcessKeyState<T>::GetInstance().Register(v, enumId); + enum2Index[enumId] = TLocalProcessKeyState<T>::GetInstance().Register(v); } return enum2Index; } |