610d76d8bf66f97cde4c37ba3e19329acc51691f
[platform/upstream/coreclr.git] / src / vm / eventpipeprovider.h
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.
4
5 #ifndef __EVENTPIPE_PROVIDER_H__
6 #define __EVENTPIPE_PROVIDER_H__
7
8 #ifdef FEATURE_PERFTRACING
9
10 #include "slist.h"
11
12 class EventPipeEvent;
13
14 // Define the event pipe callback to match the ETW callback signature.
15 typedef void (*EventPipeCallback)(
16     LPCGUID SourceID,
17     ULONG IsEnabled,
18     UCHAR Level,
19     ULONGLONG MatchAnyKeywords,
20     ULONGLONG MatchAllKeywords,
21     void *FilterData,
22     void *CallbackContext);
23
24 enum class EventPipeEventLevel
25 {
26     LogAlways,
27     Critical,
28     Error,
29     Warning,
30     Informational,
31     Verbose
32 };
33
34 class EventPipeProvider
35 {
36     // Declare friends.
37     friend class EventPipeConfiguration;
38
39 private:
40     // The GUID of the provider.
41     GUID m_providerID;
42
43     // True if the provider is enabled.
44     bool m_enabled;
45
46     // Bit vector containing the currently enabled keywords.
47     INT64 m_keywords;
48
49     // The current verbosity of the provider.
50     EventPipeEventLevel m_providerLevel;
51
52     // List of every event currently associated with the provider.
53     // New events can be added on-the-fly.
54     SList<SListElem<EventPipeEvent*>> *m_pEventList;
55
56     // The optional provider callback.
57     EventPipeCallback m_pCallbackFunction;
58
59     // The optional provider callback data pointer.
60     void *m_pCallbackData;
61
62 public:
63
64     EventPipeProvider(const GUID &providerID);
65     ~EventPipeProvider();
66
67     // Get the provider ID.
68     const GUID& GetProviderID() const;
69
70     // Determine if the provider is enabled.
71     bool Enabled() const;
72
73     // Determine if the specified keywords are enabled.
74     bool EventEnabled(INT64 keywords) const;
75
76     // Determine if the specified keywords and level match the configuration.
77     bool EventEnabled(INT64 keywords, EventPipeEventLevel eventLevel) const;
78
79     // Create a new event.
80     EventPipeEvent* AddEvent(INT64 keywords, unsigned int eventID, unsigned int eventVersion, EventPipeEventLevel level, bool needStack);
81
82     // Register a callback with the provider to be called on state change.
83     void RegisterCallback(EventPipeCallback pCallbackFunction, void *pData);
84
85     // Unregister a callback.
86     void UnregisterCallback(EventPipeCallback pCallbackFunction);
87
88 private:
89
90     // Add an event to the provider.
91     void AddEvent(EventPipeEvent &event);
92
93     // Set the provider configuration (enable and disable sets of events).
94     // This is called by EventPipeConfiguration.
95     void SetConfiguration(bool providerEnabled, INT64 keywords, EventPipeEventLevel providerLevel);
96
97     // Refresh the runtime state of all events.
98     void RefreshAllEvents();
99
100     // Invoke the provider callback.
101     void InvokeCallback();
102 };
103
104 #endif // FEATURE_PERFTRACING
105
106 #endif // __EVENTPIPE_PROVIDER_H__