Skip to content

Instantly share code, notes, and snippets.

@nategraf
Created August 18, 2017 21:03
Show Gist options
  • Save nategraf/1c9ab4ad2a3042bf58aa8dbd0d8a1598 to your computer and use it in GitHub Desktop.
Save nategraf/1c9ab4ad2a3042bf58aa8dbd0d8a1598 to your computer and use it in GitHub Desktop.
Question
class EventPipeEvent
{
...
private:
// The provider that contains the event.
EventPipeProvider *m_pProvider;
...
}
class EventPipeEventInstance
{
...
public:
void FastSerialize(FastSerializer *pSerializer, StreamLabel metadataLabel);
...
protected:
EventPipeEvent *m_pEvent;
...
}
void EventPipeEventInstance::FastSerialize(FastSerializer *pSerializer, StreamLabel metadataLabel)
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
MODE_ANY;
}
CONTRACTL_END;
#ifdef EVENTPIPE_EVENT_MARKER
// Useful for diagnosing serialization bugs.
const unsigned int value = 0xDEADBEEF;
pSerializer->WriteBuffer((BYTE*)&value, sizeof(value));
#endif
// Calculate the size of the total payload so that it can be written to the file.
unsigned int payloadLength =
sizeof(metadataLabel) +
sizeof(m_threadID) + // Thread ID
sizeof(m_timeStamp) + // TimeStamp
sizeof(m_activityId) + // Activity ID
sizeof(m_relatedActivityId) + // Related Activity ID
sizeof(m_dataLength) + // Data payload length
m_dataLength + // Event payload data
sizeof(unsigned int) + // Prepended stack payload size in bytes
m_stackContents.GetSize(); // Stack payload size
// Write the size of the event to the file.
pSerializer->WriteBuffer((BYTE*)&payloadLength, sizeof(payloadLength));
// Write the metadata label.
pSerializer->WriteBuffer((BYTE*)&metadataLabel, sizeof(metadataLabel));
// Write the thread ID.
pSerializer->WriteBuffer((BYTE*)&m_threadID, sizeof(m_threadID));
// Write the timestamp.
pSerializer->WriteBuffer((BYTE*)&m_timeStamp, sizeof(m_timeStamp));
// Write the activity id.
pSerializer->WriteBuffer((BYTE*)&m_activityId, sizeof(m_activityId));
// Write the related activity id.
pSerializer->WriteBuffer((BYTE*)&m_relatedActivityId, sizeof(m_relatedActivityId));
// Write the data payload size.
pSerializer->WriteBuffer((BYTE*)&m_dataLength, sizeof(m_dataLength));
// Write the event data payload.
if(m_dataLength > 0)
{
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(stackSize > 0)
{
pSerializer->WriteBuffer(m_stackContents.GetPointer(), stackSize);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment