Sfoglia il codice sorgente

Update legend to show show/hide/focus/ignore settings (#151)

* Added info on focus/ignore/show/hide to legend on graphs

* Made separate function for formatting filters in legend
Margaret Nolan 7 anni fa
parent
commit
5374a54a2c

+ 10
- 0
internal/driver/driver.go Vedi File

@@ -225,6 +225,14 @@ func reportOptions(p *profile.Profile, vars variables) (*report.Options, error)
225 225
 		return nil, fmt.Errorf("zero divisor specified")
226 226
 	}
227 227
 
228
+	var filters []string
229
+	for _, k := range []string{"focus", "ignore", "hide", "show", "tagfocus", "tagignore", "tagshow", "taghide"} {
230
+		v := vars[k].value
231
+		if v != "" {
232
+			filters = append(filters, k+"="+v)
233
+		}
234
+	}
235
+
228 236
 	ropt := &report.Options{
229 237
 		CumSort:             vars["cum"].boolValue(),
230 238
 		CallTree:            vars["call_tree"].boolValue(),
@@ -238,6 +246,8 @@ func reportOptions(p *profile.Profile, vars variables) (*report.Options, error)
238 246
 		NodeFraction: vars["nodefraction"].floatValue(),
239 247
 		EdgeFraction: vars["edgefraction"].floatValue(),
240 248
 
249
+		ActiveFilters: filters,
250
+
241 251
 		SampleValue:       value,
242 252
 		SampleMeanDivisor: meanDiv,
243 253
 		SampleType:        stype,

+ 3
- 0
internal/driver/driver_test.go Vedi File

@@ -56,9 +56,11 @@ func TestParse(t *testing.T) {
56 56
 		{"text,functions,flat,nodecount=5,call_tree", "unknown"},
57 57
 		{"text,alloc_objects,flat", "heap_alloc"},
58 58
 		{"text,files,flat", "heap"},
59
+		{"text,files,flat,focus=[12]00,taghide=[X3]00", "heap"},
59 60
 		{"text,inuse_objects,flat", "heap"},
60 61
 		{"text,lines,cum,hide=line[X3]0", "cpu"},
61 62
 		{"text,lines,cum,show=[12]00", "cpu"},
63
+		{"text,lines,cum,hide=line[X3]0,focus=[12]00", "cpu"},
62 64
 		{"topproto,lines,cum,hide=mangled[X3]0", "cpu"},
63 65
 		{"tree,lines,cum,focus=[24]00", "heap"},
64 66
 		{"tree,relative_percentages,cum,focus=[24]00", "heap"},
@@ -78,6 +80,7 @@ func TestParse(t *testing.T) {
78 80
 		{"tags,unit=bytes", "heap"},
79 81
 		{"traces", "cpu"},
80 82
 		{"dot,alloc_space,flat,focus=[234]00", "heap_alloc"},
83
+		{"dot,alloc_space,flat,tagshow=[2]00", "heap_alloc"},
81 84
 		{"dot,alloc_space,flat,hide=line.*1?23?", "heap_alloc"},
82 85
 		{"dot,inuse_space,flat,tagfocus=1mb:2gb", "heap"},
83 86
 		{"dot,inuse_space,flat,tagfocus=30kb:,tagignore=1mb:2mb", "heap"},

+ 1
- 1
internal/driver/testdata/pprof.contention.flat.addresses.dot.focus.ignore Vedi File

@@ -1,6 +1,6 @@
1 1
 digraph "unnamed" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "Build ID: buildid-contention" [shape=box fontsize=16 label="Build ID: buildid-contention\lComment #1\lComment #2\lType: delay\lShowing nodes accounting for 40.96ms, 27.40% of 149.50ms total\l"] }
3
+subgraph cluster_L { "Build ID: buildid-contention" [shape=box fontsize=16 label="Build ID: buildid-contention\lComment #1\lComment #2\lType: delay\lActive filters:\l   focus=[X1]000\l   ignore=[X3]002\lShowing nodes accounting for 40.96ms, 27.40% of 149.50ms total\l"] }
4 4
 N1 [label="0000000000001000\nline1000\nfile1000.src:1\n40.96ms (27.40%)" fontsize=24 shape=box tooltip="0000000000001000 line1000 testdata/file1000.src:1 (40.96ms)" color="#b23900" fillcolor="#edddd5"]
5 5
 N2 [label="0000000000003001\nline3000\nfile3000.src:5\n0 of 40.96ms (27.40%)" fontsize=8 shape=box tooltip="0000000000003001 line3000 testdata/file3000.src:5 (40.96ms)" color="#b23900" fillcolor="#edddd5"]
6 6
 N3 [label="0000000000003001\nline3001\nfile3000.src:3\n0 of 40.96ms (27.40%)" fontsize=8 shape=box tooltip="0000000000003001 line3001 testdata/file3000.src:3 (40.96ms)" color="#b23900" fillcolor="#edddd5"]

+ 8
- 0
internal/driver/testdata/pprof.cpu.cum.lines.text.focus.hide Vedi File

@@ -0,0 +1,8 @@
1
+Active filters:
2
+   focus=[12]00
3
+   hide=line[X3]0
4
+Showing nodes accounting for 1.11s, 99.11% of 1.12s total
5
+      flat  flat%   sum%        cum   cum%
6
+     1.10s 98.21% 98.21%      1.10s 98.21%  line1000 testdata/file1000.src:1
7
+         0     0% 98.21%      1.01s 90.18%  line2000 testdata/file2000.src:4
8
+     0.01s  0.89% 99.11%      1.01s 90.18%  line2001 testdata/file2000.src:9 (inline)

+ 2
- 0
internal/driver/testdata/pprof.cpu.cum.lines.text.hide Vedi File

@@ -1,3 +1,5 @@
1
+Active filters:
2
+   hide=line[X3]0
1 3
 Showing nodes accounting for 1.11s, 99.11% of 1.12s total
2 4
       flat  flat%   sum%        cum   cum%
3 5
      1.10s 98.21% 98.21%      1.10s 98.21%  line1000 testdata/file1000.src:1

+ 2
- 0
internal/driver/testdata/pprof.cpu.cum.lines.text.show Vedi File

@@ -1,3 +1,5 @@
1
+Active filters:
2
+   show=[12]00
1 3
 Showing nodes accounting for 1.11s, 99.11% of 1.12s total
2 4
       flat  flat%   sum%        cum   cum%
3 5
      1.10s 98.21% 98.21%      1.10s 98.21%  line1000 testdata/file1000.src:1

+ 2
- 0
internal/driver/testdata/pprof.cpu.cum.lines.topproto.hide Vedi File

@@ -1,3 +1,5 @@
1
+Active filters:
2
+   hide=mangled[X3]0
1 3
 Showing nodes accounting for 1s, 100% of 1s total
2 4
       flat  flat%   sum%        cum   cum%
3 5
         1s   100%   100%         1s   100%  mangled1000 testdata/file1000.src:1

+ 2
- 0
internal/driver/testdata/pprof.heap.cum.lines.tree.focus Vedi File

@@ -1,3 +1,5 @@
1
+Active filters:
2
+   focus=[24]00
1 3
 Showing nodes accounting for 62.50MB, 63.37% of 98.63MB total
2 4
 Dropped 2 nodes (cum <= 4.93MB)
3 5
 ----------------------------------------------------------+-------------

+ 2
- 0
internal/driver/testdata/pprof.heap.cum.relative_percentages.tree.focus Vedi File

@@ -1,3 +1,5 @@
1
+Active filters:
2
+   focus=[24]00
1 3
 Showing nodes accounting for 62.50MB, 98.46% of 63.48MB total
2 4
 Dropped 2 nodes (cum <= 3.17MB)
3 5
 ----------------------------------------------------------+-------------

+ 8
- 0
internal/driver/testdata/pprof.heap.flat.files.text.focus Vedi File

@@ -0,0 +1,8 @@
1
+Active filters:
2
+   focus=[12]00
3
+   taghide=[X3]00
4
+Showing nodes accounting for 67.38MB, 68.32% of 98.63MB total
5
+      flat  flat%   sum%        cum   cum%
6
+   62.50MB 63.37% 63.37%    63.48MB 64.36%  testdata/file2000.src
7
+    4.88MB  4.95% 68.32%     4.88MB  4.95%  testdata/file1000.src
8
+         0     0% 68.32%    67.38MB 68.32%  testdata/file3000.src

+ 1
- 1
internal/driver/testdata/pprof.heap.flat.inuse_space.dot.focus Vedi File

@@ -1,6 +1,6 @@
1 1
 digraph "unnamed" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "Build ID: buildid" [shape=box fontsize=16 label="Build ID: buildid\lcomment\lType: inuse_space\lShowing nodes accounting for 62.50MB, 63.37% of 98.63MB total\l"] }
3
+subgraph cluster_L { "Build ID: buildid" [shape=box fontsize=16 label="Build ID: buildid\lcomment\lType: inuse_space\lActive filters:\l   tagfocus=1mb:2gb\lShowing nodes accounting for 62.50MB, 63.37% of 98.63MB total\l"] }
4 4
 N1 [label="line2001\n62.50MB (63.37%)" fontsize=24 shape=box tooltip="line2001 (62.50MB)" color="#b21600" fillcolor="#edd8d5"]
5 5
 NN1_0 [label = "1.56MB" fontsize=8 shape=box3d tooltip="62.50MB"]
6 6
 N1 -> NN1_0 [label=" 62.50MB" weight=100 tooltip="62.50MB" labeltooltip="62.50MB"]

+ 1
- 1
internal/driver/testdata/pprof.heap.flat.inuse_space.dot.focus.ignore Vedi File

@@ -1,6 +1,6 @@
1 1
 digraph "unnamed" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "Build ID: buildid" [shape=box fontsize=16 label="Build ID: buildid\lcomment\lType: inuse_space\lShowing nodes accounting for 36.13MB, 36.63% of 98.63MB total\lDropped 2 nodes (cum <= 4.93MB)\l"] }
