mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: add timeHistogram type
This change adds a concurrent HDR time histogram to the runtime with tests. It also adds a function to generate boundaries for use by the metrics package. For #37112. Change-Id: Ifbef8ddce8e3a965a0dcd58ccd4915c282ae2098 Reviewed-on: https://go-review.googlesource.com/c/go/+/247046 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
8e2370bf7f
commit
36c5edd8d9
4 changed files with 232 additions and 0 deletions
|
|
@ -1141,3 +1141,27 @@ func MSpanCountAlloc(ms *MSpan, bits []byte) int {
|
|||
s.gcmarkBits = nil
|
||||
return result
|
||||
}
|
||||
|
||||
const (
|
||||
TimeHistSubBucketBits = timeHistSubBucketBits
|
||||
TimeHistNumSubBuckets = timeHistNumSubBuckets
|
||||
TimeHistNumSuperBuckets = timeHistNumSuperBuckets
|
||||
)
|
||||
|
||||
type TimeHistogram timeHistogram
|
||||
|
||||
// Counts returns the counts for the given bucket, subBucket indices.
|
||||
// Returns true if the bucket was valid, otherwise returns the counts
|
||||
// for the overflow bucket and false.
|
||||
func (th *TimeHistogram) Count(bucket, subBucket uint) (uint64, bool) {
|
||||
t := (*timeHistogram)(th)
|
||||
i := bucket*TimeHistNumSubBuckets + subBucket
|
||||
if i >= uint(len(t.counts)) {
|
||||
return t.overflow, false
|
||||
}
|
||||
return t.counts[i], true
|
||||
}
|
||||
|
||||
func (th *TimeHistogram) Record(duration int64) {
|
||||
(*timeHistogram)(th).record(duration)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue