Skip to content

Commit

Permalink
Comment how memory reuse misses are handled
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Jul 26, 2023
1 parent a8d0fb1 commit 95cc60c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sdk/metric/internal/aggregate/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type sum[N int64 | float64] struct {
func (s *sum[N]) delta(dest *metricdata.Aggregation) int {
t := now()

// If *dest is not a metricdata.Sum, memory reuse is missed. In that case,
// use the zero-value sData and hope for better alignment next cycle.
sData, _ := (*dest).(metricdata.Sum[N])
sData.Temporality = metricdata.DeltaTemporality
sData.IsMonotonic = s.monotonic
Expand Down Expand Up @@ -93,6 +95,8 @@ func (s *sum[N]) delta(dest *metricdata.Aggregation) int {
func (s *sum[N]) cumulative(dest *metricdata.Aggregation) int {
t := now()

// If *dest is not a metricdata.Sum, memory reuse is missed. In that case,
// use the zero-value sData and hope for better alignment next cycle.
sData, _ := (*dest).(metricdata.Sum[N])
sData.Temporality = metricdata.CumulativeTemporality
sData.IsMonotonic = s.monotonic
Expand Down Expand Up @@ -147,6 +151,8 @@ func (s *precomputedSum[N]) delta(dest *metricdata.Aggregation) int {
t := now()
newReported := make(map[attribute.Set]N)

// If *dest is not a metricdata.Sum, memory reuse is missed. In that case,
// use the zero-value sData and hope for better alignment next cycle.
sData, _ := (*dest).(metricdata.Sum[N])
sData.Temporality = metricdata.DeltaTemporality
sData.IsMonotonic = s.monotonic
Expand Down Expand Up @@ -185,6 +191,8 @@ func (s *precomputedSum[N]) delta(dest *metricdata.Aggregation) int {
func (s *precomputedSum[N]) cumulative(dest *metricdata.Aggregation) int {
t := now()

// If *dest is not a metricdata.Sum, memory reuse is missed. In that case,
// use the zero-value sData and hope for better alignment next cycle.
sData, _ := (*dest).(metricdata.Sum[N])
sData.Temporality = metricdata.CumulativeTemporality
sData.IsMonotonic = s.monotonic
Expand Down

0 comments on commit 95cc60c

Please sign in to comment.