3
+subgraph cluster_L { "Build ID: buildid" [shape=box fontsize=16 label="Build ID: buildid\lcomment\lType: inuse_space\lActive filters:\l   tagfocus=30kb:\l   tagignore=1mb:2mb\lShowing nodes accounting for 36.13MB, 36.63% of 98.63MB total\lDropped 2 nodes (cum <= 4.93MB)\l"] }
4 4
 N1 [label="line3002\n31.25MB (31.68%)\nof 32.23MB (32.67%)" fontsize=24 shape=box tooltip="line3002 (32.23MB)" color="#b23200" fillcolor="#eddcd5"]
5 5
 NN1_0 [label = "400kB" fontsize=8 shape=box3d tooltip="31.25MB"]
6 6
 N1 -> NN1_0 [label=" 31.25MB" weight=100 tooltip="31.25MB" labeltooltip="31.25MB"]

+ 1
- 1
internal/driver/testdata/pprof.heap.flat.lines.dot.focus Vedi File

@@ -1,6 +1,6 @@
1 1
 digraph "unnamed" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "Build ID: buildid" [shape=box fontsize=16 label="Build ID: buildid\lcomment\lType: inuse_space\lShowing nodes accounting for 67.38MB, 68.32% of 98.63MB total\l"] }
3
+subgraph cluster_L { "Build ID: buildid" [shape=box fontsize=16 label="Build ID: buildid\lcomment\lType: inuse_space\lActive filters:\l   focus=[12]00\lShowing nodes accounting for 67.38MB, 68.32% of 98.63MB total\l"] }
4 4
 N1 [label="line3000\nfile3000.src:4\n0 of 67.38MB (68.32%)" fontsize=8 shape=box tooltip="line3000 testdata/file3000.src:4 (67.38MB)" color="#b21300" fillcolor="#edd7d5"]
