From 71e482e4fbe431375e90cebee9f63636c343fcaf Mon Sep 17 00:00:00 2001 From: Maggie Nolan Date: Thu, 24 May 2018 16:08:06 -0700 Subject: [PATCH 1/3] apply additional command overrides based on report format --- internal/driver/driver.go | 20 ++++++++++++++------ internal/driver/interactive_test.go | 8 +++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/internal/driver/driver.go b/internal/driver/driver.go index acc0b4ad..b88d73b0 100644 --- a/internal/driver/driver.go +++ b/internal/driver/driver.go @@ -65,7 +65,13 @@ func generateRawReport(p *profile.Profile, cmd []string, vars variables, o *plug // Identify units of numeric tags in profile. numLabelUnits := identifyNumLabelUnits(p, o.UI) - vars = applyCommandOverrides(cmd, vars) + // Get report output format + c := pprofCommands[cmd[0]] + if c == nil { + panic("unexpected nil command") + } + + vars = applyCommandOverrides(cmd, c.format, vars) // Delay focus after configuring report to get percentages on all samples. relative := vars["relative_percentages"].boolValue() @@ -78,10 +84,6 @@ func generateRawReport(p *profile.Profile, cmd []string, vars variables, o *plug if err != nil { return nil, nil, err } - c := pprofCommands[cmd[0]] - if c == nil { - panic("unexpected nil command") - } ropt.OutputFormat = c.format if len(cmd) == 2 { s, err := regexp.Compile(cmd[1]) @@ -149,7 +151,7 @@ func generateReport(p *profile.Profile, cmd []string, vars variables, o *plugin. return out.Close() } -func applyCommandOverrides(cmd []string, v variables) variables { +func applyCommandOverrides(cmd []string, outputFormat int, v variables) variables { trim, tagfilter, filter := v["trim"].boolValue(), true, true switch cmd[0] { @@ -176,6 +178,12 @@ func applyCommandOverrides(cmd []string, v variables) variables { v.set("nodecount", "80") } } + + if outputFormat == report.Proto { + trim, tagfilter, filter = false, false, false + v.set("addresses", "t") + } + if !trim { v.set("nodecount", "0") v.set("nodefraction", "0") diff --git a/internal/driver/interactive_test.go b/internal/driver/interactive_test.go index db26862c..31a230f0 100644 --- a/internal/driver/interactive_test.go +++ b/internal/driver/interactive_test.go @@ -294,7 +294,13 @@ func TestInteractiveCommands(t *testing.T) { t.Errorf("failed on %q: %v", tc.input, err) continue } - vars = applyCommandOverrides(cmd, vars) + + // Get report output format + c := pprofCommands[cmd[0]] + if c == nil { + t.Errorf("unexpected nil command") + } + vars = applyCommandOverrides(cmd, c.format, vars) for n, want := range tc.want { if got := vars[n].stringValue(); got != want { From 5aacbbbec9e2faa8a90c54af876672f2176649b5 Mon Sep 17 00:00:00 2001 From: Maggie Nolan Date: Fri, 25 May 2018 08:47:27 -0700 Subject: [PATCH 2/3] address comments --- internal/driver/driver.go | 11 ++++------- internal/driver/interactive_test.go | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/internal/driver/driver.go b/internal/driver/driver.go index b88d73b0..473cc2d9 100644 --- a/internal/driver/driver.go +++ b/internal/driver/driver.go @@ -71,7 +71,7 @@ func generateRawReport(p *profile.Profile, cmd []string, vars variables, o *plug panic("unexpected nil command") } - vars = applyCommandOverrides(cmd, c.format, vars) + vars = applyCommandOverrides(cmd[0], c.format, vars) // Delay focus after configuring report to get percentages on all samples. relative := vars["relative_percentages"].boolValue() @@ -151,13 +151,10 @@ func generateReport(p *profile.Profile, cmd []string, vars variables, o *plugin. return out.Close() } -func applyCommandOverrides(cmd []string, outputFormat int, v variables) variables { +func applyCommandOverrides(cmd string, outputFormat int, v variables) variables { trim, tagfilter, filter := v["trim"].boolValue(), true, true - switch cmd[0] { - case "proto", "raw": - trim, tagfilter, filter = false, false, false - v.set("addresses", "t") + switch cmd { case "callgrind", "kcachegrind": trim = false v.set("addresses", "t") @@ -179,7 +176,7 @@ func applyCommandOverrides(cmd []string, outputFormat int, v variables) variable } } - if outputFormat == report.Proto { + if outputFormat == report.Proto || outputFormat == report.Raw { trim, tagfilter, filter = false, false, false v.set("addresses", "t") } diff --git a/internal/driver/interactive_test.go b/internal/driver/interactive_test.go index 31a230f0..8d775e16 100644 --- a/internal/driver/interactive_test.go +++ b/internal/driver/interactive_test.go @@ -300,7 +300,7 @@ func TestInteractiveCommands(t *testing.T) { if c == nil { t.Errorf("unexpected nil command") } - vars = applyCommandOverrides(cmd, c.format, vars) + vars = applyCommandOverrides(cmd[0], c.format, vars) for n, want := range tc.want { if got := vars[n].stringValue(); got != want { From 28beb40de5d4ce931d44c2a99f3d0909a4bf4171 Mon Sep 17 00:00:00 2001 From: Maggie Nolan Date: Tue, 29 May 2018 12:56:16 -0700 Subject: [PATCH 3/3] update filtering --- internal/driver/driver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/driver/driver.go b/internal/driver/driver.go index 473cc2d9..2dabc301 100644 --- a/internal/driver/driver.go +++ b/internal/driver/driver.go @@ -162,7 +162,7 @@ func applyCommandOverrides(cmd string, outputFormat int, v variables) variables trim = false v.set("addressnoinlines", "t") case "peek": - trim, filter = false, false + trim, tagfilter, filter = false, false, false case "list": v.set("nodecount", "0") v.set("lines", "t")