@@ -8,14 +8,19 @@ import (
88
99type funcSizeRunner struct {
1010 messageRE * regexp.Regexp
11+ filterRE * regexp.Regexp
1112}
1213
1314func (r * funcSizeRunner ) Init () {
1415 r .messageRE = regexp .MustCompile (`(.*) STEXT.* size=(\d+)` )
16+ if filter != "" {
17+ r .filterRE = regexp .MustCompile (filter )
18+ }
1519}
1620
1721func (r * funcSizeRunner ) Run (pkg string ) error {
1822 cmd := exec .Command ("go" , r .getCmd (pkg )... )
23+
1924 out , err := cmd .CombinedOutput ()
2025 if err != nil {
2126 return fmt .Errorf ("%v: %s" , err , out )
@@ -27,13 +32,15 @@ func (r *funcSizeRunner) Run(pkg string) error {
2732 }
2833 results := []resultRow {}
2934
30- // TODO: add a CLI flag for the function name filtering?
31- // Having to use a grep in 99% of use cases is not very convenient.
3235 for _ , submatches := range r .messageRE .FindAllStringSubmatch (string (out ), - 1 ) {
33- results = append (results , resultRow {
34- Fn : submatches [1 ],
35- Size : submatches [2 ],
36- })
36+ fn , size := submatches [1 ], submatches [2 ]
37+
38+ if r .passesFilter (fn ) {
39+ results = append (results , resultRow {
40+ Fn : fn ,
41+ Size : size ,
42+ })
43+ }
3744 }
3845
3946 if asJSON {
@@ -47,6 +54,10 @@ func (r *funcSizeRunner) Run(pkg string) error {
4754 return nil
4855}
4956
57+ func (r * funcSizeRunner ) passesFilter (fn string ) bool {
58+ return r .filterRE == nil || r .filterRE .MatchString (fn )
59+ }
60+
5061func (r * funcSizeRunner ) getCmd (pkg string ) []string {
5162 return goArgs (pkg , goArgsBuild , goArgsGcFlags ("-S" ))
5263}
0 commit comments