From: Michael Pratt Date: Thu, 11 May 2023 18:27:25 +0000 (-0400) Subject: cmd/compile/internal/pgo: move pprof graph to internal package X-Git-Tag: go1.21rc1~577 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d740b365b7c1ecefb91b2e2fed5719c8ec49d155;p=gostls13.git cmd/compile/internal/pgo: move pprof graph to internal package graph.go is a simplified fork of github.com/google/pprof/internal/graph, which is used as an intermediate data structure to construct the final graph exported by package pgo (IRGraph). Exporting both is a bit confusing as the former is unused outside of the package. Since the naming is also similar, move graph.go to its own package entirely. Change-Id: I2bccb3ddb6c3f63afb869ea9cf34d2a261cad058 Reviewed-on: https://go-review.googlesource.com/c/go/+/494437 Reviewed-by: Cherry Mui Run-TryBot: Michael Pratt TryBot-Result: Gopher Robot Auto-Submit: Michael Pratt --- diff --git a/src/cmd/compile/internal/pgo/graph.go b/src/cmd/compile/internal/pgo/internal/graph/graph.go similarity index 98% rename from src/cmd/compile/internal/pgo/graph.go rename to src/cmd/compile/internal/pgo/internal/graph/graph.go index a2cf18f936..72d3f2194d 100644 --- a/src/cmd/compile/internal/pgo/graph.go +++ b/src/cmd/compile/internal/pgo/internal/graph/graph.go @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package graph collects a set of samples into a directed graph. - -// Original file location: https://github.com/google/pprof/tree/main/internal/graph/graph.go -package pgo +// Package graph represents a pprof profile as a directed graph. +// +// This package is a simplified fork of github.com/google/pprof/internal/graph. +package graph import ( "fmt" @@ -245,8 +245,8 @@ func (e *Edge) WeightValue() int64 { return e.Weight / e.WeightDiv } -// newGraph computes a graph from a profile. -func newGraph(prof *profile.Profile, o *Options) *Graph { +// NewGraph computes a graph from a profile. +func NewGraph(prof *profile.Profile, o *Options) *Graph { nodes, locationMap := CreateNodes(prof, o) seenNode := make(map[*Node]bool) seenEdge := make(map[nodePair]bool) diff --git a/src/cmd/compile/internal/pgo/irgraph.go b/src/cmd/compile/internal/pgo/irgraph.go index 42ba27afb7..4a9de2ef00 100644 --- a/src/cmd/compile/internal/pgo/irgraph.go +++ b/src/cmd/compile/internal/pgo/irgraph.go @@ -43,6 +43,7 @@ package pgo import ( "cmd/compile/internal/base" "cmd/compile/internal/ir" + "cmd/compile/internal/pgo/internal/graph" "cmd/compile/internal/typecheck" "cmd/compile/internal/types" "fmt" @@ -155,7 +156,7 @@ func New(profileFile string) (*Profile, error) { return nil, fmt.Errorf(`profile does not contain a sample index with value/type "samples/count" or cpu/nanoseconds"`) } - g := newGraph(profile, &Options{ + g := graph.NewGraph(profile, &graph.Options{ CallTree: false, SampleValue: func(v []int64) int64 { return v[valueIndex] }, }) @@ -189,7 +190,7 @@ func New(profileFile string) (*Profile, error) { // create edges for WeightedCG. // // Caller should ignore the profile if p.TotalNodeWeight == 0 || p.TotalEdgeWeight == 0. -func (p *Profile) processprofileGraph(g *Graph) error { +func (p *Profile) processprofileGraph(g *graph.Graph) error { nFlat := make(map[string]int64) nCum := make(map[string]int64) seenStartLine := false