1// The .NET Foundation licenses this file to you under the MIT license.
2// See the LICENSE file in the project root for more information.
3
4#ifndef __EVENTPIPE_CONFIGURATION_H__
5#define __EVENTPIPE_CONFIGURATION_H__
6
7#ifdef FEATURE_PERFTRACING
8
9#include "eventpipe.h"
10#include "slist.h"
11
12class EventPipeSessionProvider;
13class EventPipeEvent;
14class EventPipeEventInstance;
15class EventPipeProvider;
16struct EventPipeProviderConfiguration;
17class EventPipeSession;
18enum class EventPipeSessionType;
19class EventPipeSessionProvider;
20
21enum class EventPipeEventLevel
22{
23 LogAlways,
24 Critical,
25 Error,
26 Warning,
27 Informational,
28 Verbose
29};
30
31class EventPipeConfiguration
32{
33public:
34
35 EventPipeConfiguration();
36 ~EventPipeConfiguration();
37
38 // Perform initialization that cannot be performed in the constructor.
39 void Initialize();
40
41 // Create a new provider.
42 EventPipeProvider* CreateProvider(const SString &providerName, EventPipeCallback pCallbackFunction, void *pCallbackData);
43
44 // Delete a provider.
45 void DeleteProvider(EventPipeProvider *pProvider);
46
47 // Register a provider.
48 bool RegisterProvider(EventPipeProvider &provider);
49
50 // Unregister a provider.
51 bool UnregisterProvider(EventPipeProvider &provider);
52
53 // Get the provider with the specified provider ID if it exists.
54 EventPipeProvider* GetProvider(const SString &providerID);
55
56 // Create a new session.
57 EventPipeSession* CreateSession(EventPipeSessionType sessionType, unsigned int circularBufferSizeInMB, EventPipeProviderConfiguration *pProviders, unsigned int numProviders, UINT64 multiFileTraceLengthInSeconds = 0);
58
59 // Delete a session.
60 void DeleteSession(EventPipeSession *pSession);
61
62 // Get the configured size of the circular buffer.
63 size_t GetCircularBufferSize() const;
64
65 // Enable a session in the event pipe.
66 void Enable(EventPipeSession *pSession);
67
68 // Disable a session in the event pipe.
69 void Disable(EventPipeSession *pSession);
70
71 // Get the status of the event pipe.
72 bool Enabled() const;
73
74 // Determine if rundown is enabled.
75 bool RundownEnabled() const;
76
77 // Enable rundown using the specified configuration.
78 void EnableRundown(EventPipeSession *pSession);
79
80 // Get the event used to write metadata to the event stream.
81 EventPipeEventInstance* BuildEventMetadataEvent(EventPipeEventInstance &sourceInstance, unsigned int metdataId);
82
83 // Delete deferred providers.
84 void DeleteDeferredProviders();
85
86 // Determine if the specified thread is the rundown thread.
87 // Used during rundown to ignore events from all other threads so that we don't corrupt the trace file.
88 inline bool IsRundownThread(Thread *pThread)
89 {
90 LIMITED_METHOD_CONTRACT;
91
92 return (pThread == m_pRundownThread);
93 }
94
95private:
96
97 // Get the provider without taking the lock.
98 EventPipeProvider* GetProviderNoLock(const SString &providerID);
99
100 // Get the enabled provider.
101 EventPipeSessionProvider* GetSessionProvider(EventPipeSession *pSession, EventPipeProvider *pProvider);
102
103 // The one and only EventPipe session.
104 EventPipeSession *m_pSession;
105
106 // Determines whether or not the event pipe is enabled.
107 Volatile<bool> m_enabled;
108
109 // The list of event pipe providers.
110 SList<SListElem<EventPipeProvider*>> *m_pProviderList;
111
112 // The provider used to write configuration events to the event stream.
113 EventPipeProvider *m_pConfigProvider;
114
115 // The event used to write event information to the event stream.
116 EventPipeEvent *m_pMetadataEvent;
117
118 // The provider name for the configuration event pipe provider.
119 // This provider is used to emit configuration events.
120 const static WCHAR* s_configurationProviderName;
121
122 // True if rundown is enabled.
123 Volatile<bool> m_rundownEnabled;
124
125 // The rundown thread. If rundown is not enabled, this is NULL.
126 Thread *m_pRundownThread;
127};
128
129#endif // FEATURE_PERFTRACING
130
131#endif // __EVENTPIPE_CONFIGURATION_H__
132