aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/fastlog2_test.go
diff options
context:
space:
mode:
authorRaul Silvera <rsilvera@google.com>2015-09-14 14:03:45 -0700
committerMinux Ma <minux@golang.org>2015-10-05 08:15:09 +0000
commit27ee719fb32b47b9bc59921e457f4b1e7f767968 (patch)
tree61845f2dc10b387dac8b4fe5c4ff7b5ae6fd4ad4 /src/runtime/fastlog2_test.go
parent0357c38adfd5d368390d82a2ab5b32748e4bb549 (diff)
downloadgo-27ee719fb32b47b9bc59921e457f4b1e7f767968.tar.gz
go-27ee719fb32b47b9bc59921e457f4b1e7f767968.zip
pprof: improve sampling for heap profiling
The current heap sampling introduces some bias that interferes with unsampling, producing unexpected heap profiles. The solution is to use a Poisson process to generate the sampling points, using the formulas described at https://en.wikipedia.org/wiki/Poisson_process This fixes #12620 Change-Id: If2400809ed3c41de504dd6cff06be14e476ff96c Reviewed-on: https://go-review.googlesource.com/14590 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Minux Ma <minux@golang.org> Run-TryBot: Minux Ma <minux@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/fastlog2_test.go')
-rw-r--r--src/runtime/fastlog2_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/runtime/fastlog2_test.go b/src/runtime/fastlog2_test.go
new file mode 100644
index 0000000000..8937365d51
--- /dev/null
+++ b/src/runtime/fastlog2_test.go
@@ -0,0 +1,28 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package runtime_test
+
+import (
+ "math"
+ "runtime"
+ "testing"
+)
+
+func TestFastLog2(t *testing.T) {
+ // Compute the euclidean distance between math.Log2 and the FastLog2
+ // implementation over the range of interest for heap sampling.
+ const randomBitCount = 26
+ var e float64
+ for i := 1; i < 1<<randomBitCount; i++ {
+ l, fl := math.Log2(float64(i)), runtime.Fastlog2(float64(i))
+ d := l - fl
+ e += d * d
+ }
+ e = math.Sqrt(e)
+
+ if e > 1.0 {
+ t.Fatalf("imprecision on fastlog2 implementation, want <=1.0, got %f", e)
+ }
+}