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

[Instrumentation.Runtime] Change API for GC Heap Size #495

Merged
merged 12 commits into from
Jul 19, 2022

Conversation

xiang17
Copy link
Contributor

@xiang17 xiang17 commented Jul 8, 2022

Changes

Use internal method GC.GetGenerationSize for GC Heap Size.

.NET 6.0 has a bug in computing those generation sizes for the GC.GetGCMemoryInfo() API and it was fixed in .NET 7.

Note that the heap sizes are not retrieved in one transactional query with GC.GetGCMemoryInfo(). It'd be better to change it back to GC.GetGCMemoryInfo().GenerationInfo[i].SizeAfterBytes for .NET 7 when appropriate.

For significant contributions please make sure you have completed the following items:

@xiang17 xiang17 requested a review from a team as a code owner July 8, 2022 23:27
@codecov
Copy link

codecov bot commented Jul 8, 2022

Codecov Report

Merging #495 (2af64eb) into main (d8ab64a) will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #495   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        167     167           
  Lines       5084    5098   +14     
=====================================
- Misses      5084    5098   +14     
Impacted Files Coverage Δ
...elemetry.Instrumentation.Runtime/RuntimeMetrics.cs 0.00% <0.00%> (ø)

Copy link
Contributor

@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.

Aside from the comments inline, LGTM : )

error SA1025: Code should not contain multiple whitespace characters in a row
error SA1108: Block statements should not contain embedded comments
@utpilla utpilla added the comp:instrumentation.runtime Things related to OpenTelemetry.Instrumentation.Runtime label Jul 11, 2022
() =>
// GC.GetGCMemoryInfo().GenerationInfo[i].SizeAfterBytes is better but it has a bug in .NET 6. See context in https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/496
Func<int, ulong> getGenerationSize = null;
bool isCodeRunningOnBuggyRuntimeVersion = Environment.Version.Major == 6;
Copy link
Member

Choose a reason for hiding this comment

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

I understand that this code is guarded by #if NET6_0_OR_GREATER, I wonder if we should change == 6 to <= 6 (although both would give the exact same results) just to express the intention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My intention was to "check to avoid the buggy API on certain Runtime version" (only 6 and forward has this new API and only 6 has bug, thus the variable name), but not to "use GC.GetGenerationSize whenever possible".

In fact, if I go with the intention of the latter, I'd think whether we could add the metric for more Runtime versions whenever GC.GetGenerationSize is available. However, I don't think it's a good idea, because it would be a change of the spec and this API is not an official API.

@cijothomas
Copy link
Member

Please add changelog entry

@xiang17
Copy link
Contributor Author

xiang17 commented Jul 15, 2022

Please add changelog entry

Added.

@cijothomas cijothomas merged commit 25f3c43 into open-telemetry:main Jul 19, 2022
@cijothomas
Copy link
Member

Looks good with this change:

image

@xiang17 xiang17 deleted the xiang17/fixGCHeapSizeAPI branch July 20, 2022 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.runtime Things related to OpenTelemetry.Instrumentation.Runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants