1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
7 #include "eventpipeconfiguration.h"
8 #include "eventpipeevent.h"
9 #include "eventpipeprovider.h"
11 #ifdef FEATURE_PERFTRACING
13 EventPipeProvider::EventPipeProvider(const GUID &providerID, EventPipeCallback pCallbackFunction, void *pCallbackData)
23 m_providerID = providerID;
26 m_providerLevel = EventPipeEventLevel::Critical;
27 m_pEventList = new SList<SListElem<EventPipeEvent*>>();
28 m_pCallbackFunction = pCallbackFunction;
29 m_pCallbackData = pCallbackData;
31 // Register the provider.
32 EventPipeConfiguration* pConfig = EventPipe::GetConfiguration();
33 _ASSERTE(pConfig != NULL);
34 pConfig->RegisterProvider(*this);
37 EventPipeProvider::~EventPipeProvider()
47 // Unregister the provider.
48 // This call is re-entrant.
49 EventPipeConfiguration* pConfig = EventPipe::GetConfiguration();
50 _ASSERTE(pConfig != NULL);
51 pConfig->UnregisterProvider(*this);
53 // Free all of the events.
54 if(m_pEventList != NULL)
56 // Take the lock before manipulating the list.
57 CrstHolder _crst(EventPipe::GetLock());
59 SListElem<EventPipeEvent*> *pElem = m_pEventList->GetHead();
62 EventPipeEvent *pEvent = pElem->GetValue();
65 pElem = m_pEventList->GetNext(pElem);
73 const GUID& EventPipeProvider::GetProviderID() const
75 LIMITED_METHOD_CONTRACT;
80 bool EventPipeProvider::Enabled() const
82 LIMITED_METHOD_CONTRACT;
87 bool EventPipeProvider::EventEnabled(INT64 keywords) const
89 LIMITED_METHOD_CONTRACT;
91 // The event is enabled if:
92 // - The provider is enabled.
93 // - The event keywords are unspecified in the manifest (== 0) or when masked with the enabled config are != 0.
94 return (Enabled() && ((keywords == 0) || ((m_keywords & keywords) != 0)));
97 bool EventPipeProvider::EventEnabled(INT64 keywords, EventPipeEventLevel eventLevel) const
99 LIMITED_METHOD_CONTRACT;
101 // The event is enabled if:
102 // - The provider is enabled.
103 // - The event keywords are unspecified in the manifest (== 0) or when masked with the enabled config are != 0.
104 // - The event level is LogAlways or the provider's verbosity level is set to greater than the event's verbosity level in the manifest.
105 return (EventEnabled(keywords) &&
106 ((eventLevel == EventPipeEventLevel::LogAlways) || (m_providerLevel >= eventLevel)));
109 void EventPipeProvider::SetConfiguration(bool providerEnabled, INT64 keywords, EventPipeEventLevel providerLevel)
116 PRECONDITION(EventPipe::GetLock()->OwnedByCurrentThread());
120 m_enabled = providerEnabled;
121 m_keywords = keywords;
122 m_providerLevel = providerLevel;
128 EventPipeEvent* EventPipeProvider::AddEvent(INT64 keywords, unsigned int eventID, unsigned int eventVersion, EventPipeEventLevel level, bool needStack)
139 EventPipeEvent *pEvent = new EventPipeEvent(
147 // Add it to the list of events.
152 void EventPipeProvider::AddEvent(EventPipeEvent &event)
162 // Take the config lock before inserting a new event.
163 CrstHolder _crst(EventPipe::GetLock());
165 m_pEventList->InsertTail(new SListElem<EventPipeEvent*>(&event));
168 void EventPipeProvider::InvokeCallback()
175 PRECONDITION(EventPipe::GetLock()->OwnedByCurrentThread());
179 if(m_pCallbackFunction != NULL && !g_fEEShutDown)
181 (*m_pCallbackFunction)(
184 (UCHAR) m_providerLevel,
186 0 /* matchAllKeywords */,
187 NULL /* FilterData */,
188 m_pCallbackData /* CallbackContext */);
192 void EventPipeProvider::RefreshAllEvents()
199 PRECONDITION(EventPipe::GetLock()->OwnedByCurrentThread());
203 SListElem<EventPipeEvent*> *pElem = m_pEventList->GetHead();
206 EventPipeEvent *pEvent = pElem->GetValue();
207 pEvent->RefreshState();
209 pElem = m_pEventList->GetNext(pElem);
213 #endif // FEATURE_PERFTRACING