1+ #pragma once
2+
3+ #include " thread_context.h"
4+ #include " worker_context.h"
5+
6+ #include < ydb/library/actors/actor_type/common.h>
7+ #include < ydb/library/actors/actor_type/index_constructor.h>
8+ #include < ydb/library/actors/util/local_process_key.h>
9+
10+ namespace NActors {
11+
12+
13+ template <EInternalActorSystemActivity type>
14+ class TInternalActorTypeGuard {
15+ public:
16+ TInternalActorTypeGuard () {
17+ if (Enabled && TlsThreadContext) {
18+ NHPTimer::STime hpnow = GetCycleCountFast ();
19+ NHPTimer::STime hpprev = TlsThreadContext->UpdateStartOfProcessingEventTS (hpnow);
20+ NextIndex = TlsThreadContext->ElapsingActorActivity .exchange (Index, std::memory_order_acq_rel);
21+ TlsThreadContext->WorkerCtx ->AddElapsedCycles (NextIndex, hpnow - hpprev);
22+ }
23+ }
24+
25+ TInternalActorTypeGuard (ui32 nextIndex)
26+ : NextIndex(nextIndex)
27+ {
28+ if (Enabled && TlsThreadContext) {
29+ NHPTimer::STime hpnow = GetCycleCountFast ();
30+ NHPTimer::STime hpprev = TlsThreadContext->UpdateStartOfProcessingEventTS (hpnow);
31+ ui32 prevIndex = TlsThreadContext->ElapsingActorActivity .exchange (Index, std::memory_order_acq_rel);
32+ TlsThreadContext->WorkerCtx ->AddElapsedCycles (prevIndex, hpnow - hpprev);
33+ }
34+ }
35+
36+ TInternalActorTypeGuard (NHPTimer::STime hpnow) {
37+ if (Enabled && TlsThreadContext) {
38+ NHPTimer::STime hpprev = TlsThreadContext->UpdateStartOfProcessingEventTS (hpnow);
39+ NextIndex = TlsThreadContext->ElapsingActorActivity .exchange (Index, std::memory_order_acq_rel);
40+ TlsThreadContext->WorkerCtx ->AddElapsedCycles (NextIndex, hpnow - hpprev);
41+ }
42+ }
43+
44+ TInternalActorTypeGuard (NHPTimer::STime hpnow, ui32 nextIndex)
45+ : NextIndex(nextIndex)
46+ {
47+ if (Enabled && TlsThreadContext) {
48+ NHPTimer::STime hpprev = TlsThreadContext->UpdateStartOfProcessingEventTS (hpnow);
49+ ui32 prevIndex = TlsThreadContext->ElapsingActorActivity .exchange (Index, std::memory_order_acq_rel);
50+ TlsThreadContext->WorkerCtx ->AddElapsedCycles (prevIndex, hpnow - hpprev);
51+ }
52+ }
53+
54+ ~TInternalActorTypeGuard () {
55+ if (Enabled && TlsThreadContext) {
56+ NHPTimer::STime hpnow = GetCycleCountFast ();
57+ NHPTimer::STime hpprev = TlsThreadContext->UpdateStartOfProcessingEventTS (hpnow);
58+ TlsThreadContext->ElapsingActorActivity .store (NextIndex, std::memory_order_release);
59+ TlsThreadContext->WorkerCtx ->AddElapsedCycles (Index, hpnow - hpprev);
60+ }
61+ }
62+
63+
64+ private:
65+ static constexpr bool Enabled = false ;
66+ static ui32 Index;
67+ ui32 NextIndex = 0 ;
68+ };
69+
70+ template <EInternalActorSystemActivity type>
71+ ui32 TInternalActorTypeGuard<type>::Index = TEnumProcessKey<TActorActivityTag, EInternalActorSystemActivity>::GetIndex(type);
72+
73+ }
0 commit comments