From 5b9ad0968ae529662c055517e65b14a554c46e1e Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Fri, 8 Mar 2019 16:00:36 -0800 Subject: [PATCH] Avoid StackWalk in EventPipeEventInstance constructor Commit migrated from https://github.com/dotnet/coreclr/commit/8009ba276895edc9decf49c8a2470a1e6bbe2997 --- src/coreclr/src/vm/eventpipe.cpp | 1 + src/coreclr/src/vm/eventpipebuffer.cpp | 1 + src/coreclr/src/vm/eventpipeconfiguration.cpp | 1 + src/coreclr/src/vm/eventpipeeventinstance.cpp | 16 +++++++++------- src/coreclr/src/vm/eventpipeeventinstance.h | 2 ++ 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/coreclr/src/vm/eventpipe.cpp b/src/coreclr/src/vm/eventpipe.cpp index c2db06d..4de0b3c 100644 --- a/src/coreclr/src/vm/eventpipe.cpp +++ b/src/coreclr/src/vm/eventpipe.cpp @@ -798,6 +798,7 @@ void EventPipe::WriteEventInternal(EventPipeEvent &event, EventPipeEventPayload payload.GetSize(), pActivityId, pRelatedActivityId); + instance.EnsureStack(*s_pSession); if(s_pFile != NULL) { diff --git a/src/coreclr/src/vm/eventpipebuffer.cpp b/src/coreclr/src/vm/eventpipebuffer.cpp index 395725e..6cc901c 100644 --- a/src/coreclr/src/vm/eventpipebuffer.cpp +++ b/src/coreclr/src/vm/eventpipebuffer.cpp @@ -83,6 +83,7 @@ bool EventPipeBuffer::WriteEvent(Thread *pThread, EventPipeSession &session, Eve payload.GetSize(), (pThread == NULL) ? NULL : pActivityId, pRelatedActivityId); + pInstance->EnsureStack(session); // TODO: Perform the stackwalk before the constructor // Copy the stack if a separate stack trace was provided. if(pStack != NULL) diff --git a/src/coreclr/src/vm/eventpipeconfiguration.cpp b/src/coreclr/src/vm/eventpipeconfiguration.cpp index d40f2b7..9cf8280 100644 --- a/src/coreclr/src/vm/eventpipeconfiguration.cpp +++ b/src/coreclr/src/vm/eventpipeconfiguration.cpp @@ -505,6 +505,7 @@ EventPipeEventInstance* EventPipeConfiguration::BuildEventMetadataEvent(EventPip instancePayloadSize, NULL /* pActivityId */, NULL /* pRelatedActivityId */); + _ASSERTE(!m_pMetadataEvent->NeedStack()); // Set the timestamp to match the source event, because the metadata event // will be emitted right before the source event. diff --git a/src/coreclr/src/vm/eventpipeeventinstance.cpp b/src/coreclr/src/vm/eventpipeeventinstance.cpp index 1424dbc..03ebc6d 100644 --- a/src/coreclr/src/vm/eventpipeeventinstance.cpp +++ b/src/coreclr/src/vm/eventpipeeventinstance.cpp @@ -34,7 +34,7 @@ EventPipeEventInstance::EventPipeEventInstance( #endif // _DEBUG m_pEvent = &event; m_threadID = threadID; - if(pActivityId != NULL) + if (pActivityId != NULL) { m_activityId = *pActivityId; } @@ -42,7 +42,7 @@ EventPipeEventInstance::EventPipeEventInstance( { m_activityId = {0}; } - if(pRelatedActivityId != NULL) + if (pRelatedActivityId != NULL) { m_relatedActivityId = *pRelatedActivityId; } @@ -55,15 +55,17 @@ EventPipeEventInstance::EventPipeEventInstance( m_dataLength = length; QueryPerformanceCounter(&m_timeStamp); _ASSERTE(m_timeStamp.QuadPart > 0); +#ifdef _DEBUG + EnsureConsistency(); +#endif // _DEBUG +} - if(event.NeedStack() && !session.RundownEnabled()) +void EventPipeEventInstance::EnsureStack(const EventPipeSession &session) +{ + if (m_pEvent->NeedStack() && !session.RundownEnabled()) { EventPipe::WalkManagedStackForCurrentThread(m_stackContents); } - -#ifdef _DEBUG - EnsureConsistency(); -#endif // _DEBUG } unsigned int EventPipeEventInstance::GetAlignedTotalSize() const diff --git a/src/coreclr/src/vm/eventpipeeventinstance.h b/src/coreclr/src/vm/eventpipeeventinstance.h index 47f1b5c..a0e6e54 100644 --- a/src/coreclr/src/vm/eventpipeeventinstance.h +++ b/src/coreclr/src/vm/eventpipeeventinstance.h @@ -23,6 +23,8 @@ public: EventPipeEventInstance(EventPipeSession &session, EventPipeEvent &event, DWORD threadID, BYTE *pData, unsigned int length, LPCGUID pActivityId, LPCGUID pRelatedActivityId); + void EnsureStack(const EventPipeSession &session); + StackContents* GetStack() { LIMITED_METHOD_CONTRACT; -- 2.7.4