cmd/compile: add countRule rewrite rule helper

noteRule is useful when you're trying to debug
a particular rule, or get a general sense for
how often a rule fires overall.

It is less useful if you're trying to figure
out which functions might be useful to benchmark
to ascertain the impact of a newly added rule.

Enter countRule. You use it like noteRule,
except that you get per-function summaries.

Sample output:

 # runtime
(*mspan).sweep: idx1=1
evacuate_faststr: idx1=1
evacuate_fast32: idx1=1
evacuate: idx1=2
evacuate_fast64: idx1=1
sweepone: idx1=1
purgecachedstats: idx1=1
mProf_Free: idx1=1

This suggests that the map benchmarks
might be good to run for this added rule.

Change-Id: Id471c3231f1736165f2020f6979ff01c29677808
Reviewed-on: https://go-review.googlesource.com/c/go/+/167088
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2019-03-11 19:22:49 -07:00
parent 591454c44c
commit 0047353c53
3 changed files with 35 additions and 3 deletions

View file

@ -5,6 +5,7 @@
package ssa
import (
"bytes"
"cmd/internal/objabi"
"cmd/internal/src"
"fmt"
@ -14,6 +15,7 @@ import (
"os"
"regexp"
"runtime"
"sort"
"strings"
"time"
)
@ -133,6 +135,21 @@ func Compile(f *Func) {
}
}
if f.ruleMatches != nil {
var keys []string
for key := range f.ruleMatches {
keys = append(keys, key)
}
sort.Strings(keys)
buf := new(bytes.Buffer)
fmt.Fprintf(buf, "%s: ", f.Name)
for _, key := range keys {
fmt.Fprintf(buf, "%s=%d ", key, f.ruleMatches[key])
}
fmt.Fprint(buf, "\n")
fmt.Print(buf.String())
}
// Squash error printing defer
phaseName = ""
}