Browse Source

Support sign in tagfocus (#438)

Support sign in tagfocus
Matt Fowles Kulukundis 6 years ago
parent
commit
b4f47329b9
2 changed files with 16 additions and 1 deletions
  1. 1
    1
      internal/driver/driver_focus.go
  2. 15
    0
      internal/driver/driver_test.go

+ 1
- 1
internal/driver/driver_focus.go View File

25
 	"github.com/google/pprof/profile"
25
 	"github.com/google/pprof/profile"
26
 )
26
 )
27
 
27
 
28
-var tagFilterRangeRx = regexp.MustCompile("([[:digit:]]+)([[:alpha:]]+)")
28
+var tagFilterRangeRx = regexp.MustCompile("([+-]?[[:digit:]]+)([[:alpha:]]+)")
29
 
29
 
30
 // applyFocus filters samples based on the focus/ignore options
30
 // applyFocus filters samples based on the focus/ignore options
31
 func applyFocus(prof *profile.Profile, numLabelUnits map[string]string, v variables, ui plugin.UI) error {
31
 func applyFocus(prof *profile.Profile, numLabelUnits map[string]string, v variables, ui plugin.UI) error {

+ 15
- 0
internal/driver/driver_test.go View File

96
 		{"peek=line.*01", "cpu"},
96
 		{"peek=line.*01", "cpu"},
97
 		{"weblist=line[13],addresses,flat", "cpu"},
97
 		{"weblist=line[13],addresses,flat", "cpu"},
98
 		{"tags,tagfocus=400kb:", "heap_request"},
98
 		{"tags,tagfocus=400kb:", "heap_request"},
99
+		{"tags,tagfocus=+400kb:", "heap_request"},
99
 		{"dot", "longNameFuncs"},
100
 		{"dot", "longNameFuncs"},
100
 		{"text", "longNameFuncs"},
101
 		{"text", "longNameFuncs"},
101
 	}
102
 	}
1440
 			map[string]string{"key1": "bytes"},
1441
 			map[string]string{"key1": "bytes"},
1441
 			false,
1442
 			false,
1442
 		},
1443
 		},
1444
+		{
1445
+			"Match negative key and range of values, value matches",
1446
+			"bytes=-512b:-128b",
1447
+			map[string][]int64{"bytes": {-256}},
1448
+			map[string]string{"bytes": "bytes"},
1449
+			true,
1450
+		},
1451
+		{
1452
+			"Match negative key and range of values, value outside range",
1453
+			"bytes=-512b:-128b",
1454
+			map[string][]int64{"bytes": {-2048}},
1455
+			map[string]string{"bytes": "bytes"},
1456
+			false,
1457
+		},
1443
 	}
1458
 	}
1444
 	for _, test := range tagFilterTests {
1459
 	for _, test := range tagFilterTests {
1445
 		t.Run(test.desc, func(*testing.T) {
1460
 		t.Run(test.desc, func(*testing.T) {