// Copyright 2014 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// Implements methods to filter samples from profiles.package profileimport// 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.func ( *Profile) (, , *regexp.Regexp) (, , bool) { := make(map[uint64]bool) := make(map[uint64]bool)for , := range .Location {if != nil && .matchesName() { = true [.ID] = false } elseif == nil || .matchesName() { = true [.ID] = true }if != nil && .matchesName() { = true .Line = .unmatchedLines()iflen(.Line) == 0 { [.ID] = true } } } := make([]*Sample, 0, len(.Sample))for , := range .Sample {iffocusedAndNotIgnored(.Location, ) {iflen() > 0 {var []*Locationfor , := range .Location {if ![.ID] { = append(, ) } }iflen() == 0 {// Remove sample with no locations (by not adding it to s).continue } .Location = } = append(, ) } } .Sample = return}// matchesName reports whether the function name or file in the// location matches the regular expression.func ( *Location) ( *regexp.Regexp) bool {for , := range .Line {if := .Function; != nil {if .MatchString(.Name) {returntrue }if .MatchString(.Filename) {returntrue } } }returnfalse}// unmatchedLines returns the lines in the location that do not match// the regular expression.func ( *Location) ( *regexp.Regexp) []Line {var []Linefor , := range .Line {if := .Function; != nil {if .MatchString(.Name) {continue }if .MatchString(.Filename) {continue } } = append(, ) }return}// focusedAndNotIgnored looks up a slice of ids against a map of// focused/ignored locations. The map only contains locations that are// explicitly focused or ignored. Returns whether there is at least// one focused location but no ignored locations.func ( []*Location, map[uint64]bool) bool {varboolfor , := range {if , := [.ID]; {if {// Found focused location. Must keep searching in case there // is an ignored one as well. = true } else {// Found ignored location. Can return false right away.returnfalse } } }return}// TagMatch selects tags for filteringtypeTagMatchfunc(key, val string, nval int64) bool// FilterSamplesByTag removes all samples from the profile, except// those that match focus and do not match the ignore regular// expression.func ( *Profile) (, TagMatch) (, bool) { := make([]*Sample, 0, len(.Sample))for , := range .Sample { , := focusedSample(, , ) = || = || if && ! { = append(, ) } } .Sample = return}// focusedTag checks a sample against focus and ignore regexps.// Returns whether the focus/ignore regexps match any tagsfunc ( *Sample, , TagMatch) (, bool) { = == nilfor , := range .Label {for , := range {if != nil && (, , 0) { = true }if ! && (, , 0) { = true } } }for , := range .NumLabel {for , := range {if != nil && (, "", ) { = true }if ! && (, "", ) { = true } } }return , }
The pages are generated with Goldsv0.4.9. (GOOS=linux GOARCH=amd64)