diff options
author | Innokentii Mokin <innokentii@ydb.tech> | 2024-12-20 13:44:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-20 13:44:39 +0300 |
commit | f036a6c4feca5e538af0738c977b8620162051a9 (patch) | |
tree | 7e7f3a04591ecd31de960c6273c3fa0d0203891d | |
parent | 114915e078e620984c80a8e8797da11cc0a4fc1b (diff) | |
download | ydb-f036a6c4feca5e538af0738c977b8620162051a9.tar.gz |
Add event tracing capabilities in debugging (#12801)
-rw-r--r-- | ydb/library/actors/core/actor.h | 5 | ||||
-rw-r--r-- | ydb/library/actors/core/event.cpp | 6 | ||||
-rw-r--r-- | ydb/library/actors/core/event.h | 33 |
3 files changed, 40 insertions, 4 deletions
diff --git a/ydb/library/actors/core/actor.h b/ydb/library/actors/core/actor.h index c07403dbb48..55bff683c14 100644 --- a/ydb/library/actors/core/actor.h +++ b/ydb/library/actors/core/actor.h @@ -537,6 +537,11 @@ namespace NActors { } void Receive(TAutoPtr<IEventHandle>& ev) { +#ifndef NDEBUG + if (ev->Flags & IEventHandle::FlagDebugTrackReceive) { + YaDebugBreak(); + } +#endif ++HandledEvents; LastReceiveTimestamp = TActivationContext::Monotonic(); if (CImpl.Initialized()) { diff --git a/ydb/library/actors/core/event.cpp b/ydb/library/actors/core/event.cpp index 762e67e0594..8b8584e0019 100644 --- a/ydb/library/actors/core/event.cpp +++ b/ydb/library/actors/core/event.cpp @@ -60,4 +60,10 @@ namespace NActors { return DoExecute(actor, std::move(eventPtr)); } +#ifndef NDEBUG + void IEventHandle::DoTrackNextEvent() { + TrackNextEvent = true; + } +#endif + } diff --git a/ydb/library/actors/core/event.h b/ydb/library/actors/core/event.h index 63286133b30..4bcc3b4311e 100644 --- a/ydb/library/actors/core/event.h +++ b/ydb/library/actors/core/event.h @@ -13,7 +13,7 @@ namespace NActors { class TChunkSerializer; class IActor; - + class IEventBase : TNonCopyable { protected: @@ -122,6 +122,7 @@ namespace NActors { FlagUseSubChannel = 1 << 3, FlagGenerateUnsureUndelivered = 1 << 4, FlagExtendedFormat = 1 << 5, + FlagDebugTrackReceive = 1 << 6, }; using TEventFlags = ui32; @@ -194,10 +195,34 @@ namespace NActors { return OnNondeliveryHolder.Get() ? OnNondeliveryHolder->Recipient : TActorId(); } +#ifndef NDEBUG + static inline thread_local bool TrackNextEvent = false; + + /** + * Call this function in gdb before + * sending the event you want to debug + * and continue execution. __builtin_debugtrap/SIGTRAP + * will stop gdb at the receiving point. + * Currently, to get to Handle function you + * also need to ascend couple frames (up, up) and step to + * function you are searching for + */ + static void DoTrackNextEvent(); + + static TEventFlags ApplyGlobals(TEventFlags flags) { + bool trackNextEvent = std::exchange(TrackNextEvent, false); + return flags | (trackNextEvent ? FlagDebugTrackReceive : 0); + } +#else + Y_FORCE_INLINE static TEventFlags ApplyGlobals(TEventFlags flags) { + return flags; + } +#endif + IEventHandle(const TActorId& recipient, const TActorId& sender, IEventBase* ev, TEventFlags flags = 0, ui64 cookie = 0, const TActorId* forwardOnNondelivery = nullptr, NWilson::TTraceId traceId = {}) : Type(ev->Type()) - , Flags(flags) + , Flags(ApplyGlobals(flags)) , Recipient(recipient) , Sender(sender) , Cookie(cookie) @@ -222,7 +247,7 @@ namespace NActors { const TActorId* forwardOnNondelivery = nullptr, NWilson::TTraceId traceId = {}) : Type(type) - , Flags(flags) + , Flags(ApplyGlobals(flags)) , Recipient(recipient) , Sender(sender) , Cookie(cookie) @@ -249,7 +274,7 @@ namespace NActors { TScopeId originScopeId, NWilson::TTraceId traceId) noexcept : Type(type) - , Flags(flags) + , Flags(ApplyGlobals(flags)) , Recipient(recipient) , Sender(sender) , Cookie(cookie) |