Commit 0c0c94a9 authored by Austin Clements's avatar Austin Clements

runtime/pprof: fix period information

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: 's avatarMichael Hudson-Doyle <michael.hudson@canonical.com>
Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent f3f3f0d6
...@@ -270,7 +270,9 @@ func (b *profileBuilder) addCPUData(data []uint64, tags []unsafe.Pointer) error ...@@ -270,7 +270,9 @@ func (b *profileBuilder) addCPUData(data []uint64, tags []unsafe.Pointer) error
if data[0] != 3 || data[2] == 0 { if data[0] != 3 || data[2] == 0 {
return fmt.Errorf("malformed profile") 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 b.havePeriod = true
data = data[3:] data = data[3:]
} }
......
...@@ -40,7 +40,7 @@ func TestConvertCPUProfileEmpty(t *testing.T) { ...@@ -40,7 +40,7 @@ func TestConvertCPUProfileEmpty(t *testing.T) {
// A test server with mock cpu profile data. // A test server with mock cpu profile data.
var buf bytes.Buffer 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) p, err := translateCPUProfile(b)
if err != nil { if err != nil {
t.Fatalf("translateCPUProfile: %v", err) t.Fatalf("translateCPUProfile: %v", err)
...@@ -103,7 +103,7 @@ func TestConvertCPUProfile(t *testing.T) { ...@@ -103,7 +103,7 @@ func TestConvertCPUProfile(t *testing.T) {
addr1, addr2, map1, map2 := testPCs(t) addr1, addr2, map1, map2 := testPCs(t)
b := []uint64{ 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, 10, uint64(addr1), uint64(addr1 + 2), // 10 samples in addr1
5, 0, 40, uint64(addr2), uint64(addr2 + 2), // 40 samples in addr2 5, 0, 40, uint64(addr2), uint64(addr2 + 2), // 40 samples in addr2
5, 0, 10, uint64(addr1), uint64(addr1 + 2), // 10 samples in addr1 5, 0, 10, uint64(addr1), uint64(addr1 + 2), // 10 samples in addr1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment