mirror of https://github.com/golang/go.git
cmd/compile/internal/pgo: allow and ignore profiles with no sample
Passing a profile with no sample is arguably not a user error. Accept such a profile, and ignore it as it doesn't indicate any optimizations. This also makes testing easier. Change-Id: Iae49a4260e20757419643153f50d8d5d51478411 Reviewed-on: https://go-review.googlesource.com/c/go/+/448495 Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
0409314db3
commit
efe541d4e5
|
|
@ -153,7 +153,9 @@ func New(profileFile string) *Profile {
|
|||
}
|
||||
|
||||
// Build the node map and totals from the profile graph.
|
||||
p.processprofileGraph(g)
|
||||
if !p.processprofileGraph(g) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create package-level call graph with weights from profile and IR.
|
||||
p.initializeIRGraph()
|
||||
|
|
@ -166,7 +168,8 @@ func New(profileFile string) *Profile {
|
|||
// It initializes NodeMap and Total{Node,Edge}Weight based on the name and
|
||||
// callsite to compute node and edge weights which will be used later on to
|
||||
// create edges for WeightedCG.
|
||||
func (p *Profile) processprofileGraph(g *Graph) {
|
||||
// Returns whether it successfully processed the profile.
|
||||
func (p *Profile) processprofileGraph(g *Graph) bool {
|
||||
nFlat := make(map[string]int64)
|
||||
nCum := make(map[string]int64)
|
||||
seenStartLine := false
|
||||
|
|
@ -206,12 +209,18 @@ func (p *Profile) processprofileGraph(g *Graph) {
|
|||
}
|
||||
}
|
||||
|
||||
if p.TotalNodeWeight == 0 || p.TotalEdgeWeight == 0 {
|
||||
return false // accept but ignore profile with no sample
|
||||
}
|
||||
|
||||
if !seenStartLine {
|
||||
// TODO(prattic): If Function.start_line is missing we could
|
||||
// fall back to using absolute line numbers, which is better
|
||||
// than nothing.
|
||||
log.Fatal("PGO profile missing Function.start_line data")
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// initializeIRGraph builds the IRGraph by visting all the ir.Func in decl list
|
||||
|
|
@ -352,11 +361,7 @@ func (p *Profile) createIRGraphEdge(fn *ir.Func, callernode *IRNode, name string
|
|||
|
||||
// WeightInPercentage converts profile weights to a percentage.
|
||||
func WeightInPercentage(value int64, total int64) float64 {
|
||||
var ratio float64
|
||||
if total != 0 {
|
||||
ratio = (float64(value) / float64(total)) * 100
|
||||
}
|
||||
return ratio
|
||||
return (float64(value) / float64(total)) * 100
|
||||
}
|
||||
|
||||
// PrintWeightedCallGraphDOT prints IRGraph in DOT format.
|
||||
|
|
|
|||
Loading…
Reference in New Issue