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

Metrics: MetricPointValueStorage explicit layout struct #2694

Merged
merged 1 commit into from
Nov 28, 2021

Conversation

CodeBlanch
Copy link
Member

Changes

Added MetricPointValueStorage to store the values needed by MetricPoint. MetricPointValueStorage is basically a union where the same bytes are used for either long or double modes.

Details

Before we had 3 longs & 3 doubles (48 bytes) for all MetricPoints and then an additional 16 bytes (long Count + double Sum) for histograms. This should give us a fixed 32 bytes for all types of MetricPoints.

I also tried to improve the clarity of the code by renaming things from "val"/"value" style to "current"/"snapshot" style.

@CodeBlanch CodeBlanch requested a review from a team November 27, 2021 19:01
@codecov
Copy link

codecov bot commented Nov 27, 2021

Codecov Report

Merging #2694 (401898d) into main (580a2a5) will increase coverage by 0.03%.
The diff coverage is 88.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2694      +/-   ##
==========================================
+ Coverage   82.88%   82.92%   +0.03%     
==========================================
  Files         249      249              
  Lines        8708     8704       -4     
==========================================
  Hits         7218     7218              
+ Misses       1490     1486       -4     
Impacted Files Coverage Δ
src/OpenTelemetry/Metrics/HistogramBuckets.cs 100.00% <ø> (ø)
src/OpenTelemetry/Metrics/MetricPoint.cs 85.00% <88.37%> (-0.49%) ⬇️
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 74.76% <0.00%> (+2.80%) ⬆️
...ZPages/Implementation/ZPagesExporterEventSource.cs 62.50% <0.00%> (+6.25%) ⬆️

@cijothomas cijothomas merged commit 494af25 into open-telemetry:main Nov 28, 2021
@utpilla
Copy link
Contributor

utpilla commented Nov 28, 2021

secondaryValue.Snapshot used for Histogram sum is only used by Histogram types. Should we move it to HistogramBuckets instead? (Add another struct explicitly laid out for a single long or double field?) Currently, we will assign 8 bytes of memory taken up this for all types of MetricPoint.

@CodeBlanch CodeBlanch deleted the metricpoint-valuestorage branch November 29, 2021 18:15
@CodeBlanch
Copy link
Member Author

@utpilla I'm not opposed to that. For counters & gauges, there is a null pointer to HistogramBuckets on the MetricPoint struct. Even though it is null, those structs still have to pay for the storage of the pointer. I think it is sizeof(IntPtr) which is 4 bytes on 32bit and 8 bytes on 64bit. Not 100% sure about that. If we could use those 8 bytes we're holding for the pointer for the "lastValue" delta stuff (and move the sum tracking completely into HistogramBuckets) we could save another 16 bytes for all counters & gauges (eliminate secondardValue, basically). I was going to mess with that, but feel free to give it a shot.

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