aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/export_test.go
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2020-12-22 17:47:43 +0000
committerMichael Knyszek <mknyszek@google.com>2020-12-23 17:31:18 +0000
commitb116404444addc69b5ec987a2a64b92d4956eab0 (patch)
tree3d63739c377016e8db952be441855b809be87981 /src/runtime/export_test.go
parent8db7e2fecdcd04af31c82d075c60ab6fdf6b7a48 (diff)
downloadgo-b116404444addc69b5ec987a2a64b92d4956eab0.tar.gz
go-b116404444addc69b5ec987a2a64b92d4956eab0.zip
runtime: shift timeHistogram buckets and allow negative durations
Today, timeHistogram, when copied, has the wrong set of counts for the bucket that should represent (-inf, 0), when in fact it contains [0, 1). In essence, the buckets are all shifted over by one from where they're supposed to be. But this also means that the existence of the overflow bucket is wrong: the top bucket is supposed to extend to infinity, and what we're really missing is an underflow bucket to represent the range (-inf, 0). We could just always zero this bucket and continue ignoring negative durations, but that likely isn't prudent. timeHistogram is intended to be used with differences in nanotime, but depending on how a platform is implemented (or due to a bug in that platform) it's possible to get a negative duration without having done anything wrong. We should just be resilient to that and be able to detect it. So this change removes the overflow bucket and replaces it with an underflow bucket, and timeHistogram no longer panics when faced with a negative duration. Fixes #43328. Fixes #43329. Change-Id: If336425d7d080fd37bf071e18746800e22d38108 Reviewed-on: https://go-review.googlesource.com/c/go/+/279468 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>
Diffstat (limited to 'src/runtime/export_test.go')
-rw-r--r--src/runtime/export_test.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/runtime/export_test.go b/src/runtime/export_test.go
index 44551dcaf1..22fef3134f 100644
--- a/src/runtime/export_test.go
+++ b/src/runtime/export_test.go
@@ -1201,12 +1201,12 @@ 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.
+// for the underflow 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.underflow, false
}
return t.counts[i], true
}