Skip to content

Commit e16f56d

Browse files
committed
Fixes for innerloop trace management.
1 parent bfbcfa5 commit e16f56d

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-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: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,8 +2526,12 @@ 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+
byte buff[TTD_EVENT_PLUS_DATA_SIZE(NSLogEvents::TTDInnerLoopLogWriteEventLogEntry)];
2530+
2531+
NSLogEvents::EventLogEntry* entry = reinterpret_cast<NSLogEvents::EventLogEntry*>(buff);
2532+
NSLogEvents::EventLogEntry_Initialize<NSLogEvents::EventKind::TTDInnerLoopLogWriteTag>(entry, this->m_eventTimeCtr);
2533+
2534+
NSLogEvents::TTDInnerLoopLogWriteEventLogEntry* evt = NSLogEvents::GetInlineEventDataAs<NSLogEvents::TTDInnerLoopLogWriteEventLogEntry, NSLogEvents::EventKind::TTDInnerLoopLogWriteTag>(entry);
25312535

25322536
evt->SourceScriptLogId = writeLocation.GetScriptLogTagId();
25332537
evt->EventTime = writeLocation.GetRootEventTime();
@@ -2541,10 +2545,23 @@ namespace TTD
25412545
evt->Line = writeLocation.GetSourceLine();
25422546
evt->Column = writeLocation.GetSourceColumn();
25432547

2544-
this->EmitLog(emitUri, emitUriLength);
2548+
this->EmitLog(emitUri, emitUriLength, entry);
2549+
}
2550+
2551+
bool EventLog::CanWriteInnerLoopTrace() const
2552+
{
2553+
bool isInnerLoop = (this->m_currentMode & (TTDMode::RecordDebuggerMode)) == TTDMode::RecordDebuggerMode;
2554+
bool isEnabled = (this->m_currentMode & (TTDMode::CurrentlyEnabled)) == TTDMode::CurrentlyEnabled;
2555+
2556+
return isInnerLoop & isEnabled;
25452557
}
25462558

2547-
void EventLog::EmitLog(const char* emitUri, size_t emitUriLength)
2559+
bool EventLog::SuppressDiagnosticTracesDuringInnerLoop() const
2560+
{
2561+
return (this->m_currentMode & (TTDMode::DebuggerAttachedMode)) == TTDMode::DebuggerAttachedMode;
2562+
}
2563+
2564+
void EventLog::EmitLog(const char* emitUri, size_t emitUriLength, NSLogEvents::EventLogEntry* optInnerLoopEvent)
25482565
{
25492566
#if ENABLE_BASIC_TRACE || ENABLE_FULL_BC_TRACE
25502567
this->m_threadContext->TTDExecutionInfo->GetTraceLogger()->ForceFlush();
@@ -2604,7 +2621,7 @@ namespace TTD
26042621
writer.WriteUInt64(NSTokens::Key::usedMemory, usedSpace, NSTokens::Separator::CommaSeparator);
26052622
writer.WriteUInt64(NSTokens::Key::reservedMemory, reservedSpace, NSTokens::Separator::CommaSeparator);
26062623

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

26102627
#if ENABLE_TTD_INTERNAL_DIAGNOSTICS
@@ -2677,6 +2694,10 @@ namespace TTD
26772694
}
26782695
#endif
26792696
}
2697+
if (optInnerLoopEvent != nullptr)
2698+
{
2699+
NSLogEvents::EventLogEntry_Emit(optInnerLoopEvent, this->m_eventListVTable, &writer, this->m_threadContext, NSTokens::Separator::BigSpaceSeparator);
2700+
}
26802701
writer.AdjustIndent(-1);
26812702
writer.WriteSequenceEnd(NSTokens::Separator::BigSpaceSeparator);
26822703

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)