16
16
17
17
namespace OpenTelemetry . Metrics
18
18
{
19
+ /// <summary>
20
+ /// A collection of <see cref="HistogramBucket"/>s associated with a histogram metric type.
21
+ /// </summary>
22
+ // Note: Does not implement IEnumerable<> to prevent accidental boxing.
19
23
public class HistogramBuckets
20
24
{
21
- internal readonly long [ ] BucketCounts ;
25
+ internal readonly double [ ] ExplicitBounds ;
22
26
23
- internal readonly long [ ] AggregatedBucketCounts ;
27
+ internal readonly long [ ] RunningBucketCounts ;
24
28
25
- internal readonly double [ ] ExplicitBounds ;
29
+ internal readonly long [ ] SnapshotBucketCounts ;
26
30
27
- internal readonly object LockObject ;
31
+ internal double RunningSum ;
28
32
29
- internal HistogramBuckets ( double [ ] histogramBounds )
33
+ internal double SnapshotSum ;
34
+
35
+ internal HistogramBuckets ( double [ ] explicitBounds )
30
36
{
31
- this . ExplicitBounds = histogramBounds ;
32
- this . BucketCounts = histogramBounds != null ? new long [ histogramBounds . Length + 1 ] : null ;
33
- this . AggregatedBucketCounts = histogramBounds != null ? new long [ histogramBounds . Length + 1 ] : null ;
34
- this . LockObject = new object ( ) ;
37
+ this . ExplicitBounds = explicitBounds ;
38
+ this . RunningBucketCounts = explicitBounds != null ? new long [ explicitBounds . Length + 1 ] : null ;
39
+ this . SnapshotBucketCounts = explicitBounds != null ? new long [ explicitBounds . Length + 1 ] : new long [ 0 ] ;
35
40
}
36
41
42
+ internal object LockObject => this . SnapshotBucketCounts ;
43
+
37
44
public Enumerator GetEnumerator ( ) => new ( this ) ;
38
45
46
+ /// <summary>
47
+ /// Enumerates the elements of a <see cref="HistogramBuckets"/>.
48
+ /// </summary>
49
+ // Note: Does not implement IEnumerator<> to prevent accidental boxing.
39
50
public struct Enumerator
40
51
{
41
52
private readonly int numberOfBuckets ;
@@ -47,19 +58,30 @@ internal Enumerator(HistogramBuckets histogramMeasurements)
47
58
this . histogramMeasurements = histogramMeasurements ;
48
59
this . index = 0 ;
49
60
this . Current = default ;
50
- this . numberOfBuckets = histogramMeasurements . AggregatedBucketCounts == null ? 0 : histogramMeasurements . AggregatedBucketCounts . Length ;
61
+ this . numberOfBuckets = histogramMeasurements . SnapshotBucketCounts . Length ;
51
62
}
52
63
64
+ /// <summary>
65
+ /// Gets the <see cref="HistogramBucket"/> at the current position of the enumerator.
66
+ /// </summary>
53
67
public HistogramBucket Current { get ; private set ; }
54
68
69
+ /// <summary>
70
+ /// Advances the enumerator to the next element of the <see
71
+ /// cref="HistogramBuckets"/>.
72
+ /// </summary>
73
+ /// <returns><see langword="true"/> if the enumerator was
74
+ /// successfully advanced to the next element; <see
75
+ /// langword="false"/> if the enumerator has passed the end of the
76
+ /// collection.</returns>
55
77
public bool MoveNext ( )
56
78
{
57
79
if ( this . index < this . numberOfBuckets )
58
80
{
59
81
double explicitBound = this . index < this . numberOfBuckets - 1
60
82
? this . histogramMeasurements . ExplicitBounds [ this . index ]
61
83
: double . PositiveInfinity ;
62
- long bucketCount = this . histogramMeasurements . AggregatedBucketCounts [ this . index ] ;
84
+ long bucketCount = this . histogramMeasurements . SnapshotBucketCounts [ this . index ] ;
63
85
this . Current = new HistogramBucket ( explicitBound , bucketCount ) ;
64
86
this . index ++ ;
65
87
return true ;
0 commit comments