FilterSamplesByName filters the samples in a profile and only keeps samples where at least one frame matches focus but none match ignore. Returns true is the corresponding regexp matched at least one sample.
(focus, ignore, hide, show *regexp.Regexp)
| 22 | // samples where at least one frame matches focus but none match ignore. |
| 23 | // Returns true is the corresponding regexp matched at least one sample. |
| 24 | func (p *Profile) FilterSamplesByName(focus, ignore, hide, show *regexp.Regexp) (fm, im, hm, hnm bool) { |
| 25 | if focus == nil && ignore == nil && hide == nil && show == nil { |
| 26 | fm = true // Missing focus implies a match |
| 27 | return |
| 28 | } |
| 29 | focusOrIgnore := make(map[uint64]bool) |
| 30 | hidden := make(map[uint64]bool) |
| 31 | for _, l := range p.Location { |
| 32 | if ignore != nil && l.matchesName(ignore) { |
| 33 | im = true |
| 34 | focusOrIgnore[l.ID] = false |
| 35 | } else if focus == nil || l.matchesName(focus) { |
| 36 | fm = true |
| 37 | focusOrIgnore[l.ID] = true |
| 38 | } |
| 39 | |
| 40 | if hide != nil && l.matchesName(hide) { |
| 41 | hm = true |
| 42 | l.Line = l.unmatchedLines(hide) |
| 43 | if len(l.Line) == 0 { |
| 44 | hidden[l.ID] = true |
| 45 | } |
| 46 | } |
| 47 | if show != nil { |
| 48 | l.Line = l.matchedLines(show) |
| 49 | if len(l.Line) == 0 { |
| 50 | hidden[l.ID] = true |
| 51 | } else { |
| 52 | hnm = true |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | s := make([]*Sample, 0, len(p.Sample)) |
| 58 | for _, sample := range p.Sample { |
| 59 | if focusedAndNotIgnored(sample.Location, focusOrIgnore) { |
| 60 | if len(hidden) > 0 { |
| 61 | var locs []*Location |
| 62 | for _, loc := range sample.Location { |
| 63 | if !hidden[loc.ID] { |
| 64 | locs = append(locs, loc) |
| 65 | } |
| 66 | } |
| 67 | if len(locs) == 0 { |
| 68 | // Remove sample with no locations (by not adding it to s). |
| 69 | continue |
| 70 | } |
| 71 | sample.Location = locs |
| 72 | } |
| 73 | s = append(s, sample) |
| 74 | } |
| 75 | } |
| 76 | p.Sample = s |
| 77 | |
| 78 | return |
| 79 | } |
| 80 | |
| 81 | // ShowFrom drops all stack frames above the highest matching frame and returns |