Debian Codegraph @

internal/driver/driver_focus.go

raw symbols SCIP
1 // Copyright 2014 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package driverscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/
16
17 import (
18 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
19 "regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/"
20 "slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/"
21 "strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/"
22 "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/"
23
24 "github.com/google/pprof/internal/measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/"
25 "github.com/google/pprof/internal/pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/"
26 "github.com/google/pprof/profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/"
27 )
28
29 var tagFilterRangeRxscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/tagFilterRangeRx. = regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.24.0 regexp/MustCompile().("([+-]?[[:digit:]]+)([[:alpha:]]+)?")
30
31 // applyFocus filters samples based on the focus/ignore options
32 func applyFocusscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/applyFocus().(prof *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, numLabelUnits map[string]string, cfg configscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#, ui pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#) error {
33 focus, err := compileRegexOptionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileRegexOption().("focus", cfg.Focusscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Focus., nil)
34 ignore, err := compileRegexOptionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileRegexOption().("ignore", cfg.Ignorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Ignore., err)
35 hide, err := compileRegexOptionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileRegexOption().("hide", cfg.Hidescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Hide., err)
36 show, err := compileRegexOptionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileRegexOption().("show", cfg.Showscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#Show., err)
37 showfrom, err := compileRegexOptionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileRegexOption().("show_from", cfg.ShowFromscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#ShowFrom., err)
38 tagfocus, err := compileTagFilterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileTagFilter().("tagfocus", cfg.TagFocusscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagFocus., numLabelUnits, ui, err)
39 tagignore, err := compileTagFilterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileTagFilter().("tagignore", cfg.TagIgnorescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagIgnore., numLabelUnits, ui, err)
40 prunefrom, err := compileRegexOptionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileRegexOption().("prune_from", cfg.PruneFromscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#PruneFrom., err)
41 if err != nil {
42 return err
43 }
44
45 fm, im, hm, hnm := prof.FilterSamplesByNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#FilterSamplesByName().(focus, ignore, hide, show)
46 warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(focus == nil || fm, "Focus", ui)
47 warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(ignore == nil || im, "Ignore", ui)
48 warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(hide == nil || hm, "Hide", ui)
49 warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(show == nil || hnm, "Show", ui)
50
51 sfm := prof.ShowFromscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#ShowFrom().(showfrom)
52 warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(showfrom == nil || sfm, "ShowFrom", ui)
53
54 tfm, tim := prof.FilterSamplesByTagscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#FilterSamplesByTag().(tagfocus, tagignore)
55 warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(tagfocus == nil || tfm, "TagFocus", ui)
56 warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(tagignore == nil || tim, "TagIgnore", ui)
57
58 tagshow, err := compileRegexOptionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileRegexOption().("tagshow", cfg.TagShowscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagShow., err)
59 taghide, err := compileRegexOptionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileRegexOption().("taghide", cfg.TagHidescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/config#TagHide., err)
60 tns, tnh := prof.FilterTagsByNamescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#FilterTagsByName().(tagshow, taghide)
61 warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(tagshow == nil || tns, "TagShow", ui)
62 warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(taghide == nil || tnh, "TagHide", ui)
63
64 if prunefrom != nil {
65 prof.PruneFromscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PruneFrom().(prunefrom)
66 }
67 return err
68 }
69
70 func compileRegexOptionscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileRegexOption().(name, value string, err error) (*regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.Regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#, error) {
71 if value == "" || err != nil {
72 return nil, err
73 }
74 rx, err := regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.Compilescip-go gomod github.com/golang/go/src go1.24.0 regexp/Compile().(value)
75 if err != nil {
76 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("parsing %s regexp: %v", name, err)
77 }
78 return rx, nil
79 }
80
81 func compileTagFilterscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/compileTagFilter().(name, value string, numLabelUnits map[string]string, ui pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#, err error) (func(*profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#) bool, error) {
82 if value == "" || err != nil {
83 return nil, err
84 }
85
86 tagValuePair := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.SplitNscip-go gomod github.com/golang/go/src go1.24.0 strings/SplitN().(value, "=", 2)
87 var wantKey string
88 if len(tagValuePair) == 2 {
89 wantKey = tagValuePair[0]
90 value = tagValuePair[1]
91 }
92
93 if numFilter := parseTagFilterRangescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/parseTagFilterRange().(value); numFilter != nil {
94 ui.PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(name, ":Interpreted '", value, "' as range, not regexp")
95 labelFilter := func(vals []int64, unit string) bool {
96 for _, val := range vals {
97 if numFilter(val, unit) {
98 return true
99 }
100 }
101 return false
102 }
103 numLabelUnit := func(key string) string {
104 return numLabelUnits[key]
105 }
106 if wantKey == "" {
107 return func(s *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#) bool {
108 for key, vals := range s.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel. {
109 if labelFilter(vals, numLabelUnit(key)) {
110 return true
111 }
112 }
113 return false
114 }, nil
115 }
116 return func(s *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#) bool {
117 if vals, ok := s.NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel.[wantKey]; ok {
118 return labelFilter(vals, numLabelUnit(wantKey))
119 }
120 return false
121 }, nil
122 }
123
124 var rfx []*regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.Regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#
125 for _, tagf := range stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.24.0 strings/Split().(value, ",") {
126 fx, err := regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/.Compilescip-go gomod github.com/golang/go/src go1.24.0 regexp/Compile().(tagf)
127 if err != nil {
128 return nil, fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("parsing %s regexp: %v", name, err)
129 }
130 rfx = append(rfx, fx)
131 }
132 if wantKey == "" {
133 return func(s *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#) bool {
134 matchedrx:
135 for _, rx := range rfx {
136 for key, vals := range s.Labelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Label. {
137 for _, val := range vals {
138 // TODO: Match against val, not key:val in future
139 if rx.MatchStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#MatchString().(key + ":" + val) {
140 continue matchedrx
141 }
142 }
143 }
144 return false
145 }
146 return true
147 }, nil
148 }
149 return func(s *profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#) bool {
150 if vals, ok := s.Labelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Label.[wantKey]; ok {
151 for _, rx := range rfx {
152 if slicesscip-go gomod github.com/golang/go/src go1.24.0 slices/.ContainsFuncscip-go gomod github.com/golang/go/src go1.24.0 slices/ContainsFunc().(vals, rx.MatchStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#MatchString().) {
153 return true
154 }
155 }
156 }
157 return false
158 }, nil
159 }
160
161 // parseTagFilterRange returns a function to checks if a value is
162 // contained on the range described by a string. It can recognize
163 // strings of the form:
164 // "32kb" -- matches values == 32kb
165 // ":64kb" -- matches values <= 64kb
166 // "4mb:" -- matches values >= 4mb
167 // "12kb:64mb" -- matches values between 12kb and 64mb (both included).
168 func parseTagFilterRangescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/parseTagFilterRange().(filter string) func(int64, string) bool {
169 ranges := tagFilterRangeRxscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/tagFilterRangeRx..FindAllStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindAllStringSubmatch().(filter, 2)
170 if len(ranges) == 0 {
171 return nil // No ranges were identified
172 }
173 v, err := strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.24.0 strconv/ParseInt().(ranges[0][1], 10, 64)
174 if err != nil {
175 panic(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("failed to parse int %s: %v", ranges[0][1], err))
176 }
177 scaledValue, unit := measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/.Scalescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/Scale().(v, ranges[0][2], ranges[0][2])
178 if len(ranges) == 1 {
179 switch match := ranges[0][0]; filter {
180 case match:
181 return func(v int64, u string) bool {
182 sv, su := measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/.Scalescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/Scale().(v, u, unit)
183 return su == unit && sv == scaledValue
184 }
185 case match + ":":
186 return func(v int64, u string) bool {
187 sv, su := measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/.Scalescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/Scale().(v, u, unit)
188 return su == unit && sv >= scaledValue
189 }
190 case ":" + match:
191 return func(v int64, u string) bool {
192 sv, su := measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/.Scalescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/Scale().(v, u, unit)
193 return su == unit && sv <= scaledValue
194 }
195 }
196 return nil
197 }
198 if filter != ranges[0][0]+":"+ranges[1][0] {
199 return nil
200 }
201 if v, err = strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.ParseIntscip-go gomod github.com/golang/go/src go1.24.0 strconv/ParseInt().(ranges[1][1], 10, 64); err != nil {
202 panic(fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Errorf().("failed to parse int %s: %v", ranges[1][1], err))
203 }
204 scaledValue2, unit2 := measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/.Scalescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/Scale().(v, ranges[1][2], unit)
205 if unit != unit2 {
206 return nil
207 }
208 return func(v int64, u string) bool {
209 sv, su := measurementscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/.Scalescip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/measurement`/Scale().(v, u, unit)
210 return su == unit && sv >= scaledValue && sv <= scaledValue2
211 }
212 }
213
214 func warnNoMatchesscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/driver`/warnNoMatches().(match bool, option string, ui pluginscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/.UIscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#) {
215 if !match {
216 ui.PrintErrscip-go gomod github.com/google/pprof . `github.com/google/pprof/internal/plugin`/UI#PrintErr.(option + " expression matched no samples")
217 }
218 }