@@ -48,6 +48,7 @@ namespace NActors {
48
48
, ThreadName (threadName)
49
49
, TimePerMailbox (timePerMailbox)
50
50
, EventsPerMailbox (eventsPerMailbox)
51
+ , ActorSystemIndex (TActorTypeOperator::GetActorSystemIndex ())
51
52
{
52
53
Ctx.Switch (
53
54
ExecutorPool,
@@ -75,6 +76,7 @@ namespace NActors {
75
76
, EventsPerMailbox (eventsPerMailbox)
76
77
, SoftProcessingDurationTs (softProcessingDurationTs)
77
78
, SharedStats (poolCount)
79
+ , ActorSystemIndex (TActorTypeOperator::GetActorSystemIndex ())
78
80
{
79
81
Ctx.Switch (
80
82
ExecutorPool,
@@ -239,9 +241,14 @@ namespace NActors {
239
241
if (activityType != prevActivityType) {
240
242
prevActivityType = activityType;
241
243
NProfiling::TMemoryTagScope::Reset (activityType);
244
+ TlsThreadContext->ElapsingActorActivity .store (activityType, std::memory_order_release);
242
245
}
243
246
244
247
actor->Receive (ev);
248
+
249
+ hpnow = GetCycleCountFast ();
250
+ hpprev = TlsThreadContext->StartOfElapsingTime .exchange (hpnow, std::memory_order_acq_rel);
251
+
245
252
mailbox->ProcessEvents (mailbox);
246
253
actor->OnDequeueEvent ();
247
254
@@ -256,7 +263,6 @@ namespace NActors {
256
263
if (mailbox->IsEmpty ()) // was not-free and become free, we must reclaim mailbox
257
264
reclaimAsFree = true ;
258
265
259
- hpnow = GetCycleCountFast ();
260
266
NHPTimer::STime elapsed = Ctx.AddEventProcessingStats (hpprev, hpnow, activityType, CurrentActorScheduledEventsCounter);
261
267
if (elapsed > 1000000 ) {
262
268
LwTraceSlowEvent (ev.Get (), evTypeForTracing, actorType, Ctx.PoolId , CurrentRecipient, NHPTimer::GetSeconds (elapsed) * 1000.0 );
@@ -277,10 +283,10 @@ namespace NActors {
277
283
Ctx.IncrementNonDeliveredEvents ();
278
284
}
279
285
hpnow = GetCycleCountFast ();
286
+ hpprev = TlsThreadContext->StartOfElapsingTime .exchange (hpnow, std::memory_order_acq_rel);
287
+ Ctx.AddElapsedCycles (ActorSystemIndex, hpnow - hpprev);
280
288
}
281
289
282
- hpprev = hpnow;
283
-
284
290
if (TlsThreadContext->CapturedType == ESendingType::Tail) {
285
291
AtomicStore (&mailbox->ScheduleMoment , hpnow);
286
292
Ctx.IncrementMailboxPushedOutByTailSending ();
@@ -360,6 +366,7 @@ namespace NActors {
360
366
break ; // empty queue, leave
361
367
}
362
368
}
369
+ TlsThreadContext->ElapsingActorActivity .store (ActorSystemIndex, std::memory_order_release);
363
370
364
371
NProfiling::TMemoryTagScope::Reset (0 );
365
372
TlsActivationContext = nullptr ;
@@ -495,8 +502,11 @@ namespace NActors {
495
502
ThreadDisableBalloc ();
496
503
#endif
497
504
498
- TThreadContext threadCtx;
499
- TlsThreadContext = &threadCtx;
505
+ TlsThreadCtx.WorkerCtx = &Ctx;
506
+ TlsThreadCtx.ActorSystemIndex = ActorSystemIndex;
507
+ TlsThreadCtx.ElapsingActorActivity = ActorSystemIndex;
508
+ TlsThreadCtx.StartOfElapsingTime = GetCycleCountFast ();
509
+ TlsThreadContext = &TlsThreadCtx;
500
510
if (ThreadName) {
501
511
::SetCurrentThreadName (ThreadName);
502
512
}
@@ -529,8 +539,11 @@ namespace NActors {
529
539
ThreadDisableBalloc ();
530
540
#endif
531
541
532
- TThreadContext threadCtx;
533
- TlsThreadContext = &threadCtx;
542
+ TlsThreadCtx.WorkerCtx = &Ctx;
543
+ TlsThreadCtx.ActorSystemIndex = ActorSystemIndex;
544
+ TlsThreadCtx.ElapsingActorActivity = ActorSystemIndex;
545
+ TlsThreadCtx.StartOfElapsingTime = GetCycleCountFast ();
546
+ TlsThreadContext = &TlsThreadCtx;
534
547
if (ThreadName) {
535
548
::SetCurrentThreadName (ThreadName);
536
549
}
@@ -551,7 +564,7 @@ namespace NActors {
551
564
}
552
565
553
566
if (!wasWorking && !StopFlag.load (std::memory_order_relaxed)) {
554
- TlsThreadContext-> Timers . Reset ();
567
+ ThreadCtx-> UnsetWork ();
555
568
ThreadCtx->Wait (0 , &StopFlag);
556
569
}
557
570
@@ -760,10 +773,26 @@ namespace NActors {
760
773
}
761
774
762
775
void TGenericExecutorThread::GetCurrentStats (TExecutorThreadStats& statsCopy) const {
776
+ NHPTimer::STime hpnow = GetCycleCountFast ();
777
+ ui64 activityType = TlsThreadCtx.ElapsingActorActivity .load (std::memory_order_acquire);
778
+ NHPTimer::STime hpprev = TlsThreadCtx.StartOfElapsingTime .exchange (hpnow, std::memory_order_acq_rel);
779
+ if (activityType == Max<ui64>()) {
780
+ Ctx.AddParkedCycles (hpnow - hpprev);
781
+ } else {
782
+ Ctx.AddElapsedCycles (activityType, hpnow - hpprev);
783
+ }
763
784
Ctx.GetCurrentStats (statsCopy);
764
785
}
765
786
766
787
void TGenericExecutorThread::GetSharedStats (i16 poolId, TExecutorThreadStats &statsCopy) const {
788
+ NHPTimer::STime hpnow = GetCycleCountFast ();
789
+ ui64 activityType = TlsThreadCtx.ElapsingActorActivity .load (std::memory_order_acquire);
790
+ NHPTimer::STime hpprev = TlsThreadCtx.StartOfElapsingTime .exchange (hpnow, std::memory_order_acq_rel);
791
+ if (activityType == Max<ui64>()) {
792
+ Ctx.AddParkedCycles (hpnow - hpprev);
793
+ } else {
794
+ Ctx.AddElapsedCycles (activityType, hpnow - hpprev);
795
+ }
767
796
statsCopy = TExecutorThreadStats ();
768
797
statsCopy.Aggregate (SharedStats[poolId]);
769
798
}
0 commit comments