Skip to content

Commit f9a4ae0

Browse files
aalexandhyangah
authored andcommitted
runtime/pprof: compute memory profile block size using sampled values
Fixes #26638. Change-Id: I3c18d1298d99af8ea8c00916303efd2b5a5effc7 Reviewed-on: https://go-review.googlesource.com/126336 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent c64006a commit f9a4ae0

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/runtime/pprof/protomem.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func writeHeapProto(w io.Writer, p []runtime.MemProfileRecord, rate int64, defau
5656
values[0], values[1] = scaleHeapSample(r.AllocObjects, r.AllocBytes, rate)
5757
values[2], values[3] = scaleHeapSample(r.InUseObjects(), r.InUseBytes(), rate)
5858
var blockSize int64
59-
if values[0] > 0 {
60-
blockSize = values[1] / values[0]
59+
if r.AllocObjects > 0 {
60+
blockSize = r.AllocBytes / r.AllocObjects
6161
}
6262
b.pbSample(values, locs, func() {
6363
if blockSize != 0 {

src/runtime/pprof/protomem_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestConvertMemProfile(t *testing.T) {
4848
{ID: 3, Mapping: map2, Address: addr2 + 1},
4949
{ID: 4, Mapping: map2, Address: addr2 + 2},
5050
},
51-
NumLabel: map[string][]int64{"bytes": {829411}},
51+
NumLabel: map[string][]int64{"bytes": {512 * 1024}},
5252
},
5353
{
5454
Value: []int64{1, 829411, 0, 0},
@@ -57,7 +57,7 @@ func TestConvertMemProfile(t *testing.T) {
5757
{ID: 6, Mapping: map1, Address: addr1 + 2},
5858
{ID: 7, Mapping: map2, Address: addr2 + 3},
5959
},
60-
NumLabel: map[string][]int64{"bytes": {829411}},
60+
NumLabel: map[string][]int64{"bytes": {512 * 1024}},
6161
},
6262
}
6363
for _, tc := range []struct {

0 commit comments

Comments
 (0)