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 GC heap size and count in Runtime metrics #412

Merged
merged 20 commits into from
Jun 11, 2022

Conversation

xiang17
Copy link
Contributor

@xiang17 xiang17 commented Jun 8, 2022

Fixes #335.

Changes

Add gc.heapsize and change gc.count to multi-dimensional metrics

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

@xiang17 xiang17 requested a review from a team June 8, 2022 22:47
@codecov
Copy link

codecov bot commented Jun 8, 2022

Codecov Report

Merging #412 (bf5f62e) into main (5ac01fa) will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #412   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        155     155           
  Lines       4776    4784    +8     
=====================================
- Misses      4776    4784    +8     
Impacted Files Coverage Δ
...elemetry.Instrumentation.Runtime/RuntimeMetrics.cs 0.00% <0.00%> (ø)

Measurement<long>[] measurements = new Measurement<long>[NumberOfGenerations];
for (int i = 0; i < measurements.Length; i++)
{
measurements[i] = new Measurement<long>(GC.CollectionCount(i), new KeyValuePair<string, object>("gen", HeapNames[i]));
Copy link
Member

Choose a reason for hiding this comment

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

"gen" might be too "generic" ?

Copy link
Contributor Author

@xiang17 xiang17 Jun 8, 2022

Choose a reason for hiding this comment

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

I think it won't be if it appears together with a value from ("gen0", "gen1", "gen2", "loh", "poh"). However I'm ok to better name suggestions like "generation" or "generationName".

Can I keep it as is and update this attribute key accordingly once #404 is finalized?

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

@xiang17 xiang17 requested a review from reyang June 10, 2022 22:34
Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

LGTM with some nonblocking clarification questions / suggestions.

# Conflicts:
#	src/OpenTelemetry.Instrumentation.Runtime/CHANGELOG.md
#	src/OpenTelemetry.Instrumentation.Runtime/RuntimeMetrics.cs
return new[]
var generationInfo = GC.GetGCMemoryInfo().GenerationInfo;

Measurement<long>[] measurements = new Measurement<long>[generationInfo.Length];
Copy link
Contributor

@utpilla utpilla Jun 11, 2022

Choose a reason for hiding this comment

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

This will cause allocation. We could either use a pre allocated array/list or make use of the yield return semantic.

Copy link
Contributor Author

@xiang17 xiang17 Jun 11, 2022

Choose a reason for hiding this comment

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

This metrics is an Observable and gets called once every 15~20 seconds. So it's not worth doing too much optimization for now. Most importantly, if there are multiple readers reading it at almost the same time, they could have incorrect values from reading pre allocated shared array.

I've tried to use yield return and it worked for two other methods, however, for this one I got an error. See discussion thread at #412 (comment)

The compile will fail with GetGarbageCollectionHeapSizes because it needs a Span<T>: "CS4013 Instance of type 'ReadOnlySpan' cannot be used inside a nested function, query expression, iterator block or async method".

@utpilla utpilla merged commit 667cf28 into open-telemetry:main Jun 11, 2022
swetharavichandrancisco pushed a commit to swetharavichandrancisco/opentelemetry-dotnet-contrib that referenced this pull request Jun 16, 2022
* Add `gc.heapsize` and change `gc.count` to multi-dimensional metrics
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.

Bringing .NET Runtime metrics instrumentation to Stable
4 participants