diff options
author | Brian Robbins <brianrob@microsoft.com> | 2017-05-16 17:11:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-16 17:11:47 -0700 |
commit | 40b87c9810c31fb6ab471a44b5735408269ce6ba (patch) | |
tree | 144465f0ad9ddf55d274114e0ac77c7ba615a298 /src/vm | |
parent | 36e988ee6593351f1e962118a99154df5eae0254 (diff) | |
download | coreclr-40b87c9810c31fb6ab471a44b5735408269ce6ba.tar.gz coreclr-40b87c9810c31fb6ab471a44b5735408269ce6ba.tar.bz2 coreclr-40b87c9810c31fb6ab471a44b5735408269ce6ba.zip |
Allow provider deletion to be deferred until after tracing is stopped. (#11651)
Diffstat (limited to 'src/vm')
-rw-r--r-- | src/vm/eventpipe.cpp | 52 | ||||
-rw-r--r-- | src/vm/eventpipe.h | 7 | ||||
-rw-r--r-- | src/vm/eventpipeconfiguration.cpp | 29 | ||||
-rw-r--r-- | src/vm/eventpipeconfiguration.h | 3 | ||||
-rw-r--r-- | src/vm/eventpipeprovider.cpp | 12 | ||||
-rw-r--r-- | src/vm/eventpipeprovider.h | 16 | ||||
-rw-r--r-- | src/vm/sampleprofiler.cpp | 2 |
7 files changed, 116 insertions, 5 deletions
diff --git a/src/vm/eventpipe.cpp b/src/vm/eventpipe.cpp index 58f93ef179..e7bef23d4f 100644 --- a/src/vm/eventpipe.cpp +++ b/src/vm/eventpipe.cpp @@ -218,6 +218,10 @@ void EventPipe::Disable() // De-allocate buffers. s_pBufferManager->DeAllocateBuffers(); + + // Delete deferred providers. + // Providers can't be deleted during tracing because they may be needed when serializing the file. + s_pConfig->DeleteDeferredProviders(); } } @@ -234,6 +238,50 @@ bool EventPipe::Enabled() return enabled; } +EventPipeProvider* EventPipe::CreateProvider(const GUID &providerID, EventPipeCallback pCallbackFunction, void *pCallbackData) +{ + CONTRACTL + { + THROWS; + GC_TRIGGERS; + MODE_ANY; + } + CONTRACTL_END; + + return new EventPipeProvider(providerID, pCallbackFunction, pCallbackData); +} + +void EventPipe::DeleteProvider(EventPipeProvider *pProvider) +{ + CONTRACTL + { + THROWS; + GC_TRIGGERS; + MODE_ANY; + } + CONTRACTL_END; + + // Take the lock to make sure that we don't have a race + // between disabling tracing and deleting a provider + // where we hold a provider after tracing has been disabled. + CrstHolder _crst(GetLock()); + + if(pProvider != NULL) + { + if(Enabled()) + { + // Save the provider until the end of the tracing session. + pProvider->SetDeleteDeferred(); + } + else + { + // Delete the provider now. + // NOTE: This will remove it from all of the EventPipe data structures. + delete(pProvider); + } + } +} + void EventPipe::WriteEvent(EventPipeEvent &event, BYTE *pData, unsigned int length) { CONTRACTL @@ -477,7 +525,7 @@ INT_PTR QCALLTYPE EventPipeInternal::CreateProvider( BEGIN_QCALL; - pProvider = new EventPipeProvider(providerID, pCallbackFunc, NULL); + pProvider = EventPipe::CreateProvider(providerID, pCallbackFunc, NULL); END_QCALL; @@ -519,7 +567,7 @@ void QCALLTYPE EventPipeInternal::DeleteProvider( if(provHandle != NULL) { EventPipeProvider *pProvider = reinterpret_cast<EventPipeProvider*>(provHandle); - delete pProvider; + EventPipe::DeleteProvider(pProvider); } END_QCALL; diff --git a/src/vm/eventpipe.h b/src/vm/eventpipe.h index 0aced258c0..092508fe0f 100644 --- a/src/vm/eventpipe.h +++ b/src/vm/eventpipe.h @@ -14,6 +14,7 @@ class EventPipeFile; class EventPipeJsonFile; class EventPipeBuffer; class EventPipeBufferManager; +class EventPipeProvider; class MethodDesc; class SampleProfilerEventInstance; struct EventPipeProviderConfiguration; @@ -179,6 +180,12 @@ class EventPipe // Specifies whether or not the event pipe is enabled. static bool Enabled(); + // Create a provider. + static EventPipeProvider* CreateProvider(const GUID &providerID, EventPipeCallback pCallbackFunction = NULL, void *pCallbackData = NULL); + + // Delete a provider. + static void DeleteProvider(EventPipeProvider *pProvider); + // Write out an event. // Data is written as a serialized blob matching the ETW serialization conventions. static void WriteEvent(EventPipeEvent &event, BYTE *pData, unsigned int length); diff --git a/src/vm/eventpipeconfiguration.cpp b/src/vm/eventpipeconfiguration.cpp index a227d9d68a..73379fed1b 100644 --- a/src/vm/eventpipeconfiguration.cpp +++ b/src/vm/eventpipeconfiguration.cpp @@ -59,7 +59,7 @@ void EventPipeConfiguration::Initialize() CONTRACTL_END; // Create the configuration provider. - m_pConfigProvider = new EventPipeProvider(s_configurationProviderID); + m_pConfigProvider = EventPipe::CreateProvider(s_configurationProviderID); // Create the metadata event. m_pMetadataEvent = m_pConfigProvider->AddEvent( @@ -379,6 +379,33 @@ EventPipeEventInstance* EventPipeConfiguration::BuildEventMetadataEvent(EventPip return pInstance; } +void EventPipeConfiguration::DeleteDeferredProviders() +{ + CONTRACTL + { + THROWS; + GC_TRIGGERS; + MODE_ANY; + // Lock must be held by EventPipe::Disable. + PRECONDITION(EventPipe::GetLock()->OwnedByCurrentThread()); + + } + CONTRACTL_END; + + SListElem<EventPipeProvider*> *pElem = m_pProviderList->GetHead(); + while(pElem != NULL) + { + EventPipeProvider *pProvider = pElem->GetValue(); + if(pProvider->GetDeleteDeferred()) + { + // The act of deleting the provider unregisters it and removes it from the list. + delete(pProvider); + } + + pElem = m_pProviderList->GetNext(pElem); + } +} + EventPipeEnabledProviderList::EventPipeEnabledProviderList( EventPipeProviderConfiguration *pConfigs, unsigned int numConfigs) diff --git a/src/vm/eventpipeconfiguration.h b/src/vm/eventpipeconfiguration.h index 44c4205c55..de8e79d2f3 100644 --- a/src/vm/eventpipeconfiguration.h +++ b/src/vm/eventpipeconfiguration.h @@ -71,6 +71,9 @@ public: // Get the event used to write metadata to the event stream. EventPipeEventInstance* BuildEventMetadataEvent(EventPipeEventInstance &sourceInstance); + // Delete deferred providers. + void DeleteDeferredProviders(); + private: // Get the provider without taking the lock. diff --git a/src/vm/eventpipeprovider.cpp b/src/vm/eventpipeprovider.cpp index 3c2d25401e..896f9b2650 100644 --- a/src/vm/eventpipeprovider.cpp +++ b/src/vm/eventpipeprovider.cpp @@ -208,6 +208,18 @@ void EventPipeProvider::InvokeCallback() } } +bool EventPipeProvider::GetDeleteDeferred() const +{ + LIMITED_METHOD_CONTRACT; + return m_deleteDeferred; +} + +void EventPipeProvider::SetDeleteDeferred() +{ + LIMITED_METHOD_CONTRACT; + m_deleteDeferred = true; +} + void EventPipeProvider::RefreshAllEvents() { CONTRACTL diff --git a/src/vm/eventpipeprovider.h b/src/vm/eventpipeprovider.h index 605a82b151..d2c459ef32 100644 --- a/src/vm/eventpipeprovider.h +++ b/src/vm/eventpipeprovider.h @@ -26,6 +26,7 @@ typedef void (*EventPipeCallback)( class EventPipeProvider { // Declare friends. + friend class EventPipe; friend class EventPipeConfiguration; friend class SampleProfiler; @@ -55,9 +56,15 @@ private: // The configuration object. EventPipeConfiguration *m_pConfig; -public: + // True if the provider has been deleted, but that deletion + // has been deferred until tracing is stopped. + bool m_deleteDeferred; + // Private constructor because all providers are created through EventPipe::CreateProvider. EventPipeProvider(const GUID &providerID, EventPipeCallback pCallbackFunction = NULL, void *pCallbackData = NULL); + +public: + ~EventPipeProvider(); // Get the provider ID. @@ -96,6 +103,13 @@ public: // Invoke the provider callback. void InvokeCallback(); + + // Specifies whether or not the provider was deleted, but that deletion + // was deferred until after tracing is stopped. + bool GetDeleteDeferred() const; + + // Defer deletion of the provider. + void SetDeleteDeferred(); }; #endif // FEATURE_PERFTRACING diff --git a/src/vm/sampleprofiler.cpp b/src/vm/sampleprofiler.cpp index c7373bc088..bec757fd66 100644 --- a/src/vm/sampleprofiler.cpp +++ b/src/vm/sampleprofiler.cpp @@ -34,7 +34,7 @@ void SampleProfiler::Enable() if(s_pEventPipeProvider == NULL) { - s_pEventPipeProvider = new EventPipeProvider(s_providerID); + s_pEventPipeProvider = EventPipe::CreateProvider(s_providerID); s_pThreadTimeEvent = s_pEventPipeProvider->AddEvent( 0, /* eventID */ 0, /* keywords */ |