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)
23 m_providerID = providerID;
26 m_providerLevel = EventPipeEventLevel::Critical;
27 m_pEventList = new SList<SListElem<EventPipeEvent*>>();
28 m_pCallbackFunction = NULL;
29 m_pCallbackData = NULL;
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::RegisterCallback(EventPipeCallback pCallbackFunction, void *pData)
178 // Take the config lock before setting the callback.
179 CrstHolder _crst(EventPipe::GetLock());
181 if(m_pCallbackFunction == NULL)
183 m_pCallbackFunction = pCallbackFunction;
184 m_pCallbackData = pData;
188 void EventPipeProvider::UnregisterCallback(EventPipeCallback pCallbackFunction)
198 // Take the config lock before setting the callback.
199 CrstHolder _crst(EventPipe::GetLock());
201 if(m_pCallbackFunction == pCallbackFunction)
203 m_pCallbackFunction = NULL;
204 m_pCallbackData = NULL;
208 void EventPipeProvider::InvokeCallback()
215 PRECONDITION(EventPipe::GetLock()->OwnedByCurrentThread());
219 if(m_pCallbackFunction != NULL)
221 (*m_pCallbackFunction)(
224 (UCHAR) m_providerLevel,
226 0 /* matchAllKeywords */,
227 NULL /* FilterData */,
228 m_pCallbackData /* CallbackContext */);
232 void EventPipeProvider::RefreshAllEvents()
239 PRECONDITION(EventPipe::GetLock()->OwnedByCurrentThread());
243 SListElem<EventPipeEvent*> *pElem = m_pEventList->GetHead();
246 EventPipeEvent *pEvent = pElem->GetValue();
247 pEvent->RefreshState();
249 pElem = m_pEventList->GetNext(pElem);
253 #endif // FEATURE_PERFTRACING