]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/devirtualize: sort equal weight CallStat.Hottest by name
authorMichael Pratt <mpratt@google.com>
Tue, 12 Sep 2023 18:23:15 +0000 (14:23 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 12 Sep 2023 18:40:16 +0000 (18:40 +0000)
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>

src/cmd/compile/internal/devirtualize/pgo.go

index 800b32f6ebf8cb5637d4bf6f5084023516523a26..b51028701ee214212f35047c0dcff7fc87ced5bf 100644 (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()
                }