mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
591454c44c
commit
0047353c53
3 changed files with 35 additions and 3 deletions
|
|
@ -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 = ""
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue