Ver código fonte

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

* apply additional command overrides based on report format

* address comments

* update filtering
Margaret Nolan 6 anos atrás
pai
commit
1ddc9e2132
Nenhuma conta vinculada ao e-mail do autor do commit
2 arquivos alterados com 23 adições e 12 exclusões
  1. 16
    11
      internal/driver/driver.go
  2. 7
    1
      internal/driver/interactive_test.go

+ 16
- 11
internal/driver/driver.go Ver arquivo

@@ -65,7 +65,13 @@ func generateRawReport(p *profile.Profile, cmd []string, vars variables, o *plug
65 65
 	// Identify units of numeric tags in profile.
66 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 76
 	// Delay focus after configuring report to get percentages on all samples.
71 77
 	relative := vars["relative_percentages"].boolValue()
@@ -78,10 +84,6 @@ func generateRawReport(p *profile.Profile, cmd []string, vars variables, o *plug
78 84
 	if err != nil {
79 85
 		return nil, nil, err
80 86
 	}
81
-	c := pprofCommands[cmd[0]]
82
-	if c == nil {
83
-		panic("unexpected nil command")
84
-	}
85 87
 	ropt.OutputFormat = c.format
86 88
 	if len(cmd) == 2 {
87 89
 		s, err := regexp.Compile(cmd[1])
@@ -149,13 +151,10 @@ func generateReport(p *profile.Profile, cmd []string, vars variables, o *plugin.
149 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 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 158
 	case "callgrind", "kcachegrind":
160 159
 		trim = false
161 160
 		v.set("addresses", "t")
@@ -163,7 +162,7 @@ func applyCommandOverrides(cmd []string, v variables) variables {
163 162
 		trim = false
164 163
 		v.set("addressnoinlines", "t")
165 164
 	case "peek":
166
-		trim, filter = false, false
165
+		trim, tagfilter, filter = false, false, false
167 166
 	case "list":
168 167
 		v.set("nodecount", "0")
169 168
 		v.set("lines", "t")
@@ -176,6 +175,12 @@ func applyCommandOverrides(cmd []string, v variables) variables {
176 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 184
 	if !trim {
180 185
 		v.set("nodecount", "0")
181 186
 		v.set("nodefraction", "0")

+ 7
- 1
internal/driver/interactive_test.go Ver arquivo

@@ -294,7 +294,13 @@ func TestInteractiveCommands(t *testing.T) {
294 294
 			t.Errorf("failed on %q: %v", tc.input, err)
295 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 305
 		for n, want := range tc.want {
300 306
 			if got := vars[n].stringValue(); got != want {