| |
| |
| |
|
|
| |
|
|
| package profile |
|
|
| |
| type TagMatch func(key, val string, nval int64) bool |
|
|
| |
| |
| |
| func (p *Profile) FilterSamplesByTag(focus, ignore TagMatch) (fm, im bool) { |
| samples := make([]*Sample, 0, len(p.Sample)) |
| for _, s := range p.Sample { |
| focused, ignored := focusedSample(s, focus, ignore) |
| fm = fm || focused |
| im = im || ignored |
| if focused && !ignored { |
| samples = append(samples, s) |
| } |
| } |
| p.Sample = samples |
| return |
| } |
|
|
| |
| |
| func focusedSample(s *Sample, focus, ignore TagMatch) (fm, im bool) { |
| fm = focus == nil |
| for key, vals := range s.Label { |
| for _, val := range vals { |
| if ignore != nil && ignore(key, val, 0) { |
| im = true |
| } |
| if !fm && focus(key, val, 0) { |
| fm = true |
| } |
| } |
| } |
| for key, vals := range s.NumLabel { |
| for _, val := range vals { |
| if ignore != nil && ignore(key, "", val) { |
| im = true |
| } |
| if !fm && focus(key, "", val) { |
| fm = true |
| } |
| } |
| } |
| return fm, im |
| } |
|
|