(prof *profile.Profile, o *Options)
| 414 | } |
| 415 | |
| 416 | func newTree(prof *profile.Profile, o *Options) (g *Graph) { |
| 417 | parentNodeMap := make(map[*Node]NodeMap, len(prof.Sample)) |
| 418 | for _, sample := range prof.Sample { |
| 419 | var w, dw int64 |
| 420 | w = o.SampleValue(sample.Value) |
| 421 | if o.SampleMeanDivisor != nil { |
| 422 | dw = o.SampleMeanDivisor(sample.Value) |
| 423 | } |
| 424 | if dw == 0 && w == 0 { |
| 425 | continue |
| 426 | } |
| 427 | var parent *Node |
| 428 | labels := joinLabels(sample) |
| 429 | // Group the sample frames, based on a per-node map. |
| 430 | for i := len(sample.Location) - 1; i >= 0; i-- { |
| 431 | l := sample.Location[i] |
| 432 | lines := l.Line |
| 433 | if len(lines) == 0 { |
| 434 | lines = []profile.Line{{}} // Create empty line to include location info. |
| 435 | } |
| 436 | for lidx := len(lines) - 1; lidx >= 0; lidx-- { |
| 437 | nodeMap := parentNodeMap[parent] |
| 438 | if nodeMap == nil { |
| 439 | nodeMap = make(NodeMap) |
| 440 | parentNodeMap[parent] = nodeMap |
| 441 | } |
| 442 | n := nodeMap.findOrInsertLine(l, lines[lidx], o) |
| 443 | if n == nil { |
| 444 | continue |
| 445 | } |
| 446 | n.addSample(dw, w, labels, sample.NumLabel, sample.NumUnit, o.FormatTag, false) |
| 447 | if parent != nil { |
| 448 | parent.AddToEdgeDiv(n, dw, w, false, lidx != len(lines)-1) |
| 449 | } |
| 450 | parent = n |
| 451 | } |
| 452 | } |
| 453 | if parent != nil { |
| 454 | parent.addSample(dw, w, labels, sample.NumLabel, sample.NumUnit, o.FormatTag, true) |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | nodes := make(Nodes, 0, len(prof.Location)) |
| 459 | for _, nm := range parentNodeMap { |
| 460 | nodes = append(nodes, nm.nodes()...) |
| 461 | } |
| 462 | return selectNodesForGraph(nodes, o.DropNegative) |
| 463 | } |
| 464 | |
| 465 | // ShortenFunctionName returns a shortened version of a function's name. |
| 466 | func ShortenFunctionName(f string) string { |
no test coverage detected
searching dependent graphs…