-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[DiagnosticsClient] Update APIs #50376
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
11
commits into
dotnet:main
Choose a base branch
from
mdh1418:add_diagnostics_client_user_events_check_api
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
11 commits
Select commit
Hold shift + click to select a range
e87b288
[DiagnosticsClient] Adjust class protection
mdh1418 ed99927
[DiagnosticsClient] Update StartEventPipeSession APIs
mdh1418 2aaff6a
[DiagnosticsClient] Update WriteDump APIs
mdh1418 993163e
[DiagnosticsClient] Add ApplyStartupHook APIs
mdh1418 9130adc
[DiagnosticsClient] Add PerfMap APIs
mdh1418 2e5e7e1
[DiagnosticsClient] Update DiagnosticsClientExceptions
mdh1418 e4a18ae
[DiagnosticsClient] Update EventPipeSession APIs
mdh1418 f3a1a39
[DiagnosticsClient] Add DiagnosticsClientConnector APIs
mdh1418 d5cf8ce
[DiagnosticsClient] Add SupportsEventPipeUserEventsCommand APIs
mdh1418 eba7f31
Revert "[DiagnosticsClient] Add SupportsEventPipeUserEventsCommand APIs"
mdh1418 f528fdb
Update doc date
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||
| --- | ||||||
| title: Microsoft.Diagnostics.NETCore.Client API | ||||||
| description: In this article, you'll learn about the Microsoft.Diagnostics.NETCore.Client APIs. | ||||||
| ms.date: 06/22/2021 | ||||||
| ms.date: 12/08/2025 | ||||||
| author: tommcdon | ||||||
| ms.author: tommcdon | ||||||
| ms.topic: reference | ||||||
|
|
@@ -14,7 +14,7 @@ This section describes the APIs of the diagnostics client library. | |||||
| ## DiagnosticsClient class | ||||||
|
|
||||||
| ```cs | ||||||
| public DiagnosticsClient | ||||||
| public sealed class DiagnosticsClient | ||||||
| { | ||||||
| public DiagnosticsClient(int processId); | ||||||
|
|
||||||
|
|
@@ -23,23 +23,52 @@ public DiagnosticsClient | |||||
| bool requestRundown = true, | ||||||
| int circularBufferMB = 256); | ||||||
|
|
||||||
| public EventPipeSession StartEventPipeSession( | ||||||
| EventPipeProvider provider, | ||||||
| bool requestRundown = true, | ||||||
| int circularBufferMB = 256); | ||||||
|
|
||||||
| public EventPipeSession StartEventPipeSession( | ||||||
| EventPipeSessionConfiguration config); | ||||||
|
|
||||||
| public Task<EventPipeSession> StartEventPipeSessionAsync( | ||||||
| IEnumerable<EventPipeProvider> providers, | ||||||
| bool requestRundown, | ||||||
| int circularBufferMB = 256, | ||||||
| CancellationToken token = default); | ||||||
|
|
||||||
| public Task<EventPipeSession> StartEventPipeSessionAsync( | ||||||
| EventPipeProvider provider, | ||||||
| bool requestRundown, | ||||||
| int circularBufferMB = 256, | ||||||
| CancellationToken token = default); | ||||||
|
|
||||||
| public Task<EventPipeSession> StartEventPipeSessionAsync( | ||||||
| EventPipeSessionConfiguration configuration, | ||||||
| CancellationToken token); | ||||||
|
|
||||||
| public void WriteDump( | ||||||
| DumpType dumpType, | ||||||
| string dumpPath, | ||||||
| bool logDumpGeneration = false); | ||||||
|
|
||||||
| public async Task WriteDumpAsync( | ||||||
| public void WriteDump( | ||||||
| DumpType dumpType, | ||||||
| string dumpPath, | ||||||
| WriteDumpFlags flags); | ||||||
|
|
||||||
| public Task WriteDumpAsync( | ||||||
| DumpType dumpType, | ||||||
| string dumpPath, | ||||||
| bool logDumpGeneration, | ||||||
| CancellationToken token); | ||||||
|
|
||||||
| public Task WriteDumpAsync( | ||||||
| DumpType dumpType, | ||||||
| string dumpPath, | ||||||
| WriteDumpFlags flags, | ||||||
| CancellationToken token); | ||||||
|
|
||||||
| public void AttachProfiler( | ||||||
| TimeSpan attachTimeout, | ||||||
| Guid profilerGuid, | ||||||
|
|
@@ -58,6 +87,18 @@ public DiagnosticsClient | |||||
|
|
||||||
| public Dictionary<string, string> GetProcessEnvironment(); | ||||||
|
|
||||||
| public void ApplyStartupHook( | ||||||
| string startupHookPath); | ||||||
|
|
||||||
| public Task ApplyStartupHookAsync( | ||||||
| string startupHookPath, | ||||||
| CancellationToken token); | ||||||
|
|
||||||
| public void EnablePerfMap( | ||||||
| PerfMapType type); | ||||||
|
|
||||||
| public void DisablePerfMap(); | ||||||
|
|
||||||
| public static IEnumerable<int> GetPublishedProcesses(); | ||||||
| } | ||||||
| ``` | ||||||
|
|
@@ -79,6 +120,7 @@ public EventPipeSession StartEventPipeSession( | |||||
| IEnumerable<EventPipeProvider> providers, | ||||||
| bool requestRundown = true, | ||||||
| int circularBufferMB = 256); | ||||||
|
|
||||||
| public Task<EventPipeSession> StartEventPipeSessionAsync( | ||||||
| IEnumerable<EventPipeProvider> providers, | ||||||
| bool requestRundown, | ||||||
|
|
@@ -91,17 +133,41 @@ Starts an EventPipe tracing session using the given providers and settings. | |||||
| * `providers` : An `IEnumerable` of [`EventPipeProvider`](#eventpipeprovider-class)s to start tracing. | ||||||
| * `requestRundown`: A `bool` specifying whether rundown provider events from the target app's runtime should be requested. | ||||||
| * `circularBufferMB`: An `int` specifying the total size of circular buffer used by the target app's runtime on collecting events. | ||||||
| * `token` (for the Async overload): The token to monitor for cancellation requests. | ||||||
| * `token` (for the async overload): The token to monitor for cancellation requests. | ||||||
|
|
||||||
| ```csharp | ||||||
| public EventPipeSession StartEventPipeSession(EventPipeProvider provider, bool requestRundown = true, int circularBufferMB = 256) | ||||||
| public Task<EventPipeSession> StartEventPipeSessionAsync(EventPipeProvider provider, bool requestRundown, int circularBufferMB = 256, CancellationToken token = default) | ||||||
| public EventPipeSession StartEventPipeSession( | ||||||
| EventPipeProvider provider, | ||||||
| bool requestRundown = true, | ||||||
| int circularBufferMB = 256); | ||||||
|
|
||||||
| public Task<EventPipeSession> StartEventPipeSessionAsync( | ||||||
| EventPipeProvider provider, | ||||||
| bool requestRundown, | ||||||
| int circularBufferMB = 256, | ||||||
| CancellationToken token = default); | ||||||
| ``` | ||||||
|
|
||||||
| Starts an EventPipe tracing session using a single provider. | ||||||
|
|
||||||
| * `provider` : An [`EventPipeProvider`](#eventpipeprovider-class) to start tracing. | ||||||
| * `requestRundown`: A `bool` specifying whether rundown provider events from the target app's runtime should be requested. | ||||||
| * `circularBufferMB`: An `int` specifying the total size of circular buffer used by the target app's runtime on collecting events. | ||||||
| * `token` (for the Async overload): The token to monitor for cancellation requests. | ||||||
| * `token` (for the async overload): The token to monitor for cancellation requests. | ||||||
|
|
||||||
| ```csharp | ||||||
| public EventPipeSession StartEventPipeSession( | ||||||
| EventPipeSessionConfiguration config); | ||||||
|
|
||||||
| public Task<EventPipeSession> StartEventPipeSessionAsync( | ||||||
| EventPipeSessionConfiguration configuration, | ||||||
| CancellationToken token); | ||||||
| ``` | ||||||
|
|
||||||
| Starts an EventPipe tracing session using an [`EventPipeSessionConfiguration`](#eventpipesessionconfiguration-class). | ||||||
|
|
||||||
| * `config` / `configuration` : An `EventPipeSessionConfiguration` that defines the session. | ||||||
| * `token` (for the async overload): The token to monitor for cancellation requests. | ||||||
|
|
||||||
| > [!NOTE] | ||||||
| > Rundown events contain payloads that may be needed for post analysis, such as resolving method names of thread samples. Unless you know you do not want this, we recommend setting `requestRundown` to true. In large applications, this may take a while. | ||||||
|
|
@@ -122,7 +188,10 @@ Request a dump for post-mortem debugging of the target application. The type of | |||||
| * `logDumpGeneration` : If set to `true`, the target application will write out diagnostic logs during dump generation. | ||||||
|
|
||||||
| ```csharp | ||||||
| public void WriteDump(DumpType dumpType, string dumpPath, WriteDumpFlags flags) | ||||||
| public void WriteDump( | ||||||
| DumpType dumpType, | ||||||
| string dumpPath, | ||||||
| WriteDumpFlags flags) | ||||||
| ``` | ||||||
|
|
||||||
| Request a dump for post-mortem debugging of the target application. The type of the dump can be specified using the [`DumpType`](#dumptype-enum) enum. | ||||||
|
|
@@ -132,7 +201,11 @@ Request a dump for post-mortem debugging of the target application. The type of | |||||
| * `flags` : logging and crash report flags. On runtimes less than 6.0, only LoggingEnabled is supported. | ||||||
|
|
||||||
| ```csharp | ||||||
| public async Task WriteDumpAsync(DumpType dumpType, string dumpPath, bool logDumpGeneration, CancellationToken token) | ||||||
| public Task WriteDumpAsync( | ||||||
| DumpType dumpType, | ||||||
| string dumpPath, | ||||||
| bool logDumpGeneration, | ||||||
| CancellationToken token) | ||||||
| ``` | ||||||
|
|
||||||
| Request a dump for post-mortem debugging of the target application. The type of the dump can be specified using the [`DumpType`](#dumptype-enum) enum. | ||||||
|
|
@@ -143,7 +216,11 @@ Request a dump for post-mortem debugging of the target application. The type of | |||||
| * `token` : The token to monitor for cancellation requests. | ||||||
|
|
||||||
| ```csharp | ||||||
| public async Task WriteDumpAsync(DumpType dumpType, string dumpPath, WriteDumpFlags flags, CancellationToken token) | ||||||
| public Task WriteDumpAsync( | ||||||
| DumpType dumpType, | ||||||
| string dumpPath, | ||||||
| WriteDumpFlags flags, | ||||||
| CancellationToken token) | ||||||
| ``` | ||||||
|
|
||||||
| Request a dump for post-mortem debugging of the target application. The type of the dump can be specified using the [`DumpType`](#dumptype-enum) enum. | ||||||
|
|
@@ -153,6 +230,35 @@ Request a dump for post-mortem debugging of the target application. The type of | |||||
| * `flags` : logging and crash report flags. On runtimes less than 6.0, only LoggingEnabled is supported. | ||||||
| * `token` : The token to monitor for cancellation requests. | ||||||
|
|
||||||
| ### ApplyStartupHook methods | ||||||
|
|
||||||
| ```csharp | ||||||
| public void ApplyStartupHook( | ||||||
| string startupHookPath); | ||||||
|
|
||||||
| public Task ApplyStartupHookAsync( | ||||||
| string startupHookPath, | ||||||
| CancellationToken token); | ||||||
| ``` | ||||||
|
|
||||||
| Loads the specified assembly with a `StartupHook` in the target process. | ||||||
|
|
||||||
| * `startupHookPath` : The path to the assembly containing the startup hook. | ||||||
mdh1418 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| * `token` (for the async overload): The token to monitor for cancellation requests. | ||||||
|
|
||||||
| ### PerfMap methods | ||||||
|
|
||||||
| ```csharp | ||||||
| public void EnablePerfMap( | ||||||
| PerfMapType type); | ||||||
|
|
||||||
| public void DisablePerfMap(); | ||||||
| ``` | ||||||
|
|
||||||
| Controls generation of perf maps in the target process. | ||||||
|
|
||||||
| * `type` : The [`PerfMapType`](#perfmaptype-enum) indicating the type of perf map to enable. | ||||||
gewarren marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| ### AttachProfiler method | ||||||
|
|
||||||
| ```csharp | ||||||
|
|
@@ -220,6 +326,43 @@ public static IEnumerable<int> GetPublishedProcesses(); | |||||
|
|
||||||
| Get an `IEnumerable` of process IDs of all the active .NET processes that can be attached to. | ||||||
|
|
||||||
| ## EventPipeSessionConfiguration class | ||||||
|
|
||||||
| ```csharp | ||||||
| public sealed class EventPipeSessionConfiguration | ||||||
| { | ||||||
| public EventPipeSessionConfiguration( | ||||||
| IEnumerable<EventPipeProvider> providers, | ||||||
| int circularBufferSizeMB = 256, | ||||||
| bool requestRundown = true, | ||||||
| bool requestStackwalk = true); | ||||||
|
|
||||||
| public EventPipeSessionConfiguration( | ||||||
| IEnumerable<EventPipeProvider> providers, | ||||||
| int circularBufferSizeMB, | ||||||
| long rundownKeyword, | ||||||
| bool requestStackwalk = true); | ||||||
|
|
||||||
| public bool RequestRundown { get; } | ||||||
|
|
||||||
| public int CircularBufferSizeInMB { get; } | ||||||
|
|
||||||
| public bool RequestStackwalk { get; } | ||||||
|
|
||||||
| public long RundownKeyword { get; } | ||||||
|
|
||||||
| public IReadOnlyCollection<EventPipeProvider> Providers { get; } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| Represents the configuration for an `EventPipeSession`. | ||||||
|
|
||||||
| * `providers` : An `IEnumerable` of [`EventPipeProvider`](#eventpipeprovider-class)s to enable. | ||||||
| * `circularBufferSizeMB` : The size in MB of the runtime's buffer for collecting events. | ||||||
| * `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. | ||||||
gewarren marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| ## EventPipeProvider class | ||||||
|
|
||||||
| ```cs | ||||||
|
|
@@ -305,28 +448,77 @@ This class is immutable, because EventPipe does not allow a provider's configura | |||||
| public class EventPipeSession : IDisposable | ||||||
| { | ||||||
| public Stream EventStream { get; } | ||||||
|
|
||||||
| public void Stop(); | ||||||
|
|
||||||
| public Task StopAsync( | ||||||
| CancellationToken cancellationToken); | ||||||
|
|
||||||
| public void Dispose(); | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| This class represents an ongoing EventPipe session. It is immutable and acts as a handle to an EventPipe session of the given runtime. | ||||||
|
|
||||||
| ## EventStream property | ||||||
| ### EventStream property | ||||||
|
|
||||||
| ```csharp | ||||||
| public Stream EventStream { get; } | ||||||
| ``` | ||||||
|
|
||||||
| Gets a `Stream` that can be used to read the event stream. | ||||||
|
|
||||||
| ## Stop method | ||||||
| ### Stop methods | ||||||
|
|
||||||
| ```csharp | ||||||
| public void Stop(); | ||||||
|
|
||||||
| public Task StopAsync( | ||||||
| CancellationToken cancellationToken); | ||||||
| ``` | ||||||
|
|
||||||
| Stops the given `EventPipe` session. | ||||||
|
|
||||||
| * `cancellationToken` (for the async overload): The token to monitor for cancellation requests. | ||||||
|
|
||||||
| ### Dispose method | ||||||
|
|
||||||
| ```csharp | ||||||
| public void Dispose(); | ||||||
| ``` | ||||||
|
|
||||||
| Releases resources associated with the `EventPipeSession`. | ||||||
|
|
||||||
| ## DiagnosticsClientConnector class | ||||||
|
|
||||||
| ```csharp | ||||||
| public sealed class DiagnosticsClientConnector : IAsyncDisposable | ||||||
| { | ||||||
| public DiagnosticsClient Instance { get; } | ||||||
|
|
||||||
| public ValueTask DisposeAsync(); | ||||||
|
|
||||||
| public static Task<DiagnosticsClientConnector> FromDiagnosticPort( | ||||||
| string diagnosticPort, | ||||||
| CancellationToken ct); | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| Represents a helper that creates a `DiagnosticsClient` from a diagnostic port and manages the lifetime of the underlying diagnostics server connection. | ||||||
|
|
||||||
| * `Instance` : The `DiagnosticsClient` connected to the target runtime. | ||||||
| * `DisposeAsync` : Disposes the underlying server/connection asynchronously. | ||||||
| * `FromDiagnosticPort` : Creates a new `DiagnosticsClientConnector` from the specified diagnostic port. | ||||||
|
|
||||||
| ```csharp | ||||||
| public static Task<DiagnosticsClientConnector> FromDiagnosticPort( | ||||||
| string diagnosticPort, | ||||||
| CancellationToken ct) | ||||||
| ``` | ||||||
|
|
||||||
| * `diagnosticPort` : The diagnostic port string (for example, a listen or connect port) to connect through. | ||||||
| * `ct` : The token to monitor for cancellation requests. | ||||||
|
|
||||||
| ## DumpType enum | ||||||
|
|
||||||
| ```csharp | ||||||
|
|
@@ -346,6 +538,44 @@ Represents the type of dump that can be requested. | |||||
| * `Triage`: Include just the information necessary to capture stack traces for all existing traces for all existing threads in a process. Limited GC heap memory and information. Some content that is known to contain potentially sensitive information such as full module paths will be redacted. While this is intended to mitigate some cases of sensitive data exposure, there is no guarantee this redaction feature on its own is sufficient to comply with any particular law or standard regarding data privacy. | ||||||
| * `Full`: Include all accessible memory in the process. The raw memory data is included at the end, so that the initial structures can be mapped directly without the raw memory information. This option can result in a very large dump file. | ||||||
|
|
||||||
| ## WriteDumpFlags enum | ||||||
|
|
||||||
| ```csharp | ||||||
| public enum WriteDumpFlags | ||||||
| { | ||||||
| None = 0x00, | ||||||
| LoggingEnabled = 0x01, | ||||||
| VerboseLoggingEnabled = 0x02, | ||||||
| CrashReportEnabled = 0x04 | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| Represents additional options that can be specified when requesting a dump. | ||||||
|
|
||||||
| * `None` : No additional behavior. | ||||||
| * `LoggingEnabled` : Enable basic logging during dump generation. | ||||||
| * `VerboseLoggingEnabled` : Enable verbose logging during dump generation. | ||||||
| * `CrashReportEnabled` : Enable generation of a crash report. | ||||||
gewarren marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| ## PerfMapType enum | ||||||
|
|
||||||
| ```csharp | ||||||
| public enum PerfMapType | ||||||
| { | ||||||
| None = 0, | ||||||
| All = 1, | ||||||
| JitDump = 2, | ||||||
| PerfMap = 3 | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| Represents the type of perf map behavior that can be enabled. | ||||||
|
|
||||||
| * `None` : No perf map output. | ||||||
| * `All` : Enable all perf map outputs supported by the runtime. | ||||||
| * `JitDump` : Enable JIT dump perf map output. | ||||||
| * `PerfMap` : Enable traditional perf map output. | ||||||
mdh1418 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| ## Exceptions | ||||||
|
|
||||||
| Exceptions that are thrown from the library are of type `DiagnosticsClientException` or a derived type. | ||||||
|
|
@@ -385,3 +615,11 @@ public class ServerErrorException : DiagnosticsClientException | |||||
| ``` | ||||||
|
|
||||||
| This may be thrown when the runtime responds with an error to a given command. | ||||||
|
|
||||||
| ### ProfilerAlreadyActiveException | ||||||
|
|
||||||
| ```csharp | ||||||
| public class ProfilerAlreadyActiveException : ServerErrorException | ||||||
| ``` | ||||||
|
|
||||||
| This may be thrown when a profiler is already loaded into the target runtime and another attach is attempted. | ||||||
|
Contributor
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.
Uh oh!
There was an error while loading. Please reload this page.