5 5
 N2 [label="line2001\nfile2000.src:2\n62.50MB (63.37%)\nof 63.48MB (64.36%)" fontsize=24 shape=box tooltip="line2001 testdata/file2000.src:2 (63.48MB)" color="#b21600" fillcolor="#edd8d5"]
6 6
 NN2_0 [label = "1.56MB" fontsize=8 shape=box3d tooltip="62.50MB"]

+ 14
- 0
internal/driver/testdata/pprof.heap_alloc.flat.alloc_space.dot Vedi File

@@ -0,0 +1,14 @@
1
+digraph "unnamed" {
2
+node [style=filled fillcolor="#f8f8f8"]
3
+subgraph cluster_L { "Build ID: buildid" [shape=box fontsize=16 label="Build ID: buildid\lcomment\lType: alloc_space\lActive filters:\l   tagshow=[2]00\lShowing nodes accounting for 93.75MB, 95.05% of 98.63MB total\lDropped 1 node (cum <= 4.93MB)\l"] }
4
+N1 [label="line3002\n31.25MB (31.68%)\nof 94.73MB (96.04%)" fontsize=20 shape=box tooltip="line3002 (94.73MB)" color="#b20200" fillcolor="#edd5d5"]
5
+N2 [label="line3000\n0 of 98.63MB (100%)" fontsize=8 shape=box tooltip="line3000 (98.63MB)" color="#b20000" fillcolor="#edd5d5"]
6
+N3 [label="line2001\n62.50MB (63.37%)\nof 63.48MB (64.36%)" fontsize=24 shape=box tooltip="line2001 (63.48MB)" color="#b21600" fillcolor="#edd8d5"]
7
+N4 [label="line2000\n0 of 63.48MB (64.36%)" fontsize=8 shape=box tooltip="line2000 (63.48MB)" color="#b21600" fillcolor="#edd8d5"]
8
+N5 [label="line3001\n0 of 36.13MB (36.63%)" fontsize=8 shape=box tooltip="line3001 (36.13MB)" color="#b22e00" fillcolor="#eddbd5"]
9
+N4 -> N3 [label=" 63.48MB\n (inline)" weight=65 penwidth=4 color="#b21600" tooltip="line2000 -> line2001 (63.48MB)" labeltooltip="line2000 -> line2001 (63.48MB)"]
10
+N1 -> N4 [label=" 63.48MB" weight=65 penwidth=4 color="#b21600" tooltip="line3002 -> line2000 (63.48MB)" labeltooltip="line3002 -> line2000 (63.48MB)"]
11
+N2 -> N1 [label=" 62.50MB\n (inline)" weight=64 penwidth=4 color="#b21600" tooltip="line3000 -> line3002 (62.50MB)" labeltooltip="line3000 -> line3002 (62.50MB)"]
12
+N2 -> N5 [label=" 36.13MB\n (inline)" weight=37 penwidth=2 color="#b22e00" tooltip="line3000 -> line3001 (36.13MB)" labeltooltip="line3000 -> line3001 (36.13MB)"]
13
+N5 -> N1 [label=" 32.23MB\n (inline)" weight=33 penwidth=2 color="#b23200" tooltip="line3001 -> line3002 (32.23MB)" labeltooltip="line3001 -> line3002 (32.23MB)"]
14
+}

