소스 검색

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
 	"tagignore": &variable{stringKind, "", "", helpText(
199
 	"tagignore": &variable{stringKind, "", "", helpText(
200
 		"Discard samples with tags in range or matched by regexp",
200
 		"Discard samples with tags in range or matched by regexp",
201
 		"Discard samples that do include a node with a tag matching this regexp.")},
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
 	// Heap profile options
208
 	// Heap profile options
204
 	"divide_by": &variable{floatKind, "1", "", helpText(
209
 	"divide_by": &variable{floatKind, "1", "", helpText(
205
 		"Ratio to divide all samples before visualization",
210
 		"Ratio to divide all samples before visualization",

+ 6
- 0
internal/driver/driver_focus.go 파일 보기

50
 	warnNoMatches(tagfocus == nil || tfm, "TagFocus", ui)
50
 	warnNoMatches(tagfocus == nil || tfm, "TagFocus", ui)
51
 	warnNoMatches(tagignore == nil || tim, "TagIgnore", ui)
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
 	if prunefrom != nil {
59
 	if prunefrom != nil {
54
 		prof.PruneFrom(prunefrom)
60
 		prof.PruneFrom(prunefrom)
55
 	}
61
 	}

+ 30
- 0
profile/filter.go 파일 보기

73
 	return
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
 // matchesName returns whether the location matches the regular
106
 // matchesName returns whether the location matches the regular
77
 // expression. It checks any available function names, file names, and
107
 // expression. It checks any available function names, file names, and
78
 // mapping object filename.
108
 // mapping object filename.