diff options
| author | Hana (Hyang-Ah) Kim <hyangah@gmail.com> | 2018-03-27 12:23:19 -0400 |
|---|---|---|
| committer | Hyang-Ah Hana Kim <hyangah@gmail.com> | 2018-04-24 16:11:41 +0000 |
| commit | cd037bce09ec1aecd40d9c91c23d09f5b60549f4 (patch) | |
| tree | 932329eed8ad31e2e06750de1afe7976244a4753 /src/runtime/pprof/internal | |
| parent | 70c5839fe0e2149d505c0e28c42e133d4bc01503 (diff) | |
| download | go-cd037bce09ec1aecd40d9c91c23d09f5b60549f4.tar.xz | |
runtime/pprof: introduce "allocs" profile
The Go's heap profile contains four kinds of samples
(inuse_space, inuse_objects, alloc_space, and alloc_objects).
The pprof tool by default chooses the inuse_space (the bytes
of live, in-use objects). When analyzing the current memory
usage the choice of inuse_space as the default may be useful,
but in some cases, users are more interested in analyzing the
total allocation statistics throughout the program execution.
For example, when we analyze the memory profile from benchmark
or program test run, we are more likely interested in the whole
allocation history than the live heap snapshot at the end of
the test or benchmark.
The pprof tool provides flags to control which sample type
to be used for analysis. However, it is one of the less-known
features of pprof and we believe it's better to choose the
right type of samples as the default when producing the profile.
This CL introduces a new type of profile, "allocs", which is
the same as the "heap" profile but marks the alloc_space
as the default type unlike heap profiles that use inuse_space
as the default type.
'go test -memprofile=...' command is changed to use the new
"allocs" profile type instead of the traditional "heap" profile.
Fixes #24443
Change-Id: I012dd4b6dcacd45644d7345509936b8380b6fbd9
Reviewed-on: https://go-review.googlesource.com/102696
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/runtime/pprof/internal')
| -rw-r--r-- | src/runtime/pprof/internal/profile/encode.go | 12 | ||||
| -rw-r--r-- | src/runtime/pprof/internal/profile/profile.go | 20 |
2 files changed, 24 insertions, 8 deletions
diff --git a/src/runtime/pprof/internal/profile/encode.go b/src/runtime/pprof/internal/profile/encode.go index 6b879a84ac..af319330d9 100644 --- a/src/runtime/pprof/internal/profile/encode.go +++ b/src/runtime/pprof/internal/profile/encode.go @@ -197,6 +197,10 @@ var profileDecoder = []decoder{ }, // repeated int64 period = 12 func(b *buffer, m message) error { return decodeInt64(b, &m.(*Profile).Period) }, + // repeated int64 comment = 13 + func(b *buffer, m message) error { return decodeInt64s(b, &m.(*Profile).commentX) }, + // int64 defaultSampleType = 14 + func(b *buffer, m message) error { return decodeInt64(b, &m.(*Profile).defaultSampleTypeX) }, } // postDecode takes the unexported fields populated by decode (with @@ -278,6 +282,14 @@ func (p *Profile) postDecode() error { pt.Type, err = getString(p.stringTable, &pt.typeX, err) pt.Unit, err = getString(p.stringTable, &pt.unitX, err) } + for _, i := range p.commentX { + var c string + c, err = getString(p.stringTable, &i, err) + p.Comments = append(p.Comments, c) + } + + p.commentX = nil + p.DefaultSampleType, err = getString(p.stringTable, &p.defaultSampleTypeX, err) p.stringTable = nil return nil } diff --git a/src/runtime/pprof/internal/profile/profile.go b/src/runtime/pprof/internal/profile/profile.go index 9b6a6f9aa9..64c3e3f054 100644 --- a/src/runtime/pprof/internal/profile/profile.go +++ b/src/runtime/pprof/internal/profile/profile.go @@ -22,11 +22,13 @@ import ( // Profile is an in-memory representation of profile.proto. type Profile struct { - SampleType []*ValueType - Sample []*Sample - Mapping []*Mapping - Location []*Location - Function []*Function + SampleType []*ValueType + DefaultSampleType string + Sample []*Sample + Mapping []*Mapping + Location []*Location + Function []*Function + Comments []string DropFrames string KeepFrames string @@ -36,9 +38,11 @@ type Profile struct { PeriodType *ValueType Period int64 - dropFramesX int64 - keepFramesX int64 - stringTable []string + commentX []int64 + dropFramesX int64 + keepFramesX int64 + stringTable []string + defaultSampleTypeX int64 } // ValueType corresponds to Profile.ValueType |
