From 562c51d8d743bc31e642f3d864a460e4e38e48b5 Mon Sep 17 00:00:00 2001 From: Maggie Nolan Date: Fri, 11 May 2018 15:11:35 -0700 Subject: [PATCH] address comments --- internal/driver/driver_test.go | 8 ++++++-- internal/driver/fetch_test.go | 22 ++++++---------------- internal/report/report.go | 6 +++--- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/internal/driver/driver_test.go b/internal/driver/driver_test.go index 309e9950..631e7e07 100644 --- a/internal/driver/driver_test.go +++ b/internal/driver/driver_test.go @@ -288,7 +288,7 @@ type testFlags struct { floats map[string]float64 strings map[string]string args []string - stringLists map[string][]*string + stringLists map[string][]string } func (testFlags) ExtraUsage() string { return "" } @@ -355,7 +355,11 @@ func (f testFlags) StringVar(p *string, s, d, c string) { func (f testFlags) StringList(s, d, c string) *[]*string { if t, ok := f.stringLists[s]; ok { - return &t + tp := make([]*string, len(t)) + for i, v := range t { + tp[i] = &v + } + return &tp } return &[]*string{} } diff --git a/internal/driver/fetch_test.go b/internal/driver/fetch_test.go index 0de63114..853afba8 100644 --- a/internal/driver/fetch_test.go +++ b/internal/driver/fetch_test.go @@ -437,20 +437,10 @@ func TestFetchWithBase(t *testing.T) { for _, tc := range testcases { t.Run(tc.desc, func(t *testing.T) { pprofVariables = baseVars.makeCopy() - base := make([]*string, len(tc.bases)) - for i, s := range tc.bases { - base[i] = &s - } - - diffBase := make([]*string, len(tc.diffBases)) - for i, s := range tc.diffBases { - diffBase[i] = &s - } - f := testFlags{ - stringLists: map[string][]*string{ - "base": base, - "diff_base": diffBase, + stringLists: map[string][]string{ + "base": tc.bases, + "diff_base": tc.diffBases, }, bools: map[string]bool{ "normalize": tc.normalize, @@ -468,8 +458,8 @@ func TestFetchWithBase(t *testing.T) { if err == nil { t.Fatalf("got nil, want error %q", tc.wantErrorMsg) } - gotErrMsg := err.Error() - if gotErrMsg != tc.wantErrorMsg { + + if gotErrMsg := err.Error(); gotErrMsg != tc.wantErrorMsg { t.Fatalf("got error %q, want error %q", gotErrMsg, tc.wantErrorMsg) } return @@ -485,7 +475,7 @@ func TestFetchWithBase(t *testing.T) { t.Fatal(err) } - if want, got := len(tc.wantSamples), len(p.Sample); want != got { + if got, want := len(p.Sample), len(tc.wantSamples); got != want { t.Fatalf("got %d samples want %d", got, want) } diff --git a/internal/report/report.go b/internal/report/report.go index 8e663d1c..76db9cbf 100644 --- a/internal/report/report.go +++ b/internal/report/report.go @@ -264,7 +264,7 @@ func (rpt *Report) newGraph(nodes graph.NodeSet) *graph.Graph { s.NumUnit = numUnits } - // Remove tag marking samples from the base profiles, so it does not appear + // Remove label marking samples from the base profiles, so it does not appear // as a nodelet in the graph view. prof.RemoveLabel("pprof::base") @@ -1217,8 +1217,8 @@ func NewDefault(prof *profile.Profile, options Options) *Report { } // computeTotal computes the sum of the absolute value of all sample values. -// If any samples have the tag "pprof::base" with value "true", then the total -// will only include samples with that tag. +// If any samples have the label "pprof::base" with value "true", then the total +// will only include samples with that label. func computeTotal(prof *profile.Profile, value, meanDiv func(v []int64) int64) int64 { var div, total, diffDiv, diffTotal int64 for _, sample := range prof.Sample {