Avoid StackWalk in EventPipeEventInstance constructor
authorAndrew Au <andrewau@microsoft.com>
Sat, 9 Mar 2019 00:00:36 +0000 (16:00 -0800)
committerAndrew Au <cshung@gmail.com>
Sat, 9 Mar 2019 17:04:59 +0000 (09:04 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/8009ba276895edc9decf49c8a2470a1e6bbe2997

src/coreclr/src/vm/eventpipe.cpp
src/coreclr/src/vm/eventpipebuffer.cpp
src/coreclr/src/vm/eventpipeconfiguration.cpp
src/coreclr/src/vm/eventpipeeventinstance.cpp
src/coreclr/src/vm/eventpipeeventinstance.h

index c2db06d..4de0b3c 100644 (file)
@@ -798,6 +798,7 @@ void EventPipe::WriteEventInternal(EventPipeEvent &event, EventPipeEventPayload
                 payload.GetSize(),
                 pActivityId,
                 pRelatedActivityId);
+            instance.EnsureStack(*s_pSession);
 
             if(s_pFile != NULL)
             {
index 395725e..6cc901c 100644 (file)
@@ -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)
index d40f2b7..9cf8280 100644 (file)
@@ -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.
index 1424dbc..03ebc6d 100644 (file)
@@ -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
index 47f1b5c..a0e6e54 100644 (file)
@@ -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;