aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vendor/github.com/google/pprof/internal/graph/graph.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/vendor/github.com/google/pprof/internal/graph/graph.go')
-rw-r--r--src/cmd/vendor/github.com/google/pprof/internal/graph/graph.go43
1 files changed, 30 insertions, 13 deletions
diff --git a/src/cmd/vendor/github.com/google/pprof/internal/graph/graph.go b/src/cmd/vendor/github.com/google/pprof/internal/graph/graph.go
index c4b0d4869f..ee7a700174 100644
--- a/src/cmd/vendor/github.com/google/pprof/internal/graph/graph.go
+++ b/src/cmd/vendor/github.com/google/pprof/internal/graph/graph.go
@@ -196,6 +196,21 @@ func (i *NodeInfo) NameComponents() []string {
return name
}
+// comparePrintableName compares NodeInfo lexicographically the same way as `i.PrintableName() < right.PrintableName()`, but much more performant.
+func (i *NodeInfo) comparePrintableName(right NodeInfo) (equal bool, less bool) {
+ if right == *i {
+ return true, false
+ }
+
+ if i.Address != 0 && right.Address != 0 && i.Address != right.Address {
+ // comparing ints directly is the same as comparing padded hex from fmt.Sprintf("%016x", Address)
+ return false, i.Address < right.Address
+ }
+
+ // fallback
+ return false, i.PrintableName() < right.PrintableName()
+}
+
// NodeMap maps from a node info struct to a node. It is used to merge
// report entries with the same info.
type NodeMap map[NodeInfo]*Node
@@ -583,17 +598,16 @@ func (nm NodeMap) findOrInsertLine(l *profile.Location, li profile.Line, o *Opti
objfile = m.File
}
- if ni := nodeInfo(l, li, objfile, o); ni != nil {
- return nm.FindOrInsertNode(*ni, o.KeptNodes)
- }
- return nil
+ ni := nodeInfo(l, li, objfile, o)
+
+ return nm.FindOrInsertNode(ni, o.KeptNodes)
}
-func nodeInfo(l *profile.Location, line profile.Line, objfile string, o *Options) *NodeInfo {
+func nodeInfo(l *profile.Location, line profile.Line, objfile string, o *Options) NodeInfo {
if line.Function == nil {
- return &NodeInfo{Address: l.Address, Objfile: objfile}
+ return NodeInfo{Address: l.Address, Objfile: objfile}
}
- ni := &NodeInfo{
+ ni := NodeInfo{
Address: l.Address,
Lineno: int(line.Line),
Columnno: int(line.Column),
@@ -951,8 +965,9 @@ func (ns Nodes) Sort(o NodeOrder) error {
if iv, jv := abs64(l.Flat), abs64(r.Flat); iv != jv {
return iv > jv
}
- if iv, jv := l.Info.PrintableName(), r.Info.PrintableName(); iv != jv {
- return iv < jv
+ equal, leftLess := l.Info.comparePrintableName(r.Info)
+ if !equal {
+ return leftLess
}
if iv, jv := abs64(l.Cum), abs64(r.Cum); iv != jv {
return iv > jv
@@ -969,8 +984,9 @@ func (ns Nodes) Sort(o NodeOrder) error {
if iv, jv := abs64(l.Cum), abs64(r.Cum); iv != jv {
return iv > jv
}
- if iv, jv := l.Info.PrintableName(), r.Info.PrintableName(); iv != jv {
- return iv < jv
+ equal, leftLess := l.Info.comparePrintableName(r.Info)
+ if !equal {
+ return leftLess
}
return compareNodes(l, r)
},
@@ -1012,8 +1028,9 @@ func (ns Nodes) Sort(o NodeOrder) error {
if iv, jv := abs64(score[l]), abs64(score[r]); iv != jv {
return iv > jv
}
- if iv, jv := l.Info.PrintableName(), r.Info.PrintableName(); iv != jv {
- return iv < jv
+ equal, leftLess := l.Info.comparePrintableName(r.Info)
+ if !equal {
+ return leftLess
}
if iv, jv := abs64(l.Flat), abs64(r.Flat); iv != jv {
return iv > jv