+ 1
- 1
internal/driver/testdata/pprof.heap_alloc.flat.alloc_space.dot.focus Vedi File

@@ -1,6 +1,6 @@
1 1
 digraph "unnamed" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "Build ID: buildid" [shape=box fontsize=16 label="Build ID: buildid\lcomment\lType: alloc_space\lShowing nodes accounting for 93.75MB, 95.05% of 98.63MB total\lDropped 1 node (cum <= 4.93MB)\l"] }
3
+subgraph cluster_L { "Build ID: buildid" [shape=box fontsize=16 label="Build ID: buildid\lcomment\lType: alloc_space\lActive filters:\l   focus=[234]00\lShowing nodes accounting for 93.75MB, 95.05% of 98.63MB total\lDropped 1 node (cum <= 4.93MB)\l"] }
4 4
 N1 [label="line3002\n31.25MB (31.68%)\nof 94.73MB (96.04%)" fontsize=20 shape=box tooltip="line3002 (94.73MB)" color="#b20200" fillcolor="#edd5d5"]
5 5
 NN1_0 [label = "400kB" fontsize=8 shape=box3d tooltip="31.25MB"]
6 6
 N1 -> NN1_0 [label=" 31.25MB" weight=100 tooltip="31.25MB" labeltooltip="31.25MB"]

+ 1
- 1
internal/driver/testdata/pprof.heap_alloc.flat.alloc_space.dot.hide Vedi File

