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 1 commit
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
20 changes: 14 additions & 6 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, 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,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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about changing the first argument to be just "cmd string"? It doesn't seem to be necessary to pass the array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

trim, tagfilter, filter := v["trim"].boolValue(), true, true

switch cmd[0] {
Expand All @@ -176,6 +178,12 @@ func applyCommandOverrides(cmd []string, v variables) variables {
v.set("nodecount", "80")
}
}

if outputFormat == report.Proto {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you keep case "proto", "raw": in the switch, isn't it redundant now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now redundant. Done.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side question: why does "peek" case resets the filter but not not the tagfilter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem odd. My best guess is that tagfilter was added later, and this is an oversight, but I'll look into the commit history to see if there's evidence for that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we should fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag filtering was added after the peek command, (in this PR), which suggests to me this is an oversight.

I've changed it in this PR. Let me know if you think it ought to be a separate PR.

trim, tagfilter, filter = false, false, false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps for future unless there is an easy way to do it: it would be good to have a way to generate reports in the proto format keeping the filter. E.g. using the internal -flame command with a -tagfocus filter to upload a subset of the profile.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that this could be done just by not setting filter and tagfilter to false. Not sure if we would want to also, for example, add a comment to the profile to indicate filtering was done.

Will experiment, then look into changing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done later.

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, c.format, vars)

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