Skip to content

Commit f036a6c

Browse files
authored
Add event tracing capabilities in debugging (#12801)
1 parent 114915e commit f036a6c

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

ydb/library/actors/core/actor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ namespace NActors {
537537
}
538538

539539
void Receive(TAutoPtr<IEventHandle>& ev) {
540+
#ifndef NDEBUG
541+
if (ev->Flags & IEventHandle::FlagDebugTrackReceive) {
542+
YaDebugBreak();
543+
}
544+
#endif
540545
++HandledEvents;
541546
LastReceiveTimestamp = TActivationContext::Monotonic();
542547
if (CImpl.Initialized()) {

ydb/library/actors/core/event.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,10 @@ namespace NActors {
6060
return DoExecute(actor, std::move(eventPtr));
6161
}
6262

63+
#ifndef NDEBUG
64+
void IEventHandle::DoTrackNextEvent() {
65+
TrackNextEvent = true;
66+
}
67+
#endif
68+
6369
}

ydb/library/actors/core/event.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace NActors {
1414
class TChunkSerializer;
1515
class IActor;
16-
16+
1717
class IEventBase
1818
: TNonCopyable {
1919
protected:
@@ -122,6 +122,7 @@ namespace NActors {
122122
FlagUseSubChannel = 1 << 3,
123123
FlagGenerateUnsureUndelivered = 1 << 4,
124124
FlagExtendedFormat = 1 << 5,
125+
FlagDebugTrackReceive = 1 << 6,
125126
};
126127
using TEventFlags = ui32;
127128

@@ -194,10 +195,34 @@ namespace NActors {
194195
return OnNondeliveryHolder.Get() ? OnNondeliveryHolder->Recipient : TActorId();
195196
}
196197

198+
#ifndef NDEBUG
199+
static inline thread_local bool TrackNextEvent = false;
200+
201+
/**
202+
* Call this function in gdb before
203+
* sending the event you want to debug
204+
* and continue execution. __builtin_debugtrap/SIGTRAP
205+
* will stop gdb at the receiving point.
206+
* Currently, to get to Handle function you
207+
* also need to ascend couple frames (up, up) and step to
208+
* function you are searching for
209+
*/
210+
static void DoTrackNextEvent();
211+
212+
static TEventFlags ApplyGlobals(TEventFlags flags) {
213+
bool trackNextEvent = std::exchange(TrackNextEvent, false);
214+
return flags | (trackNextEvent ? FlagDebugTrackReceive : 0);
215+
}
216+
#else
217+
Y_FORCE_INLINE static TEventFlags ApplyGlobals(TEventFlags flags) {
218+
return flags;
219+
}
220+
#endif
221+
197222
IEventHandle(const TActorId& recipient, const TActorId& sender, IEventBase* ev, TEventFlags flags = 0, ui64 cookie = 0,
198223
const TActorId* forwardOnNondelivery = nullptr, NWilson::TTraceId traceId = {})
199224
: Type(ev->Type())
200-
, Flags(flags)
225+
, Flags(ApplyGlobals(flags))
201226
, Recipient(recipient)
202227
, Sender(sender)
203228
, Cookie(cookie)
@@ -222,7 +247,7 @@ namespace NActors {
222247
const TActorId* forwardOnNondelivery = nullptr,
223248
NWilson::TTraceId traceId = {})
224249
: Type(type)
225-
, Flags(flags)
250+
, Flags(ApplyGlobals(flags))
226251
, Recipient(recipient)
227252
, Sender(sender)
228253
, Cookie(cookie)
@@ -249,7 +274,7 @@ namespace NActors {
249274
TScopeId originScopeId,
250275
NWilson::TTraceId traceId) noexcept
251276
: Type(type)
252-
, Flags(flags)
277+
, Flags(ApplyGlobals(flags))
253278
, Recipient(recipient)
254279
, Sender(sender)
255280
, Cookie(cookie)

0 commit comments

Comments
 (0)