@@ -1,6 +1,6 @@
1 1
 digraph "unnamed" {
2 2
 node [style=filled fillcolor="#f8f8f8"]
3
-subgraph cluster_L { "Build ID: buildid" [shape=box fontsize=16 label="Build ID: buildid\lcomment\lType: alloc_space\lShowing nodes accounting for 93.75MB, 95.05% of 98.63MB total\lDropped 1 node (cum <= 4.93MB)\l"] }
3
+subgraph cluster_L { "Build ID: buildid" [shape=box fontsize=16 label="Build ID: buildid\lcomment\lType: alloc_space\lActive filters:\l   hide=line.*1?23?\lShowing nodes accounting for 93.75MB, 95.05% of 98.63MB total\lDropped 1 node (cum <= 4.93MB)\l"] }
4 4
 N1 [label="line3000\n62.50MB (63.37%)\nof 98.63MB (100%)" fontsize=24 shape=box tooltip="line3000 (98.63MB)" color="#b20000" fillcolor="#edd5d5"]
5 5
 NN1_0 [label = "1.56MB" fontsize=8 shape=box3d tooltip="62.50MB"]
6 6
 N1 -> NN1_0 [label=" 62.50MB" weight=100 tooltip="62.50MB" labeltooltip="62.50MB"]

+ 18
- 0
internal/report/report.go Vedi File

@@ -64,6 +64,7 @@ type Options struct {
64 64
 	Ratio               float64
65 65
 	Title               string
66 66
 	ProfileLabels       []string
67
+	ActiveFilters       []string
67 68
 
68 69
 	NodeCount    int
69 70
 	NodeFraction float64
@@ -1070,6 +1071,11 @@ func reportLabels(rpt *Report, g *graph.Graph, origCount, droppedNodes, droppedE
1070 1071
 		flatSum = flatSum + n.FlatValue()
1071 1072
 	}
1072 1073
 
1074
+	if len(rpt.options.ActiveFilters) > 0 {
1075
+		activeFilters := legendActiveFilters(rpt.options.ActiveFilters)
1076
+		label = append(label, activeFilters...)
1077
+	}
1078
+
1073 1079
 	label = append(label, fmt.Sprintf("Showing nodes accounting for %s, %s of %s total", rpt.formatValue(flatSum), strings.TrimSpace(percentage(flatSum, rpt.total)), rpt.formatValue(rpt.total)))
1074 1080
 
1075 1081
 	if rpt.total != 0 {
@@ -1089,6 +1095,18 @@ func reportLabels(rpt *Report, g *graph.Graph, origCount, droppedNodes, droppedE
1089 1095
 	return label
1090 1096
 }
1091 1097
 
1098
+func legendActiveFilters(activeFilters []string) []string {
1099
+	legendActiveFilters := make([]string, len(activeFilters)+1)
1100
+	legendActiveFilters[0] = "Active filters:"
1101
+	for i, s := range activeFilters {
1102
+		if len(s) > 80 {
1103
+			s = s[:80] + "…"
1104
+		}
1105
+		legendActiveFilters[i+1] = "   " + s
1106
+	}
1107
+	return legendActiveFilters
1108
+}
1109
+
1092 1110
 func genLabel(d int, n, l, f string) string {
1093 1111
 	if d > 1 {
1094 1112
 		n = n + "s"

+ 21
- 0
internal/report/report_test.go Vedi File

@@ -264,3 +264,24 @@ func TestFunctionMap(t *testing.T) {
264 264
 		}
265 265
 	}
266 266
 }
267
+
268
+func TestLegendActiveFilters(t *testing.T) {
269
+	activeFilterInput := []string{
270
+		"focus=123|456|789|101112|131415|161718|192021|222324|252627|282930|313233|343536|363738|acbdefghijklmnop",
271
+		"show=short filter",
272
+	}
273
+	expectedLegendActiveFilter := []string{
274
+		"Active filters:",
275
+		"   focus=123|456|789|101112|131415|161718|192021|222324|252627|282930|313233|343536…",
276
+		"   show=short filter",
277
+	}
278
+	legendActiveFilter := legendActiveFilters(activeFilterInput)
279
+	if len(legendActiveFilter) != len(expectedLegendActiveFilter) {
280
+		t.Errorf("wanted length %v got length %v", len(expectedLegendActiveFilter), len(legendActiveFilter))
281
+	}
282
+	for i := range legendActiveFilter {
283
+		if legendActiveFilter[i] != expectedLegendActiveFilter[i] {
284
+			t.Errorf("%d: want \"%v\", got \"%v\"", i, expectedLegendActiveFilter[i], legendActiveFilter[i])
285
+		}
286
+	}
287
+}