aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaul Silvera <rsilvera@google.com>2016-12-14 13:32:18 -0800
committerMichael Matloob <matloob@golang.org>2016-12-15 14:55:37 +0000
commit7e4ef4ebfc4f24bb030716c81e0f812aa3a36c97 (patch)
tree08275ad9753550a0ef44c89e98db3b6ec38924df
parent6f5a77bf5f909e19fbc19f2c75ec1e160ec0aaa5 (diff)
downloadgo-7e4ef4ebfc4f24bb030716c81e0f812aa3a36c97.tar.gz
go-7e4ef4ebfc4f24bb030716c81e0f812aa3a36c97.zip
cmd/pprof: search for sample types in profile
Search the sample types in the profile being processed to map sample type options to indices in the profile sample type array. Previously these were hardcoded, which caused issues when the sample types for a profile type changed. For instance, this was triggered by the native generation of profiles in profile.proto format. This fixes #18230. A similar mechanism already exists on the upstream pprof. Change-Id: I945d8d842a0c2ca14299dabefe83124746ecd7e2 Reviewed-on: https://go-review.googlesource.com/34382 Reviewed-by: Michael Matloob <matloob@golang.org>
-rw-r--r--src/cmd/pprof/internal/driver/driver.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/cmd/pprof/internal/driver/driver.go b/src/cmd/pprof/internal/driver/driver.go
index 931985a7f2..0f1ed6eece 100644
--- a/src/cmd/pprof/internal/driver/driver.go
+++ b/src/cmd/pprof/internal/driver/driver.go
@@ -780,14 +780,14 @@ func processFlags(p *profile.Profile, ui plugin.UI, f *flags) error {
var err error
si, sm := *f.flagSampleIndex, *f.flagMean || *f.flagMeanDelay
- si, err = sampleIndex(p, &f.flagTotalDelay, si, 1, "delay", "-total_delay", err)
- si, err = sampleIndex(p, &f.flagMeanDelay, si, 1, "delay", "-mean_delay", err)
- si, err = sampleIndex(p, &f.flagContentions, si, 0, "contentions", "-contentions", err)
+ si, err = sampleIndex(p, &f.flagTotalDelay, si, "delay", "-total_delay", err)
+ si, err = sampleIndex(p, &f.flagMeanDelay, si, "delay", "-mean_delay", err)
+ si, err = sampleIndex(p, &f.flagContentions, si, "contentions", "-contentions", err)
- si, err = sampleIndex(p, &f.flagInUseSpace, si, 1, "inuse_space", "-inuse_space", err)
- si, err = sampleIndex(p, &f.flagInUseObjects, si, 0, "inuse_objects", "-inuse_objects", err)
- si, err = sampleIndex(p, &f.flagAllocSpace, si, 1, "alloc_space", "-alloc_space", err)
- si, err = sampleIndex(p, &f.flagAllocObjects, si, 0, "alloc_objects", "-alloc_objects", err)
+ si, err = sampleIndex(p, &f.flagInUseSpace, si, "inuse_space", "-inuse_space", err)
+ si, err = sampleIndex(p, &f.flagInUseObjects, si, "inuse_objects", "-inuse_objects", err)
+ si, err = sampleIndex(p, &f.flagAllocSpace, si, "alloc_space", "-alloc_space", err)
+ si, err = sampleIndex(p, &f.flagAllocObjects, si, "alloc_objects", "-alloc_objects", err)
if si == -1 {
// Use last value if none is requested.
@@ -806,7 +806,6 @@ func processFlags(p *profile.Profile, ui plugin.UI, f *flags) error {
func sampleIndex(p *profile.Profile, flag **bool,
sampleIndex int,
- newSampleIndex int,
sampleType, option string,
err error) (int, error) {
if err != nil || !**flag {
@@ -816,11 +815,12 @@ func sampleIndex(p *profile.Profile, flag **bool,
if sampleIndex != -1 {
return 0, fmt.Errorf("set at most one sample value selection option")
}
- if newSampleIndex >= len(p.SampleType) ||
- p.SampleType[newSampleIndex].Type != sampleType {
- return 0, fmt.Errorf("option %s not valid for this profile", option)
+ for index, s := range p.SampleType {
+ if sampleType == s.Type {
+ return index, nil
+ }
}
- return newSampleIndex, nil
+ return 0, fmt.Errorf("option %s not valid for this profile", option)
}
func countFlags(bs []*bool) int {