瀏覽代碼

profile: FilterSamplesByName returns the correct hnm (#190)

FilterSamplesByName should return true for hnm only when
"at least one sample" matched the show regexp.
Before this commit it always returned true
if the show regexp is not nil and p.Location is not empty.
Hyang-Ah Hana Kim 7 年之前
父節點
當前提交
57b9500a74
共有 2 個文件被更改,包括 27 次插入5 次删除
  1. 2
    1
      profile/filter.go
  2. 25
    4
      profile/profile_test.go

+ 2
- 1
profile/filter.go 查看文件

@@ -41,10 +41,11 @@ func (p *Profile) FilterSamplesByName(focus, ignore, hide, show *regexp.Regexp)
41 41
 			}
42 42
 		}
43 43
 		if show != nil {
44
-			hnm = true
45 44
 			l.Line = l.matchedLines(show)
46 45
 			if len(l.Line) == 0 {
47 46
 				hidden[l.ID] = true
47
+			} else {
48
+				hnm = true
48 49
 			}
49 50
 		}
50 51
 	}

+ 25
- 4
profile/profile_test.go 查看文件

@@ -591,10 +591,31 @@ func TestFilter(t *testing.T) {
591 591
 	}
592 592
 
593 593
 	for tx, tc := range []filterTestcase{
594
-		{nil, nil, nil, nil, true, false, false, false},
595
-		{regexp.MustCompile("notfound"), nil, nil, nil, false, false, false, false},
596
-		{nil, regexp.MustCompile("foo.c"), nil, nil, true, true, false, false},
597
-		{nil, nil, regexp.MustCompile("lib.so"), nil, true, false, true, false},
594
+		{
595
+			fm: true, // nil focus matches every sample
596
+		},
597
+		{
598
+			focus: regexp.MustCompile("notfound"),
599
+		},
600
+		{
601
+			ignore: regexp.MustCompile("foo.c"),
602
+			fm:     true,
603
+			im:     true,
604
+		},
605
+		{
606
+			hide: regexp.MustCompile("lib.so"),
607
+			fm:   true,
608
+			hm:   true,
609
+		},
610
+		{
611
+			show: regexp.MustCompile("foo.c"),
612
+			fm:   true,
613
+			hnm:  true,
614
+		},
615
+		{
616
+			show: regexp.MustCompile("notfound"),
617
+			fm:   true,
618
+		},
598 619
 	} {
599 620
 		prof := *testProfile1.Copy()
600 621
 		gf, gi, gh, gnh := prof.FilterSamplesByName(tc.focus, tc.ignore, tc.hide, tc.show)