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 <cherryyz@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>
This commit is contained in:
Michael Pratt 2023-05-11 14:27:25 -04:00 committed by Gopher Robot
parent c2becd70c5
commit d740b365b7
2 changed files with 9 additions and 8 deletions

View file

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// Package graph collects a set of samples into a directed graph. // Package graph represents a pprof profile as a directed graph.
//
// Original file location: https://github.com/google/pprof/tree/main/internal/graph/graph.go // This package is a simplified fork of github.com/google/pprof/internal/graph.
package pgo package graph
import ( import (
"fmt" "fmt"
@ -245,8 +245,8 @@ func (e *Edge) WeightValue() int64 {
return e.Weight / e.WeightDiv return e.Weight / e.WeightDiv
} }
// newGraph computes a graph from a profile. // NewGraph computes a graph from a profile.
func newGraph(prof *profile.Profile, o *Options) *Graph { func NewGraph(prof *profile.Profile, o *Options) *Graph {
nodes, locationMap := CreateNodes(prof, o) nodes, locationMap := CreateNodes(prof, o)
seenNode := make(map[*Node]bool) seenNode := make(map[*Node]bool)
seenEdge := make(map[nodePair]bool) seenEdge := make(map[nodePair]bool)

View file

@ -43,6 +43,7 @@ package pgo
import ( import (
"cmd/compile/internal/base" "cmd/compile/internal/base"
"cmd/compile/internal/ir" "cmd/compile/internal/ir"
"cmd/compile/internal/pgo/internal/graph"
"cmd/compile/internal/typecheck" "cmd/compile/internal/typecheck"
"cmd/compile/internal/types" "cmd/compile/internal/types"
"fmt" "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"`) 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, CallTree: false,
SampleValue: func(v []int64) int64 { return v[valueIndex] }, SampleValue: func(v []int64) int64 { return v[valueIndex] },
}) })
@ -189,7 +190,7 @@ func New(profileFile string) (*Profile, error) {
// create edges for WeightedCG. // create edges for WeightedCG.
// //
// Caller should ignore the profile if p.TotalNodeWeight == 0 || p.TotalEdgeWeight == 0. // 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) nFlat := make(map[string]int64)
nCum := make(map[string]int64) nCum := make(map[string]int64)
seenStartLine := false seenStartLine := false