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

Add runtime metrics #1

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft

Add runtime metrics #1

wants to merge 20 commits into from

Conversation

stevejgordon
Copy link
Owner

@stevejgordon stevejgordon commented Jun 26, 2024

WIP implementation for runtime metrics. Opening a PR in my fork to discuss initial technical details before this is ready for a final PR when the semantic conventions are stabilised.

@stevejgordon
Copy link
Owner Author

stevejgordon commented Jun 26, 2024

@noahfalk This is an initial stab at porting the runtime metrics from the contrib library. I've slightly tweaked to optimize the code, and I've been able to remove some redundant code that handles older .NET versions in the contrib codebase. I'm running into after building everything with:

.\build.cmd clr+libs -rc Release

I can't use the ThreadPool class because it says it's unavailable in .NET 9.

image

Any idea what's causing that?

EDIT: Issue solved

@stevejgordon
Copy link
Owner Author

I think I figured out the above with some tweaks to the csproj file. Pushing those changes so we can discuss.

@stevejgordon
Copy link
Owner Author

Testing runtime metrics can be kinda tricky. I've added an initial POC for a test, although it might be a bit brittle at the moment as a GC could occur at any point during the test. Will harden that up if we feel tests like this are practical.

Copy link

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good overall! A few things top of mind:

  • The checkin deadline for .NET 9 feature complete is next Thursday (the 18th) so we don't have much time left. Ideally we'd want to have a near final PR up this week to ensure some random CI failure or responding to a bit of PR feedback doesn't take this to the wire.
  • I've been reviewing the semantic conventions PR and made a few more comments about some hopefully small changes.
  • Tests are certainly nice, but if you have to make a tradeoff between getting this done before the deadline and having more/better tests, lets prioritize the deadline.

Thanks!

<Reference Include="System.Diagnostics.Tracing" />
<Reference Include="System.Memory" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Thread" />
<Reference Include="System.Threading.ThreadPool" />
<Reference Include="System.ComponentModel.Primitives" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, what needed us to add ComponentModel.Primitives?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be needed for Process.GetCurrentProcess()

image


instrumentRecorder.RecordObservableInstruments();

(bool success, IReadOnlyList<Measurement<long>> measurements) = await WaitForMeasurements(instrumentRecorder, GC.MaxGeneration + 1, token);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we'd need to wait here? Other than exceptions it looks like every other metric is observable so I'd expect that all the measurements would have been received during the RecordObservableInstruments() call.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On some runs, I saw the tests fail. I suspected that while RecordObservableInstruments returned and recorded everything, the OnMeasurementRecorded callback may not have queued them all at the point the code accessed the measurements. This solution might be a bit overengineered, though. A 50ms delay is probably sufficient to avoid this risk. I'll try that and we can see how it runs in CI.

@stevejgordon
Copy link
Owner Author

stevejgordon commented Jul 10, 2024

This looks pretty good overall! A few things top of mind:

  • The checkin deadline for .NET 9 feature complete is next Thursday (the 18th) so we don't have much time left. Ideally we'd want to have a near final PR up this week to ensure some random CI failure or responding to a bit of PR feedback doesn't take this to the wire.
  • I've been reviewing the semantic conventions PR and made a few more comments about some hopefully small changes.
  • Tests are certainly nice, but if you have to make a tradeoff between getting this done before the deadline and having more/better tests, lets prioritize the deadline.

Thanks!

Thanks for the feedback, @noahfalk. I've updated per your suggestions and added a bunch of extra tests. On my side, I think this is ready to go to a PR in the runtime, so I'll open it as a draft there so the CI can run.

EDIT: See dotnet#104680

stevejgordon pushed a commit that referenced this pull request Sep 19, 2024
* bug #1: don't allow for values out of the SerializationRecordType enum range

* bug dotnet#2: throw SerializationException rather than KeyNotFoundException when the referenced record is missing or it points to a record of different type

* bug dotnet#3: throw SerializationException rather than FormatException when it's being thrown by BinaryReader (or sth else that we use)

* bug dotnet#4: document the fact that IOException can be thrown

* bug dotnet#5: throw SerializationException rather than OverflowException when parsing the decimal fails

* bug dotnet#6: 0 and 17 are illegal values for PrimitiveType enum

* bug dotnet#7: throw SerializationException when a surrogate character is read (so far an ArgumentException was thrown)
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.

4 participants