Skip to content

Commit

Permalink
[MERGE #5202 @mrkmarron] TTD: explicit support for enable/disable aut…
Browse files Browse the repository at this point in the history
…o-trace

Merge pull request #5202 from mrkmarron:rrfix

Fix for auto-trace behavior.
  • Loading branch information
mrkmarron committed May 22, 2018
2 parents fe4d653 + d1fdc0f commit 1b469e2
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 6 deletions.
1 change: 1 addition & 0 deletions bin/ChakraCore/ChakraCore.def
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ JsTTDMoveToTopLevelEvent
JsTTDReplayExecution

JsTTDDiagWriteLog
JsTTDDiagSetAutoTraceStatus

JsInitializeModuleRecord
JsParseModuleSource
Expand Down
11 changes: 11 additions & 0 deletions lib/Jsrt/ChakraDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,17 @@ typedef unsigned __int32 uint32_t;
_Inout_ JsTTDMoveMode* moveMode,
_Out_ int64_t* rootEventTime);

/// <summary>
/// TTD API -- may change in future versions:
/// Enable or disable autotrace ability from JsRT.
/// </summary>
/// <param name="status">True to enable autotracing false to disable it.</param>
/// <returns>The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.</returns>
CHAKRA_API
JsTTDDiagSetAutoTraceStatus(
_In_ bool status
);

/// <summary>
/// TTD API -- may change in future versions:
/// A way for the debugger to programatically write a trace when it is at a breakpoint.
Expand Down
21 changes: 21 additions & 0 deletions lib/Jsrt/Jsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4625,6 +4625,27 @@ CHAKRA_API JsTTDReplayExecution(_Inout_ JsTTDMoveMode* moveMode, _Out_ int64_t*
#endif
}

CHAKRA_API JsTTDDiagSetAutoTraceStatus(_In_ bool status)
{
#if !ENABLE_TTD
return JsErrorCategoryUsage;
#else
JsrtContext *currentContext = JsrtContext::GetCurrent();
JsErrorCode cCheck = CheckContext(currentContext, JSRT_MAYBE_TRUE);
TTDAssert(cCheck == JsNoError, "Must have valid context when setting auto trace status.");

Js::ScriptContext* scriptContext = currentContext->GetScriptContext();
ThreadContext* threadContext = scriptContext->GetThreadContext();

if (threadContext->IsRuntimeInTTDMode())
{
threadContext->TTDLog->SetAutoTraceEnabled(status);
}

return JsNoError;
#endif
}

#ifdef _CHAKRACOREBUILD

template <class SrcChar, class DstChar>
Expand Down
24 changes: 21 additions & 3 deletions lib/Runtime/Debug/TTEventLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ namespace TTD
TTD_CREATE_EVENTLIST_VTABLE_ENTRY(ExternalCallTag, None, ExternalCallEventLogEntry, nullptr, NSLogEvents::ExternalCallEventLogEntry_UnloadEventMemory, NSLogEvents::ExternalCallEventLogEntry_Emit, NSLogEvents::ExternalCallEventLogEntry_Parse);
TTD_CREATE_EVENTLIST_VTABLE_ENTRY(ExplicitLogWriteTag, None, ExplicitLogWriteEventLogEntry, nullptr, nullptr, NSLogEvents::ExplicitLogWriteEntry_Emit, NSLogEvents::ExplicitLogWriteEntry_Parse);
TTD_CREATE_EVENTLIST_VTABLE_ENTRY(TTDInnerLoopLogWriteTag, None, TTDInnerLoopLogWriteEventLogEntry, nullptr, nullptr, NSLogEvents::TTDInnerLoopLogWriteEventLogEntry_Emit, NSLogEvents::TTDInnerLoopLogWriteEventLogEntry_Parse);
TTD_CREATE_EVENTLIST_VTABLE_ENTRY(TTDFetchAutoTraceStatusTag, None, TTDFetchAutoTraceStatusEventLogEntry, nullptr, nullptr, NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry_Emit, NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry_Parse);

TTD_CREATE_EVENTLIST_VTABLE_ENTRY(CreateScriptContextActionTag, GlobalAPIWrapper, JsRTCreateScriptContextAction, NSLogEvents::CreateScriptContext_Execute, NSLogEvents::CreateScriptContext_UnloadEventMemory, NSLogEvents::CreateScriptContext_Emit, NSLogEvents::CreateScriptContext_Parse);
TTD_CREATE_EVENTLIST_VTABLE_ENTRY_COMMON(SetActiveScriptContextActionTag, GlobalAPIWrapper, JsRTSingleVarArgumentAction, SetActiveScriptContext_Execute);
Expand Down Expand Up @@ -586,7 +587,7 @@ namespace TTD
: m_threadContext(threadContext), m_eventSlabAllocator(TTD_SLAB_BLOCK_ALLOCATION_SIZE_MID), m_miscSlabAllocator(TTD_SLAB_BLOCK_ALLOCATION_SIZE_SMALL),
m_eventTimeCtr(0), m_timer(), m_topLevelCallbackEventTime(-1),
m_eventListVTable(nullptr), m_eventList(&this->m_eventSlabAllocator), m_currentReplayEventIterator(),
m_modeStack(), m_currentMode(TTDMode::Invalid),
m_modeStack(), m_currentMode(TTDMode::Invalid), m_autoTracesEnabled(true),
m_snapExtractor(), m_elapsedExecutionTimeSinceSnapshot(0.0),
m_lastInflateSnapshotTime(-1), m_lastInflateMap(nullptr), m_propertyRecordList(&this->m_miscSlabAllocator),
m_sourceInfoCount(0), m_loadedTopLevelScripts(&this->m_miscSlabAllocator), m_newFunctionTopLevelScripts(&this->m_miscSlabAllocator), m_evalTopLevelScripts(&this->m_miscSlabAllocator)
Expand Down Expand Up @@ -879,6 +880,18 @@ namespace TTD
}
}

void EventLog::RecordTTDFetchAutoTraceStatusEvent(bool status)
{
NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry* atfEvent = this->RecordGetInitializedEvent_DataOnly<NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry, NSLogEvents::EventKind::TTDFetchAutoTraceStatusTag>();
atfEvent->IsEnabled = status;
}

bool EventLog::ReplayTTDFetchAutoTraceStatusLogEvent()
{
const NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry* atfEvent = this->ReplayGetReplayEvent_Helper<NSLogEvents::TTDFetchAutoTraceStatusEventLogEntry, NSLogEvents::EventKind::TTDFetchAutoTraceStatusTag>();
return atfEvent->IsEnabled;
}

void EventLog::RecordDateTimeEvent(double time)
{
NSLogEvents::DoubleEventLogEntry* dEvent = this->RecordGetInitializedEvent_DataOnly<NSLogEvents::DoubleEventLogEntry, NSLogEvents::EventKind::DoubleTag>();
Expand Down Expand Up @@ -2558,9 +2571,14 @@ namespace TTD
return isInnerLoop & isEnabled;
}

bool EventLog::SuppressDiagnosticTracesDuringInnerLoop() const
void EventLog::SetAutoTraceEnabled(bool enabled)
{
this->m_autoTracesEnabled = enabled;
}

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

void EventLog::EmitLog(const char* emitUri, size_t emitUriLength, NSLogEvents::EventLogEntry* optInnerLoopEvent)
Expand Down
10 changes: 9 additions & 1 deletion lib/Runtime/Debug/TTEventLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ namespace TTD
//The current mode the system is running in (and a stack of mode push/pops that we use to generate it)
TTModeStack m_modeStack;
TTDMode m_currentMode;
bool m_autoTracesEnabled;

//The snapshot extractor that this log uses
SnapshotExtractor m_snapExtractor;
Expand Down Expand Up @@ -393,6 +394,12 @@ namespace TTD
//Replay a event that writes the log to a given uri
void ReplayEmitLogEvent();

//Record that we are accessing the TTDFetchAutoTraceStatus and what the value is
void RecordTTDFetchAutoTraceStatusEvent(bool status);

//Replay that we are accessing the TTDFetchAutoTraceStatus
bool ReplayTTDFetchAutoTraceStatusLogEvent();

//Log a time that is fetched during date operations
void RecordDateTimeEvent(double time);

Expand Down Expand Up @@ -605,7 +612,8 @@ namespace TTD
void InnerLoopEmitLog(const TTDebuggerSourceLocation& writeLocation, const char* emitUri, size_t emitUriLength);

