]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: fix period information
authorAustin Clements <austin@google.com>
Tue, 18 Apr 2017 20:41:19 +0000 (16:41 -0400)
committerAustin Clements <austin@google.com>
Thu, 20 Apr 2017 19:35:08 +0000 (19:35 +0000)
The period recorded in CPU profiles is in nanoseconds, but was being
computed incorrectly as hz * 1000. As a result, many absolute times
displayed by pprof were incorrect.

Fix this by computing the period correctly.

Change-Id: I6fadd6d8ad3e57f31e8cc7a25a24fcaec510d8d4
Reviewed-on: https://go-review.googlesource.com/40995
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
Reviewed-by: Russ Cox <rsc@golang.org>
src/runtime/pprof/proto.go
src/runtime/pprof/proto_test.go

index 0f74e119b6c7c10baab22fdb37179e89c9895d40..923fa2188ad0fae34521d0b2a6f41df7f19fadc1 100644 (file)
@@ -270,7 +270,9 @@ func (b *profileBuilder) addCPUData(data []uint64, tags []unsafe.Pointer) error
                if data[0] != 3 || data[2] == 0 {
                        return fmt.Errorf("malformed profile")
                }
-               b.period = int64(data[2]) * 1000
+               // data[2] is sampling rate in Hz. Convert to sampling
+               // period in nanoseconds.
+               b.period = 1e9 / int64(data[2])
                b.havePeriod = true
                data = data[3:]
        }
index 2f104191474eaafaa0ca12dcd76b64f21137d605..59c1080e7b205748ae06765d8d8cff47dc1492ec 100644 (file)
@@ -40,7 +40,7 @@ func TestConvertCPUProfileEmpty(t *testing.T) {
        // A test server with mock cpu profile data.
        var buf bytes.Buffer
 
-       b := []uint64{3, 0, 2000} // empty profile with 2ms sample period
+       b := []uint64{3, 0, 500} // empty profile at 500 Hz (2ms sample period)
        p, err := translateCPUProfile(b)
        if err != nil {
                t.Fatalf("translateCPUProfile: %v", err)
@@ -103,7 +103,7 @@ func TestConvertCPUProfile(t *testing.T) {
        addr1, addr2, map1, map2 := testPCs(t)
 
        b := []uint64{
-               3, 0, 2000, // periodMs = 2000
+               3, 0, 500, // hz = 500
                5, 0, 10, uint64(addr1), uint64(addr1 + 2), // 10 samples in addr1
                5, 0, 40, uint64(addr2), uint64(addr2 + 2), // 40 samples in addr2
                5, 0, 10, uint64(addr1), uint64(addr1 + 2), // 10 samples in addr1