瀏覽代碼

Add tagshow/taghide commands to select a subset of tags

Raul Silvera 8 年之前
父節點
當前提交
675b85cb14
共有 3 個檔案被更改,包括 42 行新增1 行删除
  1. 6
    1
      internal/driver/commands.go
  2. 6
    0
      internal/driver/driver_focus.go
  3. 30
    0
      profile/filter.go

+ 6
- 1
internal/driver/commands.go 查看文件

@@ -199,7 +199,12 @@ var pprofVariables = variables{
199 199
 	"tagignore": &variable{stringKind, "", "", helpText(
200 200
 		"Discard samples with tags in range or matched by regexp",
201 201
 		"Discard samples that do include a node with a tag matching this regexp.")},
202
-
202
+	"tagshow": &variable{stringKind, "", "", helpText(
203
+		"Only consider tags matching this regexp",
204
+		"Discard tags that do not match this regexp")},
205
+	"taghide": &variable{stringKind, "", "", helpText(
206
+		"Skip tags matching this regexp",
207
+		"Discard tags that match this regexp")},
203 208
 	// Heap profile options
204 209
 	"divide_by": &variable{floatKind, "1", "", helpText(
205 210
 		"Ratio to divide all samples before visualization",

+ 6
- 0
internal/driver/driver_focus.go 查看文件

@@ -50,6 +50,12 @@ func applyFocus(prof *profile.Profile, v variables, ui plugin.UI) error {
50 50
 	warnNoMatches(tagfocus == nil || tfm, "TagFocus", ui)
51 51
 	warnNoMatches(tagignore == nil || tim, "TagIgnore", ui)
52 52
 
53
+	tagshow, err := compileRegexOption("tagshow", v["tagshow"].value, err)
54
+	taghide, err := compileRegexOption("taghide", v["taghide"].value, err)
55
+	tns, tnh := prof.FilterTagsByName(tagshow, taghide)
56
+	warnNoMatches(tagshow == nil || tns, "TagShow", ui)
57
+	warnNoMatches(tagignore == nil || tnh, "TagHide", ui)
58
+
53 59
 	if prunefrom != nil {
54 60
 		prof.PruneFrom(prunefrom)
55 61
 	}

+ 30
- 0
profile/filter.go 查看文件

@@ -73,6 +73,36 @@ func (p *Profile) FilterSamplesByName(focus, ignore, hide, show *regexp.Regexp)
73 73
 	return
74 74
 }
75 75
 
76
+// FilterTagsByName filters the tags in a profile and only keeps
77
+// tags that match show and not hide.
78
+func (p *Profile) FilterTagsByName(show, hide *regexp.Regexp) (sm, hm bool) {
79
+	matchShow := func(name string) bool {
80
+		matchShow := show == nil || show.MatchString(name)
81
+		matchHide := hide != nil && hide.MatchString(name)
82
+
83
+		if matchShow {
84
+			sm = true
85
+		}
86
+		if matchHide {
87
+			hm = true
88
+		}
89
+		return matchShow && !matchHide
90
+	}
91
+	for _, s := range p.Sample {
92
+		for lab := range s.Label {
93
+			if !matchShow(lab) {
94
+				delete(s.Label, lab)
95
+			}
96
+		}
97
+		for lab := range s.NumLabel {
98
+			if !matchShow(lab) {
99
+				delete(s.NumLabel, lab)
100
+			}
101
+		}
102
+	}
103
+	return
104
+}
105
+
76 106
 // matchesName returns whether the location matches the regular
77 107
 // expression. It checks any available function names, file names, and
78 108
 // mapping object filename.