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

Metric histogram aggregator: Swap in SynchronizedMove to avoid allocations #1435

Merged
merged 7 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Upstream
  • Loading branch information
Joshua MacDonald committed Jan 6, 2021
commit 539a2e19bf0503829dcd1362ebe7adf4c50d0fb8
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- `NewExporter` from `exporters/otlp` now takes a `ProtocolDriver` as a parameter. (#1369)
- Many OTLP Exporter options became gRPC ProtocolDriver options. (#1369)
- Unify endpoint API that related to OTel exporter. (#1401)
<<<<<<< HEAD
- Optimize metric histogram aggregator to re-use its slice of buckets. (#1435)
=======
- Metric aggregator Count() and histogram Bucket.Counts are consistently `uint64`. (1430)
>>>>>>> origin

### Removed

Expand Down
28 changes: 14 additions & 14 deletions sdk/metric/aggregator/histogram/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,6 @@ func New(cnt int, desc *metric.Descriptor, boundaries []float64) []Aggregator {
return aggs
}

func (c *Aggregator) newState() *state {
return &state{
bucketCounts: make([]float64, len(c.boundaries)+1),
}
}

func (c *Aggregator) clearState() {
for i := range c.state.bucketCounts {
c.state.bucketCounts[i] = 0
}
c.state.sum = 0
c.state.count = 0
}

// Aggregation returns an interface for reading the state of this aggregator.
func (c *Aggregator) Aggregation() aggregation.Aggregation {
return c
Expand Down Expand Up @@ -161,6 +147,20 @@ func (c *Aggregator) SynchronizedMove(oa export.Aggregator, desc *metric.Descrip
return nil
}

func (c *Aggregator) newState() *state {
return &state{
bucketCounts: make([]uint64, len(c.boundaries)+1),
}
}

func (c *Aggregator) clearState() {
for i := range c.state.bucketCounts {
c.state.bucketCounts[i] = 0
}
c.state.sum = 0
c.state.count = 0
}

// Update adds the recorded measurement to the current data set.
func (c *Aggregator) Update(_ context.Context, number number.Number, desc *metric.Descriptor) error {
kind := desc.NumberKind()
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.