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_SESSION_H__
6#define __EVENTPIPE_SESSION_H__
7
8#ifdef FEATURE_PERFTRACING
9
10enum class EventPipeEventLevel;
11struct EventPipeProviderConfiguration;
12class EventPipeSessionProviderList;
13class EventPipeSessionProvider;
14
15enum class EventPipeSessionType
16{
17 File,
18 Streaming
19};
20
21class EventPipeSession
22{
23private:
24 // The set of configurations for each provider in the session.
25 EventPipeSessionProviderList *m_pProviderList;
26
27 // The configured size of the circular buffer.
28 size_t m_circularBufferSizeInBytes;
29
30 // True if rundown is enabled.
31 Volatile<bool> m_rundownEnabled;
32
33 // The type of the session.
34 // This determines behavior within the system (e.g. policies around which events to drop, etc.)
35 EventPipeSessionType m_sessionType;
36
37 // Start date and time in UTC.
38 FILETIME m_sessionStartTime;
39
40 // Start timestamp.
41 LARGE_INTEGER m_sessionStartTimeStamp;
42
43 // The maximum trace length in seconds. Used to determine when to flush the current file and start a new one.
44 UINT64 m_multiFileTraceLengthInSeconds;
45
46public:
47
48 // TODO: This needs to be exposed via EventPipe::CreateSession() and EventPipe::DeleteSession() to avoid memory ownership issues.
49 EventPipeSession(
50 EventPipeSessionType sessionType,
51 unsigned int circularBufferSizeInMB,
52 EventPipeProviderConfiguration *pProviders,
53 unsigned int numProviders,
54 UINT64 multiFileTraceLengthInSeconds);
55
56 ~EventPipeSession();
57
58 // Determine if the session is valid or not. Invalid sessions can be detected before they are enabled.
59 bool IsValid() const;
60
61 // Get the session type.
62 EventPipeSessionType GetSessionType() const
63 {
64 LIMITED_METHOD_CONTRACT;
65 return m_sessionType;
66 }
67
68 // Get the configured size of the circular buffer.
69 size_t GetCircularBufferSize() const
70 {
71 LIMITED_METHOD_CONTRACT;
72 return m_circularBufferSizeInBytes;
73 }
74
75 // Determine if rundown is enabled.
76 bool RundownEnabled() const
77 {
78 LIMITED_METHOD_CONTRACT;
79 return m_rundownEnabled;
80 }
81
82 // Set the rundown enabled flag.
83 void SetRundownEnabled(bool value)
84 {
85 LIMITED_METHOD_CONTRACT;
86 m_rundownEnabled = value;
87 }
88
89 // Get the session start time in UTC.
90 FILETIME GetStartTime() const
91 {
92 LIMITED_METHOD_CONTRACT;
93 return m_sessionStartTime;
94 }
95
96 // Get the session start timestamp.
97 LARGE_INTEGER GetStartTimeStamp() const
98 {
99 LIMITED_METHOD_CONTRACT;
100 return m_sessionStartTimeStamp;
101 }
102
103 UINT64 GetMultiFileTraceLengthInSeconds() const
104 {
105 LIMITED_METHOD_CONTRACT;
106 return m_multiFileTraceLengthInSeconds;
107 }
108
109 // Add a new provider to the session.
110 void AddSessionProvider(EventPipeSessionProvider *pProvider);
111
112 // Get the session provider for the specified provider if present.
113 EventPipeSessionProvider* GetSessionProvider(EventPipeProvider *pProvider);
114};
115
116class EventPipeSessionProviderList
117{
118
119private:
120
121 // The list of providers.
122 SList<SListElem<EventPipeSessionProvider*>> *m_pProviders;
123
124 // A catch-all provider used when tracing is enabled for all events.
125 EventPipeSessionProvider *m_pCatchAllProvider;
126
127public:
128
129 // Create a new list based on the input.
130 EventPipeSessionProviderList(EventPipeProviderConfiguration *pConfigs, unsigned int numConfigs);
131 ~EventPipeSessionProviderList();
132
133 // Add a new session provider to the list.
134 void AddSessionProvider(EventPipeSessionProvider *pProvider);
135
136 // Get the session provider for the specified provider.
137 // Return NULL if one doesn't exist.
138 EventPipeSessionProvider* GetSessionProvider(EventPipeProvider *pProvider);
139
140 // Returns true if the list is empty.
141 bool IsEmpty() const;
142};
143
144class EventPipeSessionProvider
145{
146private:
147
148 // The provider name.
149 WCHAR *m_pProviderName;
150
151 // The enabled keywords.
152 UINT64 m_keywords;
153
154 // The loging level.
155 EventPipeEventLevel m_loggingLevel;
156
157 // The filter data.
158 WCHAR *m_pFilterData;
159
160public:
161
162 EventPipeSessionProvider(
163 LPCWSTR providerName,
164 UINT64 keywords,
165 EventPipeEventLevel loggingLevel,
166 LPCWSTR filterData);
167 ~EventPipeSessionProvider();
168
169 LPCWSTR GetProviderName() const;
170
171 UINT64 GetKeywords() const;
172
173 EventPipeEventLevel GetLevel() const;
174
175 LPCWSTR GetFilterData() const;
176};
177
178#endif // FEATURE_PERFTRACING
179
180#endif // __EVENTPIPE_SESSION_H__
181