Skip to content

Commit 8e52453

Browse files
committed
[MERGE #4913 @mrkmarron] TTD: Fixes for innerloop trace management.
Merge pull request #4913 from mrkmarron:innerloopfixes Fixes around trace write for innerloop debugging scenarios.
2 parents bfbcfa5 + 4b79e6e commit 8e52453

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

lib/Jsrt/JsrtDiag.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,10 @@ CHAKRA_API JsTTDDiagWriteLog(_In_reads_(uriLength) const char* uri, _In_ size_t
537537
return JsErrorCategoryUsage;
538538
#else
539539
return ContextAPIWrapper_NoRecord<true>([&](Js::ScriptContext * scriptContext) -> JsErrorCode {
540+
if (!scriptContext->GetThreadContext()->IsRuntimeInTTDMode() || !scriptContext->GetThreadContext()->TTDLog->CanWriteInnerLoopTrace())
541+
{
542+
return JsErrorDiagUnableToPerformAction;
543+
}
540544

541545
JsrtContext *currentContext = JsrtContext::GetCurrent();
542546
JsrtRuntime* runtime = currentContext->GetRuntime();

lib/Runtime/Debug/TTEventLog.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,8 +2526,14 @@ namespace TTD
25262526

25272527
void EventLog::InnerLoopEmitLog(const TTDebuggerSourceLocation& writeLocation, const char* emitUri, size_t emitUriLength)
25282528
{
2529-
NSLogEvents::TTDInnerLoopLogWriteEventLogEntry* evt = nullptr;
2530-
this->RecordGetInitializedEvent<NSLogEvents::TTDInnerLoopLogWriteEventLogEntry, NSLogEvents::EventKind::TTDInnerLoopLogWriteTag>(&evt);
2529+
//Events are slab allocated with header immediately followed by payload -- we need to replicate this layout here so we allocate an array and explicitly layout.
2530+
//See definition of GetNextAvailableEntry and GetInlineEventDataAs for more detail.
2531+
byte buff[TTD_EVENT_PLUS_DATA_SIZE(NSLogEvents::TTDInnerLoopLogWriteEventLogEntry)];
2532+
2533+
NSLogEvents::EventLogEntry* entry = reinterpret_cast<NSLogEvents::EventLogEntry*>(buff);
2534+
NSLogEvents::EventLogEntry_Initialize<NSLogEvents::EventKind::TTDInnerLoopLogWriteTag>(entry, this->m_eventTimeCtr);
2535+
2536+
NSLogEvents::TTDInnerLoopLogWriteEventLogEntry* evt = NSLogEvents::GetInlineEventDataAs<NSLogEvents::TTDInnerLoopLogWriteEventLogEntry, NSLogEvents::EventKind::TTDInnerLoopLogWriteTag>(entry);
25312537

25322538
evt->SourceScriptLogId = writeLocation.GetScriptLogTagId();
25332539
evt->EventTime = writeLocation.GetRootEventTime();
@@ -2541,10 +2547,23 @@ namespace TTD
25412547
evt->Line = writeLocation.GetSourceLine();
25422548
evt->Column = writeLocation.GetSourceColumn();
25432549

2544-
this->EmitLog(emitUri, emitUriLength);
2550+
this->EmitLog(emitUri, emitUriLength, entry);
25452551
}
25462552

2547-
void EventLog::EmitLog(const char* emitUri, size_t emitUriLength)
2553+
bool EventLog::CanWriteInnerLoopTrace() const
2554+
{
2555+
bool isInnerLoop = (this->m_currentMode & (TTDMode::RecordDebuggerMode)) == TTDMode::RecordDebuggerMode;
2556+
bool isEnabled = (this->m_currentMode & (TTDMode::CurrentlyEnabled)) == TTDMode::CurrentlyEnabled;
2557+
2558+
return isInnerLoop & isEnabled;
2559+
}
2560+
2561+
bool EventLog::SuppressDiagnosticTracesDuringInnerLoop() const
2562+
{
2563+
return (this->m_currentMode & (TTDMode::DebuggerAttachedMode)) == TTDMode::DebuggerAttachedMode;
2564+
}
2565+
2566+
void EventLog::EmitLog(const char* emitUri, size_t emitUriLength, NSLogEvents::EventLogEntry* optInnerLoopEvent)
25482567
{
25492568
#if ENABLE_BASIC_TRACE || ENABLE_FULL_BC_TRACE
25502569
this->m_threadContext->TTDExecutionInfo->GetTraceLogger()->ForceFlush();
@@ -2604,7 +2623,7 @@ namespace TTD
26042623
writer.WriteUInt64(NSTokens::Key::usedMemory, usedSpace, NSTokens::Separator::CommaSeparator);
26052624
writer.WriteUInt64(NSTokens::Key::reservedMemory, reservedSpace, NSTokens::Separator::CommaSeparator);
26062625

2607-
uint32 ecount = this->m_eventList.Count();
2626+
uint32 ecount = this->m_eventList.Count() + (optInnerLoopEvent != nullptr ? 1 : 0);
26082627
writer.WriteLengthValue(ecount, NSTokens::Separator::CommaAndBigSpaceSeparator);
26092628

26102629
#if ENABLE_TTD_INTERNAL_DIAGNOSTICS
@@ -2677,6 +2696,13 @@ namespace TTD
26772696
}
26782697
#endif
26792698
}
2699+
2700+
if (optInnerLoopEvent != nullptr)
2701+
{
2702+
//Emit the special event that indicates we want to break at the end of the log (with a known breakpoint time)
2703+
NSLogEvents::EventLogEntry_Emit(optInnerLoopEvent, this->m_eventListVTable, &writer, this->m_threadContext, NSTokens::Separator::BigSpaceSeparator);
2704+
}
2705+
26802706
writer.AdjustIndent(-1);
26812707
writer.WriteSequenceEnd(NSTokens::Separator::BigSpaceSeparator);
26822708

lib/Runtime/Debug/TTEventLog.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,10 @@ namespace TTD
604604

605605
void InnerLoopEmitLog(const TTDebuggerSourceLocation& writeLocation, const char* emitUri, size_t emitUriLength);
606606

607-
void EmitLog(const char* emitUri, size_t emitUriLength);
607+
bool CanWriteInnerLoopTrace() const;
608+
bool SuppressDiagnosticTracesDuringInnerLoop() const;
609+
610+
void EmitLog(const char* emitUri, size_t emitUriLength, NSLogEvents::EventLogEntry* optInnerLoopEvent = nullptr);
608611
void ParseLogInto(TTDataIOInfo& iofp, const char* parseUri, size_t parseUriLength);
609612
};
610613

lib/Runtime/Library/GlobalObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ namespace Js
16741674
PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault);
16751675
ARGUMENTS(args, callInfo);
16761676

1677-
if(function->GetScriptContext()->ShouldPerformRecordOrReplayAction())
1677+
if(function->GetScriptContext()->ShouldPerformRecordOrReplayAction() && !function->GetScriptContext()->GetThreadContext()->TTDLog->SuppressDiagnosticTracesDuringInnerLoop())
16781678
{
16791679
return function->GetScriptContext()->GetLibrary()->GetTrue();
16801680
}

0 commit comments

Comments
 (0)