Skip to content

Commit

Permalink
apply additional command overrides based on report format (#381)
Browse files Browse the repository at this point in the history
* apply additional command overrides based on report format

* address comments

* update filtering
  • Loading branch information
nolanmar511 authored May 30, 2018
1 parent 403a828 commit 1ddc9e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
27 changes: 16 additions & 11 deletions internal/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[0], c.format, vars)

// Delay focus after configuring report to get percentages on all samples.
relative := vars["relative_percentages"].boolValue()
Expand All @@ -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])
Expand Down Expand Up @@ -149,21 +151,18 @@ 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] {
case "proto", "raw":
trim, tagfilter, filter = false, false, false
v.set("addresses", "t")
switch cmd {
case "callgrind", "kcachegrind":
trim = false
v.set("addresses", "t")
case "disasm", "weblist":
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")
Expand All @@ -176,6 +175,12 @@ func applyCommandOverrides(cmd []string, v variables) variables {
v.set("nodecount", "80")
}
}

if outputFormat == report.Proto || outputFormat == report.Raw {
trim, tagfilter, filter = false, false, false
v.set("addresses", "t")
}

if !trim {
v.set("nodecount", "0")
v.set("nodefraction", "0")
Expand Down
8 changes: 7 additions & 1 deletion internal/driver/interactive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[0], c.format, vars)

for n, want := range tc.want {
if got := vars[n].stringValue(); got != want {
Expand Down

0 comments on commit 1ddc9e2

Please sign in to comment.