bool CanWriteInnerLoopTrace() const;
bool SuppressDiagnosticTracesDuringInnerLoop() const;
void SetAutoTraceEnabled(bool enabled);
bool GetAutoTraceEnabled() 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
14 changes: 14 additions & 0 deletions lib/Runtime/Debug/TTEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,20 @@ namespace TTD
ilevt->Line = reader->ReadUInt32(NSTokens::Key::line, true);
ilevt->Column = reader->ReadUInt32(NSTokens::Key::column, true);
}

void TTDFetchAutoTraceStatusEventLogEntry_Emit(const EventLogEntry* evt, FileWriter* writer, ThreadContext* threadContext)
{
const TTDFetchAutoTraceStatusEventLogEntry* atfevt = GetInlineEventDataAs<TTDFetchAutoTraceStatusEventLogEntry, EventKind::TTDFetchAutoTraceStatusTag>(evt);

writer->WriteLogTag(NSTokens::Key::boolVal, atfevt->IsEnabled, NSTokens::Separator::CommaSeparator);
}

void TTDFetchAutoTraceStatusEventLogEntry_Parse(EventLogEntry* evt, ThreadContext* threadContext, FileReader* reader, UnlinkableSlabAllocator& alloc)
{
TTDFetchAutoTraceStatusEventLogEntry* atfevt = GetInlineEventDataAs<TTDFetchAutoTraceStatusEventLogEntry, EventKind::TTDFetchAutoTraceStatusTag>(evt);

atfevt->IsEnabled = reader->ReadLogTag(NSTokens::Key::boolVal, true);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions lib/Runtime/Debug/TTEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ namespace TTD
ExternalCallTag,
ExplicitLogWriteTag,
TTDInnerLoopLogWriteTag,
TTDFetchAutoTraceStatusTag,
//JsRTActionTag is a marker for where the JsRT actions begin
JsRTActionTag,

Expand Down Expand Up @@ -498,6 +499,15 @@ namespace TTD

void TTDInnerLoopLogWriteEventLogEntry_Emit(const EventLogEntry* evt, FileWriter* writer, ThreadContext* threadContext);
void TTDInnerLoopLogWriteEventLogEntry_Parse(EventLogEntry* evt, ThreadContext* threadContext, FileReader* reader, UnlinkableSlabAllocator& alloc);

//A struct for recording the result of a read of the AutoTraceStatus
struct TTDFetchAutoTraceStatusEventLogEntry
{
bool IsEnabled;
};

void TTDFetchAutoTraceStatusEventLogEntry_Emit(const EventLogEntry* evt, FileWriter* writer, ThreadContext* threadContext);
void TTDFetchAutoTraceStatusEventLogEntry_Parse(EventLogEntry* evt, ThreadContext* threadContext, FileReader* reader, UnlinkableSlabAllocator& alloc);
}
}

Expand Down
15 changes: 13 additions & 2 deletions lib/Runtime/Library/GlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,9 +1674,20 @@ namespace Js
PROBE_STACK(function->GetScriptContext(), Js::Constants::MinStackDefault);
ARGUMENTS(args, callInfo);

if(function->GetScriptContext()->ShouldPerformRecordOrReplayAction() && !function->GetScriptContext()->GetThreadContext()->TTDLog->SuppressDiagnosticTracesDuringInnerLoop())
if (function->GetScriptContext()->ShouldPerformReplayAction())
{
return function->GetScriptContext()->GetLibrary()->GetTrue();
TTD::EventLog* ttlog = function->GetScriptContext()->GetThreadContext()->TTDLog;
bool isEnabled = ttlog->ReplayTTDFetchAutoTraceStatusLogEvent();

return function->GetScriptContext()->GetLibrary()->CreateBoolean(isEnabled);
}
else if (function->GetScriptContext()->ShouldPerformRecordAction())
{
TTD::EventLog* ttlog = function->GetScriptContext()->GetThreadContext()->TTDLog;
bool isEnabled = ttlog->GetAutoTraceEnabled();
ttlog->RecordTTDFetchAutoTraceStatusEvent(isEnabled);

return function->GetScriptContext()->GetLibrary()->CreateBoolean(isEnabled);
}
else
{
Expand Down

0 comments on commit 1b469e2

Please sign in to comment.