splitIntoRanges converts the set of addresses we are interested in into a set of address ranges to disassemble. It also returns the set of addresses found that did not have an associated object file and were therefore not added to an address range.
(prof *profile.Profile, addrMap map[uint64]addrInfo, flat map[uint64]int64)
| 545 | // ranges to disassemble. It also returns the set of addresses found that did not have an |
| 546 | // associated object file and were therefore not added to an address range. |
| 547 | func (sp *sourcePrinter) splitIntoRanges(prof *profile.Profile, addrMap map[uint64]addrInfo, flat map[uint64]int64) ([]addressRange, []uint64) { |
| 548 | // Partition addresses into two sets: ones with a known object file, and ones without. |
| 549 | var addrs, unprocessed []uint64 |
| 550 | for addr, info := range addrMap { |
| 551 | if info.obj != nil { |
| 552 | addrs = append(addrs, addr) |
| 553 | } else { |
| 554 | unprocessed = append(unprocessed, addr) |
| 555 | } |
| 556 | } |
| 557 | slices.Sort(addrs) |
| 558 | |
| 559 | const expand = 500 // How much to expand range to pick up nearby addresses. |
| 560 | var result []addressRange |
| 561 | for i, n := 0, len(addrs); i < n; { |
| 562 | begin, end := addrs[i], addrs[i] |
| 563 | sum := flat[begin] |
| 564 | i++ |
| 565 | |
| 566 | info := addrMap[begin] |
| 567 | m := info.loc.Mapping |
| 568 | obj := info.obj // Non-nil because of the partitioning done above. |
| 569 | |
| 570 | // Find following addresses that are close enough to addrs[i]. |
| 571 | for i < n && addrs[i] <= end+2*expand && addrs[i] < m.Limit { |
| 572 | // When we expand ranges by "expand" on either side, the ranges |
| 573 | // for addrs[i] and addrs[i-1] will merge. |
| 574 | end = addrs[i] |
| 575 | sum += flat[end] |
| 576 | i++ |
| 577 | } |
| 578 | if m.Start-begin >= expand { |
| 579 | begin -= expand |
| 580 | } else { |
| 581 | begin = m.Start |
| 582 | } |
| 583 | if m.Limit-end >= expand { |
| 584 | end += expand |
| 585 | } else { |
| 586 | end = m.Limit |
| 587 | } |
| 588 | |
| 589 | result = append(result, addressRange{begin, end, obj, m, sum}) |
| 590 | } |
| 591 | return result, unprocessed |
| 592 | } |
| 593 | |
| 594 | func (sp *sourcePrinter) initSamples(flat, cum map[uint64]int64) { |
| 595 | for addr, inst := range sp.insts { |