Skip to content
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

[Parameter Capturing] Support sending messages to managed in-proc features from dotnet-monitor #4775

Conversation

schmittjoseph
Copy link
Member

@schmittjoseph schmittjoseph commented Jun 28, 2023

Summary

This PR introduces new infrastructure to support sending messages (with arbitrary managed object payloads) from dotnet-monitor to our in-process features either in the StartupHook or the HostingStartup assemblies.

Overview:

  • The existing profiler communication channel has been upgraded to support arbitrarily sized payloads. Previously it only support sending a simple int32 payload.
  • Managed objects are serialized/deserialized as a utf8-encoded json string. They are NOT deserialized by native code. They are serialized & deserialized using System.Text.Json.
    • As a result, messages intended purely for the profiler (e.g. callstacks) do not support these json payloads.

Example flow of sending a managed->managed message:

  1. [in-proc] When the startup hook loads and initializes, it pinvokes into the profiler and register a callback to be notified of messages (iff the profiler is available).
  2. [in-proc] Any in-proc features interested in receiving messages register a callback with MonitorMessageDispatcher for a given command and its payload object type.
  3. [dotnet-monitor] A message is sent using the profiler channel, containing a specific command with a managed object as the payload.
  4. [dotnet-monitor] The managed object is serialized as a utf8-encoded json string and sent to the profiler.
  5. [in-proc] The profiler receives the message, and sees that no native features are interested in the command, and so it lets our managed code try to handle it by reverse pinvoking the previously registered callback (if present).
  6. [in-proc] The startup hook receives the message and checks if any in-proc features are interested in the command. If so, the utf8-json string is deserialized using the previously registered type and then invokes the registered callback.

Out of scope of this PR:

  • The ability to unregister a message callback with the profiler. We currently don't have a scenario that needs this functionality.
  • Allowing payloads bigger than INT32_MAX.
  • Sending back the status (profiler->dotnet-monitor) of the action taken by a message. Currently the status sent back is merely an ACK/NACK.
Release Notes Entry

@ghost ghost added the needs-review label Jun 28, 2023
@schmittjoseph schmittjoseph changed the title [draft] [Parameter Capturing] Support sending messages to managed in-proc features from dotnet-monitor [Parameter Capturing] Support sending messages to managed in-proc features from dotnet-monitor Jun 28, 2023
@schmittjoseph schmittjoseph marked this pull request as ready for review June 28, 2023 18:46
@schmittjoseph schmittjoseph requested a review from a team as a code owner June 28, 2023 18:46
@ghost ghost removed the needs-review label Jun 29, 2023
@schmittjoseph schmittjoseph marked this pull request as draft June 29, 2023 18:19
@schmittjoseph schmittjoseph marked this pull request as ready for review June 29, 2023 18:24
@ghost ghost added the needs-review label Jun 29, 2023
@ghost ghost removed the needs-review label Jun 29, 2023
@ghost ghost added the needs-review label Jun 30, 2023
@ghost ghost added the needs-review label Jun 30, 2023
@ghost ghost removed the needs-review label Jun 30, 2023
@ghost ghost added the needs-review label Jul 7, 2023
@ghost ghost removed the needs-review label Jul 12, 2023
wiktork
wiktork previously approved these changes Jul 12, 2023
@ghost ghost removed the needs-review label Jul 12, 2023
@schmittjoseph schmittjoseph enabled auto-merge (squash) July 12, 2023 17:30
@schmittjoseph schmittjoseph merged commit 655ad56 into dotnet:feature/parameter-capturing Jul 12, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants