Browse Source

apply additional command overrides based on report format (#381)

* apply additional command overrides based on report format

* address comments

* update filtering
Margaret Nolan 6 years ago
parent
commit
1ddc9e2132
No account linked to committer's email address
2 changed files with 23 additions and 12 deletions
  1. 16
    11
      internal/driver/driver.go
  2. 7
    1
      internal/driver/interactive_test.go

+ 16
- 11
internal/driver/driver.go View File

65
 	// Identify units of numeric tags in profile.
65
 	// Identify units of numeric tags in profile.
66
 	numLabelUnits := identifyNumLabelUnits(p, o.UI)
66
 	numLabelUnits := identifyNumLabelUnits(p, o.UI)
67
 
67
 
68
-	vars = applyCommandOverrides(cmd, vars)
68
+	// Get report output format
69
+	c := pprofCommands[cmd[0]]
70
+	if c == nil {
71
+		panic("unexpected nil command")
72
+	}
73
+
74
+	vars = applyCommandOverrides(cmd[0], c.format, vars)
69
 
75
 
70
 	// Delay focus after configuring report to get percentages on all samples.
76
 	// Delay focus after configuring report to get percentages on all samples.
71
 	relative := vars["relative_percentages"].boolValue()
77
 	relative := vars["relative_percentages"].boolValue()
78
 	if err != nil {
84
 	if err != nil {
79
 		return nil, nil, err
85
 		return nil, nil, err
80
 	}
86
 	}
81
-	c := pprofCommands[cmd[0]]
82
-	if c == nil {
83
-		panic("unexpected nil command")
84
-	}
85
 	ropt.OutputFormat = c.format
87
 	ropt.OutputFormat = c.format
86
 	if len(cmd) == 2 {
88
 	if len(cmd) == 2 {
87
 		s, err := regexp.Compile(cmd[1])
89
 		s, err := regexp.Compile(cmd[1])
149
 	return out.Close()
151
 	return out.Close()
150
 }
152
 }
151
 
153
 
152
-func applyCommandOverrides(cmd []string, v variables) variables {
154
+func applyCommandOverrides(cmd string, outputFormat int, v variables) variables {
153
 	trim, tagfilter, filter := v["trim"].boolValue(), true, true
155
 	trim, tagfilter, filter := v["trim"].boolValue(), true, true
154
 
156
 
155
-	switch cmd[0] {
156
-	case "proto", "raw":
157
-		trim, tagfilter, filter = false, false, false
158
-		v.set("addresses", "t")
157
+	switch cmd {
159
 	case "callgrind", "kcachegrind":
158
 	case "callgrind", "kcachegrind":
160
 		trim = false
159
 		trim = false
161
 		v.set("addresses", "t")
160
 		v.set("addresses", "t")
163
 		trim = false
162
 		trim = false
164
 		v.set("addressnoinlines", "t")
163
 		v.set("addressnoinlines", "t")
165
 	case "peek":
164
 	case "peek":
166
-		trim, filter = false, false
165
+		trim, tagfilter, filter = false, false, false
167
 	case "list":
166
 	case "list":
168
 		v.set("nodecount", "0")
167
 		v.set("nodecount", "0")
169
 		v.set("lines", "t")
168
 		v.set("lines", "t")
176
 			v.set("nodecount", "80")
175
 			v.set("nodecount", "80")
177
 		}
176
 		}
178
 	}
177
 	}
178
+
179
+	if outputFormat == report.Proto || outputFormat == report.Raw {
180
+		trim, tagfilter, filter = false, false, false
181
+		v.set("addresses", "t")
182
+	}
183
+
179
 	if !trim {
184
 	if !trim {
180
 		v.set("nodecount", "0")
185
 		v.set("nodecount", "0")
181
 		v.set("nodefraction", "0")
186
 		v.set("nodefraction", "0")

+ 7
- 1
internal/driver/interactive_test.go View File

294
 			t.Errorf("failed on %q: %v", tc.input, err)
294
 			t.Errorf("failed on %q: %v", tc.input, err)
295
 			continue
295
 			continue
296
 		}
296
 		}
297
-		vars = applyCommandOverrides(cmd, vars)
297
+
298
+		// Get report output format
299
+		c := pprofCommands[cmd[0]]
300
+		if c == nil {
301
+			t.Errorf("unexpected nil command")
302
+		}
303
+		vars = applyCommandOverrides(cmd[0], c.format, vars)
298
 
304
 
299
 		for n, want := range tc.want {
305
 		for n, want := range tc.want {
300
 			if got := vars[n].stringValue(); got != want {
306
 			if got := vars[n].stringValue(); got != want {