update updates the batchHistogram from a runtime/metrics histogram. sum must be provided if the batchHistogram was created to have an exact sum. h.buckets must be a strict subset of his.Buckets.
(his *metrics.Float64Histogram, sum float64)
| 507 | // sum must be provided if the batchHistogram was created to have an exact sum. |
| 508 | // h.buckets must be a strict subset of his.Buckets. |
| 509 | func (h *batchHistogram) update(his *metrics.Float64Histogram, sum float64) { |
| 510 | counts, buckets := his.Counts, his.Buckets |
| 511 | |
| 512 | h.mu.Lock() |
| 513 | defer h.mu.Unlock() |
| 514 | |
| 515 | // Clear buckets. |
| 516 | for i := range h.counts { |
| 517 | h.counts[i] = 0 |
| 518 | } |
| 519 | // Copy and reduce buckets. |
| 520 | var j int |
| 521 | for i, count := range counts { |
| 522 | h.counts[j] += count |
| 523 | if buckets[i+1] == h.buckets[j+1] { |
| 524 | j++ |
| 525 | } |
| 526 | } |
| 527 | if h.hasSum { |
| 528 | h.sum = sum |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | func (h *batchHistogram) Desc() *Desc { |
| 533 | return h.desc |