Skip to content

Commit 0e71bcf

Browse files
authored
feat: allow setting rundown providers for realtime EventPipe Tracelog (#2169)
* feat: allow setting rundown providers for reatlime eventpipe tracelog * chore: formatting * review change * formatting * chore: docs
1 parent 18e1629 commit 0e71bcf

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/TraceEvent/TraceLog.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using System.Diagnostics;
2626
using System.Diagnostics.Tracing;
2727
using System.IO;
28+
using System.Linq;
2829
using System.Reflection;
2930
using System.Runtime.InteropServices;
3031
using System.Text;
@@ -234,7 +235,9 @@ public static TraceLogEventSource CreateFromEventPipeSession(EventPipeSession se
234235
// rundown events and shut down immediately and feed this as an additional session to the TraceLog.
235236
// Note: it doesn't matter what the actual provider is, just that we request rundown in the constructor.
236237
using (var rundownSession = rundownDiagnosticsClient.StartEventPipeSession(
237-
new EventPipeProvider(ClrTraceEventParser.ProviderName, EventLevel.Informational, (long)ClrTraceEventParser.Keywords.Default),
238+
rundownConfiguration.m_providers?.AsEnumerable() ?? new[]{
239+
new EventPipeProvider(ClrTraceEventParser.ProviderName, EventLevel.Informational, (long)ClrTraceEventParser.Keywords.Default)
240+
},
238241
requestRundown: true
239242
))
240243
{
@@ -251,6 +254,7 @@ public static TraceLogEventSource CreateFromEventPipeSession(EventPipeSession se
251254
public class EventPipeRundownConfiguration
252255
{
253256
internal readonly DiagnosticsClient m_client;
257+
internal List<EventPipeProvider> m_providers;
254258

255259
private EventPipeRundownConfiguration(DiagnosticsClient client) { m_client = client; }
256260

@@ -272,6 +276,20 @@ public static EventPipeRundownConfiguration Enable(DiagnosticsClient client)
272276
{
273277
return new EventPipeRundownConfiguration(client);
274278
}
279+
280+
/// <summary>
281+
/// Adds a provider to use when initializing the rundown session.
282+
/// The first call resets the list, removing the default provider (CLR).
283+
/// You can use this if you need to tune the event level, keywords, etc.
284+
/// </summary>
285+
public void AddProvider(EventPipeProvider provider)
286+
{
287+
if (m_providers == null)
288+
{
289+
m_providers = new List<EventPipeProvider>();
290+
}
291+
m_providers.Add(provider);
292+
}
275293
}
276294

277295
private void ProcessInitialRundown(EventPipeSession session)

0 commit comments

Comments
 (0)