Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add managed array type support for EventPipe #36242

Merged
merged 13 commits into from
May 20, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static unsafe extern ulong Enable(
internal static extern IntPtr CreateProvider(string providerName, Interop.Advapi32.EtwEnableCallback callbackFunc);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern unsafe IntPtr DefineEvent(IntPtr provHandle, uint eventID, long keywords, uint eventVersion, uint level, void* pMetadata, uint metadataLength);
internal static extern unsafe IntPtr DefineEvent(IntPtr provHandle, uint eventID, long keywords, uint eventVersion, uint level, void *pMetadata, uint metadataLength);

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern IntPtr GetProvider(string providerName);
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/src/vm/eventpipeblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,4 @@ bool EventPipeStackBlock::WriteStack(DWORD stackId, StackContents* pStack)

return true;
}


#endif // FEATURE_PERFTRACING
3 changes: 2 additions & 1 deletion src/coreclr/src/vm/eventpipeevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ EventPipeEvent::EventPipeEvent(
m_level(level),
m_needStack(needStack),
m_enabledMask(0),
m_pMetadata(nullptr)
m_pMetadata(nullptr),
m_metadataLength(0)
{
CONTRACTL
{
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/src/vm/eventpipeevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class EventPipeEvent

// Only EventPipeProvider can create events.
// The provider is responsible for allocating and freeing events.
EventPipeEvent(EventPipeProvider &provider, INT64 keywords, unsigned int eventID, unsigned int eventVersion, EventPipeEventLevel level, bool needStack, BYTE *pMetadata = NULL, unsigned int metadataLength = 0);
EventPipeEvent(EventPipeProvider &provider, INT64 keywords, unsigned int eventID, unsigned int eventVersion, EventPipeEventLevel level, bool needStack,
BYTE *pMetadata = NULL, unsigned int metadataLength = 0);

public:
~EventPipeEvent();
Expand Down
15 changes: 10 additions & 5 deletions src/coreclr/src/vm/eventpipefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ void EventPipeFile::WriteEvent(EventPipeEventInstance &instance, ULONGLONG captu
THROWS;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(m_pSerializer != nullptr);
}
CONTRACTL_END;

if (HasErrors()) return;

#ifdef DEBUG
_ASSERTE(instance.GetTimeStamp()->QuadPart >= m_lastSortedTimestamp.QuadPart);
if (isSortedEvent)
Expand All @@ -221,14 +222,15 @@ void EventPipeFile::WriteEvent(EventPipeEventInstance &instance, ULONGLONG captu

// Check to see if we've seen this event type before.
// If not, then write the event metadata to the event stream first.
unsigned int metadataId = GetMetadataId(*instance.GetEvent());
EventPipeEvent* pEvent = instance.GetEvent();
unsigned int metadataId = GetMetadataId(*pEvent);
if(metadataId == 0)
{
metadataId = GenerateMetadataId();

EventPipeEventInstance* pMetadataInstance = EventPipe::BuildEventMetadataEvent(instance, metadataId);

WriteEventToBlock(*pMetadataInstance, 0); // metadataId=0 breaks recursion and represents the metadata event.
WriteEventToBlock(*pMetadataInstance, 0); // metadataId=0 breaks recursion and represents the metadata event.

SaveMetadataId(*instance.GetEvent(), metadataId);

Expand All @@ -247,7 +249,6 @@ void EventPipeFile::WriteSequencePoint(EventPipeSequencePoint* pSequencePoint)
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(pSequencePoint != nullptr);
PRECONDITION(m_pSerializer != nullptr);
}
CONTRACTL_END;

Expand All @@ -259,6 +260,9 @@ void EventPipeFile::WriteSequencePoint(EventPipeSequencePoint* pSequencePoint)

Flush(FlushAllBlocks);
EventPipeSequencePointBlock sequencePointBlock(pSequencePoint);

if (HasErrors()) return;

m_pSerializer->WriteObject(&sequencePointBlock);

// stack cache resets on sequence points
Expand All @@ -278,13 +282,14 @@ void EventPipeFile::Flush(FlushFlags flags)
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
PRECONDITION(m_pSerializer != nullptr);
PRECONDITION(m_pMetadataBlock != nullptr);
PRECONDITION(m_pStackBlock != nullptr);
PRECONDITION(m_pBlock != nullptr);
}
CONTRACTL_END;

if (HasErrors()) return;

// we write current blocks to the disk, whether they are full or not
if ((m_pMetadataBlock->GetBytesWritten() != 0) && ((flags & FlushMetadataBlock) != 0))
{
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/vm/eventpipeprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ EventPipeProviderCallbackData EventPipeProvider::UnsetConfiguration(
return PrepareCallbackData(m_keywords, m_providerLevel, pFilterData);
}

EventPipeEvent *EventPipeProvider::AddEvent(unsigned int eventID, INT64 keywords, unsigned int eventVersion, EventPipeEventLevel level, bool needStack, BYTE *pMetadata, unsigned int metadataLength)
EventPipeEvent *EventPipeProvider::AddEvent(unsigned int eventID, INT64 keywords, unsigned int eventVersion, EventPipeEventLevel level, bool needStack,
BYTE *pMetadata, unsigned int metadataLength)
{
CONTRACTL
{
Expand All @@ -172,7 +173,6 @@ EventPipeEvent *EventPipeProvider::AddEvent(unsigned int eventID, INT64 keywords
needStack,
pMetadata,
metadataLength);

// Add it to the list of events.
AddEvent(*pEvent);
return pEvent;
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/src/vm/eventpipeprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class EventPipeProvider
INT64 ComputeEventEnabledMask(INT64 keywords, EventPipeEventLevel eventLevel) const;

// Create a new event.
EventPipeEvent* AddEvent(unsigned int eventID, INT64 keywords, unsigned int eventVersion, EventPipeEventLevel level, bool needStack, BYTE *pMetadata = NULL, unsigned int metadataLength = 0);
EventPipeEvent* AddEvent(unsigned int eventID, INT64 keywords, unsigned int eventVersion, EventPipeEventLevel level, bool needStack,
BYTE *pMetadata = NULL, unsigned int metadataLength = 0);

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ int IEventProvider.EventActivityIdControl(Interop.Advapi32.ActivityControl Contr
}

// Define an EventPipeEvent handle.
unsafe IntPtr IEventProvider.DefineEventHandle(uint eventID, string eventName, long keywords, uint eventVersion, uint level, byte* pMetadata, uint metadataLength)
unsafe IntPtr IEventProvider.DefineEventHandle(uint eventID, string eventName, long keywords, uint eventVersion, uint level,
byte *pMetadata, uint metadataLength)
{
IntPtr eventHandlePtr = EventPipeInternal.DefineEvent(m_provHandle, eventID, keywords, eventVersion, level, pMetadata, metadataLength);
return eventHandlePtr;
Expand Down
Loading