]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/pgo: move pprof graph to internal package
authorMichael Pratt <mpratt@google.com>
Thu, 11 May 2023 18:27:25 +0000 (14:27 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 11 May 2023 20:54:03 +0000 (20:54 +0000)
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>

src/cmd/compile/internal/pgo/internal/graph/graph.go [moved from src/cmd/compile/internal/pgo/graph.go with 98% similarity]
src/cmd/compile/internal/pgo/irgraph.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 a2cf18f936aea552ca71e289ba62e1b62def4fee..72d3f2194da794305e22e9725c27a17b09d3e46d 100644 (file)
 // 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)
index 42ba27afb7a8693bb9202ff6843e94588958e618..4a9de2ef00fcc083f7edae6025ed10b4cd029365 100644 (file)
@@ -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