cmd/compile/internal/devirtualize: sort equal weight CallStat.Hottest by name

When two callees have equal weight, we need to sort by another criteria
to ensure that we get stable output.

Note that this is only for the CallStat debug JSON output. The actual
callee selection already does this secondary sort in
findHotConcreteCallee.

Change-Id: I0de105623c5ccc793ca6f5799ea25e57bc286722
Reviewed-on: https://go-review.googlesource.com/c/go/+/527796
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Michael Pratt 2023-09-12 14:23:15 -04:00 committed by Gopher Robot
parent e8ba0579e2
commit 4b17b36b3f
1 changed files with 13 additions and 1 deletions

View File

@ -223,6 +223,18 @@ func constructCallStat(p *pgo.Profile, fn *ir.Func, name string, call *ir.CallEx
offset := pgo.NodeLineOffset(call, fn)
hotter := func(e *pgo.IREdge) bool {
if stat.Hottest == "" {
return true
}
if e.Weight != stat.HottestWeight {
return e.Weight > stat.HottestWeight
}
// If weight is the same, arbitrarily sort lexicographally, as
// findHotConcreteCallee does.
return e.Dst.Name() < stat.Hottest
}
// Sum of all edges from this callsite, regardless of callee.
// For direct calls, this should be the same as the single edge
// weight (except for multiple calls on one line, which we
@ -233,7 +245,7 @@ func constructCallStat(p *pgo.Profile, fn *ir.Func, name string, call *ir.CallEx
continue
}
stat.Weight += edge.Weight
if edge.Weight > stat.HottestWeight {
if hotter(edge) {
stat.HottestWeight = edge.Weight
stat.Hottest = edge.Dst.Name()
}