Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Jsrt/JsrtDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,10 @@ CHAKRA_API JsTTDDiagWriteLog(_In_reads_(uriLength) const char* uri, _In_ size_t
return JsErrorCategoryUsage;
#else
return ContextAPIWrapper_NoRecord<true>([&](Js::ScriptContext * scriptContext) -> JsErrorCode {
if (!scriptContext->GetThreadContext()->IsRuntimeInTTDMode() || !scriptContext->GetThreadContext()->TTDLog->CanWriteInnerLoopTrace())
{
return JsErrorDiagUnableToPerformAction;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are callers of this method expecting such an error code & do they need to do anything special to account for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the caller just ignores the return code. However, the lack of an error code here is not inline with the form of the other API's so I wanted to get it added for cleanliness when I was adding the check code.

}

JsrtContext *currentContext = JsrtContext::GetCurrent();
JsrtRuntime* runtime = currentContext->GetRuntime();
Expand Down
36 changes: 31 additions & 5 deletions lib/Runtime/Debug/TTEventLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2526,8 +2526,14 @@ namespace TTD

void EventLog::InnerLoopEmitLog(const TTDebuggerSourceLocation& writeLocation, const char* emitUri, size_t emitUriLength)
{
NSLogEvents::TTDInnerLoopLogWriteEventLogEntry* evt = nullptr;
this->RecordGetInitializedEvent<NSLogEvents::TTDInnerLoopLogWriteEventLogEntry, NSLogEvents::EventKind::TTDInnerLoopLogWriteTag>(&evt);
//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.
//See definition of GetNextAvailableEntry and GetInlineEventDataAs for more detail.
byte buff[TTD_EVENT_PLUS_DATA_SIZE(NSLogEvents::TTDInnerLoopLogWriteEventLogEntry)];

NSLogEvents::EventLogEntry* entry = reinterpret_cast<NSLogEvents::EventLogEntry*>(buff);
NSLogEvents::EventLogEntry_Initialize<NSLogEvents::EventKind::TTDInnerLoopLogWriteTag>(entry, this->m_eventTimeCtr);

NSLogEvents::TTDInnerLoopLogWriteEventLogEntry* evt = NSLogEvents::GetInlineEventDataAs<NSLogEvents::TTDInnerLoopLogWriteEventLogEntry, NSLogEvents::EventKind::TTDInnerLoopLogWriteTag>(entry);

evt->SourceScriptLogId = writeLocation.GetScriptLogTagId();
evt->EventTime = writeLocation.GetRootEventTime();
Expand All @@ -2541,10 +2547,23 @@ namespace TTD
evt->Line = writeLocation.GetSourceLine();
evt->Column = writeLocation.GetSourceColumn();

this->EmitLog(emitUri, emitUriLength);
this->EmitLog(emitUri, emitUriLength, entry);
}

void EventLog::EmitLog(const char* emitUri, size_t emitUriLength)
bool EventLog::CanWriteInnerLoopTrace() const
{
bool isInnerLoop = (this->m_currentMode & (TTDMode::RecordDebuggerMode)) == TTDMode::RecordDebuggerMode;
bool isEnabled = (this->m_currentMode & (TTDMode::CurrentlyEnabled)) == TTDMode::CurrentlyEnabled;

return isInnerLoop & isEnabled;
}

bool EventLog::SuppressDiagnosticTracesDuringInnerLoop() const
{
return (this->m_currentMode & (TTDMode::DebuggerAttachedMode)) == TTDMode::DebuggerAttachedMode;
}

void EventLog::EmitLog(const char* emitUri, size_t emitUriLength, NSLogEvents::EventLogEntry* optInnerLoopEvent)
{
#if ENABLE_BASIC_TRACE || ENABLE_FULL_BC_TRACE
this->m_threadContext->TTDExecutionInfo->GetTraceLogger()->ForceFlush();
Expand Down Expand Up @@ -2604,7 +2623,7 @@ namespace TTD
writer.WriteUInt64(NSTokens::Key::usedMemory, usedSpace, NSTokens::Separator::CommaSeparator);
writer.WriteUInt64(NSTokens::Key::reservedMemory, reservedSpace, NSTokens::Separator::CommaSeparator);

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

#if ENABLE_TTD_INTERNAL_DIAGNOSTICS
Expand Down Expand Up @@ -2677,6 +2696,13 @@ namespace TTD
}
#endif
}

if (optInnerLoopEvent != nullptr)
{
//Emit the special event that indicates we want to break at the end of the log (with a known breakpoint time)
NSLogEvents::EventLogEntry_Emit(optInnerLoopEvent, this->m_eventListVTable, &writer, this->m_threadContext, NSTokens::Separator::BigSpaceSeparator);
}

writer.AdjustIndent(-1);
writer.WriteSequenceEnd(NSTokens::Separator::BigSpaceSeparator);

Expand Down
5 changes: 4 additions & 1 deletion lib/Runtime/Debug/TTEventLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,10 @@ namespace TTD

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

void EmitLog(const char* emitUri, size_t emitUriLength);
bool CanWriteInnerLoopTrace() const;
bool SuppressDiagnosticTracesDuringInnerLoop() const;

void EmitLog(const char* emitUri, size_t emitUriLength, NSLogEvents::EventLogEntry* optInnerLoopEvent = nullptr);
void ParseLogInto(TTDataIOInfo& iofp, const char* parseUri, size_t parseUriLength);
};

Expand Down
2 changes: 1 addition & 1 deletion lib/Runtime/Library/GlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ namespace Js
PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault);
ARGUMENTS(args, callInfo);

if(function->GetScriptContext()->ShouldPerformRecordOrReplayAction())
if(function->GetScriptContext()->ShouldPerformRecordOrReplayAction() && !function->GetScriptContext()->GetThreadContext()->TTDLog->SuppressDiagnosticTracesDuringInnerLoop())
{
return function->GetScriptContext()->GetLibrary()->GetTrue();
}
Expand Down