-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[Diagnostics] Add EventPipe Buffer Mode and EventFilter #54631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mdh1418
wants to merge
5
commits into
dotnet:main
Choose a base branch
from
mdh1418:eventpipe-non-lossy-buffering-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e99af79
Document EventPipe buffering mode and Event ID filter client APIs
mdh1418 32ff3aa
Document --buffering-mode for dotnet-gcdump and dotnet-trace
mdh1418 9700933
Document non-lossy EventPipe buffering environment variables
mdh1418 b8b466e
Sync buffering-mode docs to latest diagnostics and runtime changes
mdh1418 161d70c
Fix punctuation in dotnet-gcdump non-lossy buffering note
mdh1418 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,10 +1,11 @@ | ||||||
| --- | ||||||
| title: Microsoft.Diagnostics.NETCore.Client API | ||||||
| description: In this article, you'll learn about the Microsoft.Diagnostics.NETCore.Client APIs. | ||||||
| ms.date: 12/08/2025 | ||||||
| ms.date: 07/09/2026 | ||||||
| author: tommcdon | ||||||
| ms.author: tommcdon | ||||||
| ms.topic: reference | ||||||
| ai-usage: ai-assisted | ||||||
| --- | ||||||
|
|
||||||
| # Microsoft.Diagnostics.NETCore.Client API | ||||||
|
|
@@ -343,6 +344,13 @@ public sealed class EventPipeSessionConfiguration | |||||
| long rundownKeyword, | ||||||
| bool requestStackwalk = true); | ||||||
|
|
||||||
| public EventPipeSessionConfiguration( | ||||||
| IEnumerable<EventPipeProvider> providers, | ||||||
| int circularBufferSizeMB, | ||||||
| long rundownKeyword, | ||||||
| bool requestStackwalk, | ||||||
| EventPipeBufferingMode bufferingMode); | ||||||
|
|
||||||
| public bool RequestRundown { get; } | ||||||
|
|
||||||
| public int CircularBufferSizeInMB { get; } | ||||||
|
|
@@ -351,6 +359,8 @@ public sealed class EventPipeSessionConfiguration | |||||
|
|
||||||
| public long RundownKeyword { get; } | ||||||
|
|
||||||
| public EventPipeBufferingMode BufferingMode { get; } | ||||||
|
|
||||||
| public IReadOnlyCollection<EventPipeProvider> Providers { get; } | ||||||
| } | ||||||
| ``` | ||||||
|
|
@@ -362,6 +372,9 @@ Represents the configuration for an `EventPipeSession`. | |||||
| * `requestRundown` : If `true`, request rundown events from the runtime. | ||||||
| * `requestStackwalk` : If `true`, record a stack trace for every emitted event. | ||||||
| * `rundownKeyword` : The keyword mask used for rundown events. | ||||||
| * `bufferingMode` : The [`EventPipeBufferingMode`](#eventpipebufferingmode-enum) for the session. Use `Block` to request non-lossy collection. Passing `Block` requires a .NET 11+ target runtime; on an older runtime, `StartEventPipeSession` throws [`UnsupportedCommandException`](#unsupportedcommandexception). | ||||||
|
|
||||||
| The `BufferingMode` property returns the buffering mode for the session. The default value, `Drop`, keeps the runtime's lossy circular buffer. | ||||||
|
|
||||||
| ## EventPipeProvider class | ||||||
|
|
||||||
|
|
@@ -374,6 +387,13 @@ public class EventPipeProvider | |||||
| long keywords = 0, | ||||||
| IDictionary<string, string> arguments = null) | ||||||
|
|
||||||
| public EventPipeProvider( | ||||||
| string name, | ||||||
| EventLevel eventLevel, | ||||||
| long keywords, | ||||||
| IDictionary<string, string> arguments, | ||||||
| EventPipeProviderEventFilter eventFilter) | ||||||
|
|
||||||
| public string Name { get; } | ||||||
|
|
||||||
| public EventLevel EventLevel { get; } | ||||||
|
|
@@ -382,6 +402,8 @@ public class EventPipeProvider | |||||
|
|
||||||
| public IDictionary<string, string> Arguments { get; } | ||||||
|
|
||||||
| public EventPipeProviderEventFilter EventFilter { get; } | ||||||
|
|
||||||
| public override string ToString(); | ||||||
|
|
||||||
| public override bool Equals(object obj); | ||||||
|
|
@@ -402,9 +424,16 @@ public EventPipeProvider( | |||||
| EventLevel eventLevel, | ||||||
| long keywords = 0, | ||||||
| IDictionary<string, string> arguments = null) | ||||||
|
|
||||||
| public EventPipeProvider( | ||||||
| string name, | ||||||
| EventLevel eventLevel, | ||||||
| long keywords, | ||||||
| IDictionary<string, string> arguments, | ||||||
| EventPipeProviderEventFilter eventFilter) | ||||||
| ``` | ||||||
|
|
||||||
| Creates a new instance of `EventPipeProvider` with the given provider name, <xref:System.Diagnostics.Tracing.EventLevel>, keywords, and arguments. | ||||||
| Creates a new instance of `EventPipeProvider` with the given provider name, <xref:System.Diagnostics.Tracing.EventLevel>, keywords, and arguments. The second overload also takes an [`EventPipeProviderEventFilter`](#eventpipeprovidereventfilter-class) that filters which Event IDs the runtime enables for the provider. When you set an event filter, the session requires a .NET 10+ target runtime. | ||||||
|
|
||||||
| ### Name property | ||||||
|
|
||||||
|
|
@@ -438,10 +467,64 @@ public IDictionary<string, string> Arguments { get; } | |||||
|
|
||||||
| Gets an `IDictionary` of key-value pair strings representing optional arguments to be passed to `EventSource` representing the given `EventPipeProvider`. | ||||||
|
|
||||||
| ### EventFilter property | ||||||
|
|
||||||
| ```csharp | ||||||
| public EventPipeProviderEventFilter EventFilter { get; } | ||||||
| ``` | ||||||
|
|
||||||
| Gets the optional [`EventPipeProviderEventFilter`](#eventpipeprovidereventfilter-class) that the runtime applies to this provider's Event IDs after the keyword and level filter. When the value is `null`, the runtime enables every Event ID that the keyword and level filter allows. | ||||||
|
|
||||||
| ### Remarks | ||||||
|
|
||||||
| This class is immutable, because EventPipe does not allow a provider's configuration to be modified during an EventPipe session as of .NET Core 3.1. | ||||||
|
|
||||||
| ## EventPipeProviderEventFilter class | ||||||
|
|
||||||
| ```csharp | ||||||
| public sealed class EventPipeProviderEventFilter | ||||||
| { | ||||||
| public EventPipeProviderEventFilter( | ||||||
| bool enable, | ||||||
| IReadOnlyList<uint> eventIds); | ||||||
|
|
||||||
| public bool Enable { get; } | ||||||
|
|
||||||
| public IReadOnlyList<uint> EventIds { get; } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| Represents an optional per-provider filter on Event IDs. The runtime applies the filter after the keyword and level filter of the associated [`EventPipeProvider`](#eventpipeprovider-class). Event filters require a .NET 10+ target runtime. | ||||||
|
|
||||||
| ### Constructor | ||||||
|
|
||||||
| ```csharp | ||||||
| public EventPipeProviderEventFilter( | ||||||
| bool enable, | ||||||
| IReadOnlyList<uint> eventIds); | ||||||
| ``` | ||||||
|
|
||||||
| Creates a new instance of `EventPipeProviderEventFilter`. | ||||||
|
|
||||||
| * `enable` : If `true`, `eventIds` is an allow-list and the runtime enables only those Event IDs. If `false`, `eventIds` is a deny-list and the runtime enables every Event ID except those listed. An empty deny-list therefore enables all events. | ||||||
| * `eventIds` : The Event IDs to enable or disable, as determined by `enable`. | ||||||
|
|
||||||
| ### Enable property | ||||||
|
|
||||||
| ```csharp | ||||||
| public bool Enable { get; } | ||||||
| ``` | ||||||
|
|
||||||
| Gets a value that indicates whether [`EventIds`](#eventids-property) is an allow-list (`true`) or a deny-list (`false`). | ||||||
|
|
||||||
| ### EventIds property | ||||||
|
|
||||||
| ```csharp | ||||||
| public IReadOnlyList<uint> EventIds { get; } | ||||||
| ``` | ||||||
|
|
||||||
| Gets the list of Event IDs that the filter enables or disables. | ||||||
|
|
||||||
| ## EventPipeSession class | ||||||
|
|
||||||
| ```csharp | ||||||
|
|
@@ -576,22 +659,29 @@ Represents the type of perf map behavior that can be enabled. | |||||
| * `JitDump` : Enable JIT dump perf map output. | ||||||
| * `PerfMap` : Enable traditional perf map output. | ||||||
|
|
||||||
| ## Exceptions | ||||||
|
|
||||||
| Exceptions that are thrown from the library are of type `DiagnosticsClientException` or a derived type. | ||||||
| ## EventPipeBufferingMode enum | ||||||
|
|
||||||
| ```csharp | ||||||
| public class DiagnosticsClientException : Exception | ||||||
| public enum EventPipeBufferingMode | ||||||
| { | ||||||
| Drop = 0, | ||||||
| Block = 1 | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ### UnsupportedCommandException | ||||||
| Controls how the runtime's per-session event buffer behaves when it fills faster than the session drains it. | ||||||
|
|
||||||
| * `Drop` : The runtime default. The session uses a circular buffer that drops events when it overflows, so collection is lossy. | ||||||
| * `Block` : Non-lossy collection. The runtime blocks event producers when the buffer is full instead of dropping events. Use it for collections that must be complete, such as a heap snapshot on a large heap. `Block` is non-lossy only up to the buffer's capacity, not against host memory exhaustion: if the runtime can't allocate the memory it needs to reserve buffer space, or during session shutdown, it drops the event instead of blocking. `Block` requires a .NET 11+ target runtime; on an older runtime, starting the session throws [`UnsupportedCommandException`](#unsupportedcommandexception). | ||||||
|
|
||||||
| ## Exceptions | ||||||
|
|
||||||
| Exceptions that are thrown from the library are of type `DiagnosticsClientException` or a derived type. | ||||||
|
|
||||||
| ```csharp | ||||||
| public class UnsupportedCommandException : DiagnosticsClientException | ||||||
| public class DiagnosticsClientException : Exception | ||||||
| ``` | ||||||
|
|
||||||
| This may be thrown when the command is not supported by either the library or the target process's runtime. | ||||||
|
|
||||||
| ### UnsupportedProtocolException | ||||||
|
|
||||||
| ```csharp | ||||||
|
|
@@ -616,10 +706,26 @@ public class ServerErrorException : DiagnosticsClientException | |||||
|
|
||||||
| This may be thrown when the runtime responds with an error to a given command. | ||||||
|
|
||||||
| ### UnsupportedCommandException | ||||||
|
|
||||||
| ```csharp | ||||||
| public class UnsupportedCommandException : ServerErrorException | ||||||
| ``` | ||||||
|
|
||||||
| This may be thrown when the command is not supported by either the library or the target process's runtime. | ||||||
|
|
||||||
| ### ProfilerAlreadyActiveException | ||||||
|
|
||||||
| ```csharp | ||||||
| public class ProfilerAlreadyActiveException : ServerErrorException | ||||||
| ``` | ||||||
|
|
||||||
| This exception is thrown when a profiler is already loaded into the target runtime and another attach is attempted. | ||||||
|
|
||||||
| ### BadEncodingException | ||||||
|
|
||||||
| ```csharp | ||||||
| public class BadEncodingException : ServerErrorException | ||||||
| ``` | ||||||
|
|
||||||
| This is thrown when the target runtime can't decode the command payload and rejects it. From a well-formed client, it usually means the runtime is too old to understand a newer configured option value, so it rejects the request while parsing. | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.