EventPipe: Prepend variable length field sizes (#11600)
authorBrian Robbins <brianrob@microsoft.com>
Mon, 15 May 2017 15:13:42 +0000 (08:13 -0700)
committerVance Morrison <vancem@microsoft.com>
Mon, 15 May 2017 15:13:42 +0000 (08:13 -0700)
* Write the size in bytes of the stack before the stack contents.

* Specify the size of the metadata payload explicitly in the file.

src/vm/eventpipeconfiguration.cpp
src/vm/eventpipeeventinstance.cpp

index fb264e2..7ce06ba 100644 (file)
@@ -336,7 +336,7 @@ EventPipeEventInstance* EventPipeConfiguration::BuildEventMetadataEvent(EventPip
     const GUID &providerID = sourceEvent.GetProvider()->GetProviderID();
     unsigned int eventID = sourceEvent.GetEventID();
     unsigned int eventVersion = sourceEvent.GetEventVersion();
-    unsigned int instancePayloadSize = sizeof(providerID) + sizeof(eventID) + sizeof(eventVersion) + payloadLength;
+    unsigned int instancePayloadSize = sizeof(providerID) + sizeof(eventID) + sizeof(eventVersion) + sizeof(payloadLength) + payloadLength;
 
     // Allocate the payload.
     BYTE *pInstancePayload = new BYTE[instancePayloadSize];
@@ -356,6 +356,10 @@ EventPipeEventInstance* EventPipeConfiguration::BuildEventMetadataEvent(EventPip
     memcpy(currentPtr, &eventVersion, sizeof(eventVersion));
     currentPtr += sizeof(eventVersion);
 
+    // Write the size of the metadata.
+    memcpy(currentPtr, &payloadLength, sizeof(payloadLength));
+    currentPtr += sizeof(payloadLength);
+
     // Write the incoming payload data.
     memcpy(currentPtr, pPayloadData, payloadLength);
 
index dc84c04..4527ed5 100644 (file)
@@ -101,6 +101,7 @@ void EventPipeEventInstance::FastSerialize(FastSerializer *pSerializer, StreamLa
         sizeof(m_threadID) +        // Thread ID
         sizeof(m_timeStamp) +       // TimeStamp
         m_dataLength +              // Event payload data length
+        sizeof(unsigned int) +      // Prepended stack payload size in bytes
         m_stackContents.GetSize();  // Stack payload size
 
     // Write the size of the event to the file.
@@ -121,10 +122,14 @@ void EventPipeEventInstance::FastSerialize(FastSerializer *pSerializer, StreamLa
         pSerializer->WriteBuffer(m_pData, m_dataLength);
     }
 
+    // Write the size of the stack in bytes.
+    unsigned int stackSize = m_stackContents.GetSize();
+    pSerializer->WriteBuffer((BYTE*)&stackSize, sizeof(stackSize));
+
     // Write the stack if present.
-    if(m_stackContents.GetSize() > 0)
+    if(stackSize > 0)
     {
-        pSerializer->WriteBuffer(m_stackContents.GetPointer(), m_stackContents.GetSize());
+        pSerializer->WriteBuffer(m_stackContents.GetPointer(), stackSize);
     }
 }