Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply additional command overrides based on report format #381

Merged
merged 5 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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