MCPcopy Create free account
hub / github.com/google/pprof / FindOrInsertNode

Method FindOrInsertNode

internal/graph/graph.go:234–265  ·  view source on GitHub ↗

FindOrInsertNode takes the info for a node and either returns a matching node from the node map if one exists, or adds one to the map if one does not. If kept is non-nil, nodes are only added if they can be located on it.

(info NodeInfo, kept NodeSet)

Source from the content-addressed store, hash-verified

232// from the node map if one exists, or adds one to the map if one does not.
233// If kept is non-nil, nodes are only added if they can be located on it.
234func (nm NodeMap) FindOrInsertNode(info NodeInfo, kept NodeSet) *Node {
235 if kept != nil {
236 if _, ok := kept[info]; !ok {
237 return nil
238 }
239 }
240
241 if n, ok := nm[info]; ok {
242 return n
243 }
244
245 n := &Node{
246 Info: info,
247 In: make(EdgeMap),
248 Out: make(EdgeMap),
249 LabelTags: make(TagMap),
250 NumericTags: make(map[string]TagMap),
251 }
252 nm[info] = n
253 if info.Address == 0 && info.Lineno == 0 {
254 // This node represents the whole function, so point Function
255 // back to itself.
256 n.Function = n
257 return n
258 }
259 // Find a node that represents the whole function.
260 info.Address = 0
261 info.Lineno = 0
262 info.Columnno = 0
263 n.Function = nm.FindOrInsertNode(info, nil)
264 return n
265}
266
267// EdgeMap is used to represent the incoming/outgoing edges from a node.
268type EdgeMap map[*Node]*Edge

Callers 1

findOrInsertLineMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected