@@ -199,16 +199,16 @@ namespace NActors {
199199 bool firstEvent = true ;
200200 bool preempted = false ;
201201 bool wasWorking = false ;
202- NHPTimer::STime hpnow = Ctx.HPStart ;
203- NHPTimer::STime hpprev = TlsThreadContext->StartOfElapsingTime . exchange (hpnow, std::memory_order_acq_rel );
202+ NHPTimer::STime hpnow = Ctx.HPStart ;
203+ NHPTimer::STime hpprev = TlsThreadContext->UpdateStartOfElapsingTime (hpnow);
204204 Ctx.AddElapsedCycles (ActorSystemIndex, hpnow - hpprev);
205- hpprev = Ctx.HPStart ;
205+ NHPTimer::STime eventStart = Ctx.HPStart ;
206206
207207 for (; Ctx.ExecutedEvents < Ctx.EventsPerMailbox ; ++Ctx.ExecutedEvents ) {
208208 if (TAutoPtr<IEventHandle> evExt = mailbox->Pop ()) {
209209 mailbox->ProcessEvents (mailbox);
210210 recipient = evExt->GetRecipientRewrite ();
211- TActorContext ctx (*mailbox, *this , hpprev , recipient);
211+ TActorContext ctx (*mailbox, *this , eventStart , recipient);
212212 TlsActivationContext = &ctx; // ensure dtor (if any) is called within actor system
213213 // move for destruct before ctx;
214214 auto ev = std::move (evExt);
@@ -250,7 +250,7 @@ namespace NActors {
250250 actor->Receive (ev);
251251
252252 hpnow = GetCycleCountFast ();
253- hpprev = TlsThreadContext->StartOfElapsingTime . exchange (hpnow, std::memory_order_acq_rel );
253+ hpprev = TlsThreadContext->UpdateStartOfElapsingTime (hpnow);
254254
255255 mailbox->ProcessEvents (mailbox);
256256 actor->OnDequeueEvent ();
@@ -266,7 +266,10 @@ namespace NActors {
266266 if (mailbox->IsEmpty ()) // was not-free and become free, we must reclaim mailbox
267267 reclaimAsFree = true ;
268268
269- NHPTimer::STime elapsed = Ctx.AddEventProcessingStats (hpprev, hpnow, activityType, CurrentActorScheduledEventsCounter);
269+
270+ Ctx.AddElapsedCycles (activityType, hpnow - hpprev);
271+ Ctx.AddEventProcessingStats (eventStart, hpnow, activityType, CurrentActorScheduledEventsCounter);
272+ NHPTimer::STime elapsed = hpnow - eventStart;
270273 if (elapsed > 1000000 ) {
271274 LwTraceSlowEvent (ev.Get (), evTypeForTracing, actorType, Ctx.PoolId , CurrentRecipient, NHPTimer::GetSeconds (elapsed) * 1000.0 );
272275 }
@@ -286,9 +289,10 @@ namespace NActors {
286289 Ctx.IncrementNonDeliveredEvents ();
287290 }
288291 hpnow = GetCycleCountFast ();
289- hpprev = TlsThreadContext->StartOfElapsingTime . exchange (hpnow, std::memory_order_acq_rel );
292+ hpprev = TlsThreadContext->UpdateStartOfElapsingTime (hpnow);
290293 Ctx.AddElapsedCycles (ActorSystemIndex, hpnow - hpprev);
291294 }
295+ eventStart = hpnow;
292296
293297 if (TlsThreadContext->CapturedType == ESendingType::Tail) {
294298 AtomicStore (&mailbox->ScheduleMoment , hpnow);
@@ -777,7 +781,7 @@ namespace NActors {
777781 void TGenericExecutorThread::GetCurrentStats (TExecutorThreadStats& statsCopy) const {
778782 NHPTimer::STime hpnow = GetCycleCountFast ();
779783 ui64 activityType = TlsThreadCtx.ElapsingActorActivity .load (std::memory_order_acquire);
780- NHPTimer::STime hpprev = TlsThreadCtx.StartOfElapsingTime . exchange (hpnow, std::memory_order_acq_rel );
784+ NHPTimer::STime hpprev = TlsThreadCtx.UpdateStartOfElapsingTime (hpnow);
781785 if (activityType == Max<ui64>()) {
782786 Ctx.AddParkedCycles (hpnow - hpprev);
783787 } else {
@@ -789,7 +793,7 @@ namespace NActors {
789793 void TGenericExecutorThread::GetSharedStats (i16 poolId, TExecutorThreadStats &statsCopy) const {
790794 NHPTimer::STime hpnow = GetCycleCountFast ();
791795 ui64 activityType = TlsThreadCtx.ElapsingActorActivity .load (std::memory_order_acquire);
792- NHPTimer::STime hpprev = TlsThreadCtx.StartOfElapsingTime . exchange (hpnow, std::memory_order_acq_rel );
796+ NHPTimer::STime hpprev = TlsThreadCtx.UpdateStartOfElapsingTime (hpnow);
793797 if (activityType == Max<ui64>()) {
794798 Ctx.AddParkedCycles (hpnow - hpprev);
795799 } else {
0 commit comments