| 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 | // This file implements parsers to convert legacy profiles into the |
| 16 | // profile.proto format. |
| 17 | |
| 18 | package profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ |
| 19 | |
| 20 | import ( |
| 21 | "bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/" |
| 22 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 23 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 24 | "ioscip-go gomod github.com/golang/go/src go1.24.0 io/" |
| 25 | "mathscip-go gomod github.com/golang/go/src go1.24.0 math/" |
| 26 | "regexpscip-go gomod github.com/golang/go/src go1.24.0 regexp/" |
| 27 | "strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/" |
| 28 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 29 | ) |
| 30 | |
| 31 | var ( |
| 32 | countStartREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/countStartRE. = 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().(`\A(\S+) profile: total \d+\z`) |
| 33 | countREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/countRE. = 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().(`\A(\d+) @(( 0x[0-9a-f]+)+)\z`) |
| 34 | |
| 35 | heapHeaderREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/heapHeaderRE. = 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().(`heap profile: *(\d+): *(\d+) *\[ *(\d+): *(\d+) *\] *@ *(heap[_a-z0-9]*)/?(\d*)`) |
| 36 | heapSampleREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/heapSampleRE. = 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().(`(-?\d+): *(-?\d+) *\[ *(\d+): *(\d+) *] @([ x0-9a-f]*)`) |
| 37 | |
| 38 | contentionSampleREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/contentionSampleRE. = 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().(`(\d+) *(\d+) @([ x0-9a-f]*)`) |
| 39 | |
| 40 | hexNumberREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/hexNumberRE. = 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().(`0x[0-9a-f]+`) |
| 41 | |
| 42 | growthHeaderREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/growthHeaderRE. = 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().(`heap profile: *(\d+): *(\d+) *\[ *(\d+): *(\d+) *\] @ growthz?`) |
| 43 | |
| 44 | fragmentationHeaderREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/fragmentationHeaderRE. = 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().(`heap profile: *(\d+): *(\d+) *\[ *(\d+): *(\d+) *\] @ fragmentationz?`) |
| 45 | |
| 46 | threadzStartREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/threadzStartRE. = 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().(`--- threadz \d+ ---`) |
| 47 | threadStartREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/threadStartRE. = 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().(`--- Thread ([[:xdigit:]]+) \(name: (.*)/(\d+)\) stack: ---`) |
| 48 | |
| 49 | // Regular expressions to parse process mappings. Support the format used by Linux /proc/.../maps and other tools. |
| 50 | // Recommended format: |
| 51 | // Start End object file name offset(optional) linker build id |
| 52 | // 0x40000-0x80000 /path/to/binary (@FF00) abc123456 |
| 53 | spaceDigitsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/spaceDigits. = `\s+[[:digit:]]+` |
| 54 | hexPairscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/hexPair. = `\s+[[:xdigit:]]+:[[:xdigit:]]+` |
| 55 | oSpacescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/oSpace. = `\s*` |
| 56 | // Capturing expressions. |
| 57 | cHexscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cHex. = `(?:0x)?([[:xdigit:]]+)` |
| 58 | cHexRangescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cHexRange. = `\s*` + cHexscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cHex. + `[\s-]?` + oSpacescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/oSpace. + cHexscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cHex. + `:?` |
| 59 | cSpaceStringscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cSpaceString. = `(?:\s+(\S+))?` |
| 60 | cSpaceHexscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cSpaceHex. = `(?:\s+([[:xdigit:]]+))?` |
| 61 | cSpaceAtOffsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cSpaceAtOffset. = `(?:\s+\(@([[:xdigit:]]+)\))?` |
| 62 | cPermscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cPerm. = `(?:\s+([-rwxp]+))?` |
| 63 | |
| 64 | procMapsREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/procMapsRE. = 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().(`^` + cHexRangescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cHexRange. + cPermscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cPerm. + cSpaceHexscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cSpaceHex. + hexPairscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/hexPair. + spaceDigitsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/spaceDigits. + cSpaceStringscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cSpaceString.) |
| 65 | briefMapsREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/briefMapsRE. = 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().(`^` + cHexRangescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cHexRange. + cPermscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cPerm. + cSpaceStringscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cSpaceString. + cSpaceAtOffsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cSpaceAtOffset. + cSpaceHexscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cSpaceHex.) |
| 66 | |
| 67 | // Regular expression to parse log data, of the form: |
| 68 | // ... file:line] msg... |
| 69 | logInfoREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/logInfoRE. = 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().(`^[^\[\]]+:[0-9]+]\s`) |
| 70 | ) |
| 71 | |
| 72 | func isSpaceOrCommentscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isSpaceOrComment().(line string) bool { |
| 73 | trimmed := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 strings/TrimSpace().(line) |
| 74 | return len(trimmed) == 0 || trimmed[0] == '#' |
| 75 | } |
| 76 | |
| 77 | // parseGoCount parses a Go count profile (e.g., threadcreate or |
| 78 | // goroutine) and returns a new Profile. |
| 79 | func parseGoCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseGoCount().(b []byte) (*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, error) { |
| 80 | s := bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/NewScanner().(bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/NewBuffer().(b)) |
| 81 | // Skip comments at the beginning of the file. |
| 82 | for s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() && isSpaceOrCommentscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isSpaceOrComment().(s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().()) { |
| 83 | } |
| 84 | if err := s.Errscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Err().(); err != nil { |
| 85 | return nil, err |
| 86 | } |
| 87 | m := countStartREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/countStartRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().()) |
| 88 | if m == nil { |
| 89 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 90 | } |
| 91 | profileType := m[1] |
| 92 | p := &Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#{ |
| 93 | PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType.: &ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: profileType, Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "count"}, |
| 94 | Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period.: 1, |
| 95 | SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.: []*ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{{Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: profileType, Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "count"}}, |
| 96 | } |
| 97 | locations := make(map[uint64]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#) |
| 98 | for s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 99 | line := s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().() |
| 100 | if isSpaceOrCommentscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isSpaceOrComment().(line) { |
| 101 | continue |
| 102 | } |
| 103 | if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(line, "---") { |
| 104 | break |
| 105 | } |
| 106 | m := countREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/countRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(line) |
| 107 | if m == nil { |
| 108 | return nil, errMalformedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errMalformed. |
| 109 | } |
| 110 | n, 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().(m[1], 0, 64) |
| 111 | if err != nil { |
| 112 | return nil, errMalformedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errMalformed. |
| 113 | } |
| 114 | fields := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Fieldsscip-go gomod github.com/golang/go/src go1.24.0 strings/Fields().(m[2]) |
| 115 | locs := make([]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#, 0, len(fields)) |
| 116 | for _, stk := range fields { |
| 117 | addr, err := strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.ParseUintscip-go gomod github.com/golang/go/src go1.24.0 strconv/ParseUint().(stk, 0, 64) |
| 118 | if err != nil { |
| 119 | return nil, errMalformedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errMalformed. |
| 120 | } |
| 121 | // Adjust all frames by -1 to land on top of the call instruction. |
| 122 | addr-- |
| 123 | loc := locations[addr] |
| 124 | if loc == nil { |
| 125 | loc = &Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{ |
| 126 | Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.: addr, |
| 127 | } |
| 128 | locations[addr] = loc |
| 129 | p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. = append(p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location., loc) |
| 130 | } |
| 131 | locs = append(locs, loc) |
| 132 | } |
| 133 | p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. = append(p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample., &Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#{ |
| 134 | Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.: locs, |
| 135 | Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.: []int64{n}, |
| 136 | }) |
| 137 | } |
| 138 | if err := s.Errscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Err().(); err != nil { |
| 139 | return nil, err |
| 140 | } |
| 141 | |
| 142 | if err := parseAdditionalSectionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseAdditionalSections().(s, p); err != nil { |
| 143 | return nil, err |
| 144 | } |
| 145 | return p, nil |
| 146 | } |
| 147 | |
| 148 | // remapLocationIDs ensures there is a location for each address |
| 149 | // referenced by a sample, and remaps the samples to point to the new |
| 150 | // location ids. |
| 151 | func (p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) remapLocationIDsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#remapLocationIDs().() { |
| 152 | seen := make(map[*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#]bool, len(p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location.)) |
| 153 | var locs []*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# |
| 154 | |
| 155 | for _, s := range p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. { |
| 156 | for _, l := range s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location. { |
| 157 | if seen[l] { |
| 158 | continue |
| 159 | } |
| 160 | l.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#ID. = uint64(len(locs) + 1) |
| 161 | locs = append(locs, l) |
| 162 | seen[l] = true |
| 163 | } |
| 164 | } |
| 165 | p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. = locs |
| 166 | } |
| 167 | |
| 168 | func (p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) remapFunctionIDsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#remapFunctionIDs().() { |
| 169 | seen := make(map[*Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#]bool, len(p.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function.)) |
| 170 | var fns []*Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function# |
| 171 | |
| 172 | for _, l := range p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. { |
| 173 | for _, ln := range l.Linescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Line. { |
| 174 | fn := ln.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Line#Function. |
| 175 | if fn == nil || seen[fn] { |
| 176 | continue |
| 177 | } |
| 178 | fn.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Function#ID. = uint64(len(fns) + 1) |
| 179 | fns = append(fns, fn) |
| 180 | seen[fn] = true |
| 181 | } |
| 182 | } |
| 183 | p.Functionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Function. = fns |
| 184 | } |
| 185 | |
| 186 | // remapMappingIDs matches location addresses with existing mappings |
| 187 | // and updates them appropriately. This is O(N*M), if this ever shows |
| 188 | // up as a bottleneck, evaluate sorting the mappings and doing a |
| 189 | // binary search, which would make it O(N*log(M)). |
| 190 | func (p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) remapMappingIDsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#remapMappingIDs().() { |
| 191 | // Some profile handlers will incorrectly set regions for the main |
| 192 | // executable if its section is remapped. Fix them through heuristics. |
| 193 | |
| 194 | if len(p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.) > 0 { |
| 195 | // Remove the initial mapping if named '/anon_hugepage' and has a |
| 196 | // consecutive adjacent mapping. |
| 197 | if m := p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.[0]; stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(m.Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File., "/anon_hugepage") { |
| 198 | if len(p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.) > 1 && m.Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit. == p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.[1].Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start. { |
| 199 | p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping. = p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.[1:] |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // Subtract the offset from the start of the main mapping if it |
| 205 | // ends up at a recognizable start address. |
| 206 | if len(p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.) > 0 { |
| 207 | const expectedStart = 0x400000 |
| 208 | if m := p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping.[0]; m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.-m.Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset. == expectedStart { |
| 209 | m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start. = expectedStart |
| 210 | m.Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset. = 0 |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | // Associate each location with an address to the corresponding |
| 215 | // mapping. Create fake mapping if a suitable one isn't found. |
| 216 | var fake *Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping# |
| 217 | nextLocation: |
| 218 | for _, l := range p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. { |
| 219 | a := l.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address. |
| 220 | if l.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping. != nil || a == 0 { |
| 221 | continue |
| 222 | } |
| 223 | for _, m := range p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping. { |
| 224 | if m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start. <= a && a < m.Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit. { |
| 225 | l.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping. = m |
| 226 | continue nextLocation |
| 227 | } |
| 228 | } |
| 229 | // Work around legacy handlers failing to encode the first |
| 230 | // part of mappings split into adjacent ranges. |
| 231 | for _, m := range p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping. { |
| 232 | if m.Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset. != 0 && m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.-m.Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset. <= a && a < m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start. { |
| 233 | m.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start. -= m.Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset. |
| 234 | m.Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset. = 0 |
| 235 | l.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping. = m |
| 236 | continue nextLocation |
| 237 | } |
| 238 | } |
| 239 | // If there is still no mapping, create a fake one. |
| 240 | // This is important for the Go legacy handler, which produced |
| 241 | // no mappings. |
| 242 | if fake == nil { |
| 243 | fake = &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 244 | IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#ID.: 1, |
| 245 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: ^uint64(0), |
| 246 | } |
| 247 | p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping. = append(p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping., fake) |
| 248 | } |
| 249 | l.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Mapping. = fake |
| 250 | } |
| 251 | |
| 252 | // Reset all mapping IDs. |
| 253 | for i, m := range p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping. { |
| 254 | m.IDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#ID. = uint64(i + 1) |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | var cpuIntsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cpuInts. = []func([]byte) (uint64, []byte){ |
| 259 | get32lscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/get32l()., |
| 260 | get32bscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/get32b()., |
| 261 | get64lscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/get64l()., |
| 262 | get64bscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/get64b()., |
| 263 | } |
| 264 | |
| 265 | func get32lscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/get32l().(b []byte) (uint64, []byte) { |
| 266 | if len(b) < 4 { |
| 267 | return 0, nil |
| 268 | } |
| 269 | return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24, b[4:] |
| 270 | } |
| 271 | |
| 272 | func get32bscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/get32b().(b []byte) (uint64, []byte) { |
| 273 | if len(b) < 4 { |
| 274 | return 0, nil |
| 275 | } |
| 276 | return uint64(b[3]) | uint64(b[2])<<8 | uint64(b[1])<<16 | uint64(b[0])<<24, b[4:] |
| 277 | } |
| 278 | |
| 279 | func get64lscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/get64l().(b []byte) (uint64, []byte) { |
| 280 | if len(b) < 8 { |
| 281 | return 0, nil |
| 282 | } |
| 283 | return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56, b[8:] |
| 284 | } |
| 285 | |
| 286 | func get64bscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/get64b().(b []byte) (uint64, []byte) { |
| 287 | if len(b) < 8 { |
| 288 | return 0, nil |
| 289 | } |
| 290 | return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 | uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56, b[8:] |
| 291 | } |
| 292 | |
| 293 | // parseCPU parses a profilez legacy profile and returns a newly |
| 294 | // populated Profile. |
| 295 | // |
| 296 | // The general format for profilez samples is a sequence of words in |
| 297 | // binary format. The first words are a header with the following data: |
| 298 | // |
| 299 | // 1st word -- 0 |
| 300 | // 2nd word -- 3 |
| 301 | // 3rd word -- 0 if a c++ application, 1 if a java application. |
| 302 | // 4th word -- Sampling period (in microseconds). |
| 303 | // 5th word -- Padding. |
| 304 | func parseCPUscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseCPU().(b []byte) (*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, error) { |
| 305 | var parse func([]byte) (uint64, []byte) |
| 306 | var n1, n2, n3, n4, n5 uint64 |
| 307 | for _, parse = range cpuIntsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cpuInts. { |
| 308 | var tmp []byte |
| 309 | n1, tmp = parse(b) |
| 310 | n2, tmp = parse(tmp) |
| 311 | n3, tmp = parse(tmp) |
| 312 | n4, tmp = parse(tmp) |
| 313 | n5, tmp = parse(tmp) |
| 314 | |
| 315 | if tmp != nil && n1 == 0 && n2 == 3 && n3 == 0 && n4 > 0 && n5 == 0 { |
| 316 | b = tmp |
| 317 | return cpuProfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cpuProfile().(b, int64(n4), parse) |
| 318 | } |
| 319 | if tmp != nil && n1 == 0 && n2 == 3 && n3 == 1 && n4 > 0 && n5 == 0 { |
| 320 | b = tmp |
| 321 | return javaCPUProfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/javaCPUProfile().(b, int64(n4), parse) |
| 322 | } |
| 323 | } |
| 324 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 325 | } |
| 326 | |
| 327 | // cpuProfile returns a new Profile from C++ profilez data. |
| 328 | // b is the profile bytes after the header, period is the profiling |
| 329 | // period, and parse is a function to parse 8-byte chunks from the |
| 330 | // profile in its native endianness. |
| 331 | func cpuProfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cpuProfile().(b []byte, period int64, parse func(b []byte) (uint64, []byte)) (*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, error) { |
| 332 | p := &Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#{ |
| 333 | Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period.: period * 1000, |
| 334 | PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType.: &ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "cpu", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "nanoseconds"}, |
| 335 | SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.: []*ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{ |
| 336 | {Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "samples", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "count"}, |
| 337 | {Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "cpu", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "nanoseconds"}, |
| 338 | }, |
| 339 | } |
| 340 | var err error |
| 341 | if b, _, err = parseCPUSamplesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseCPUSamples().(b, parse, true, p); err != nil { |
| 342 | return nil, err |
| 343 | } |
| 344 | |
| 345 | // If *most* samples have the same second-to-the-bottom frame, it |
| 346 | // strongly suggests that it is an uninteresting artifact of |
| 347 | // measurement -- a stack frame pushed by the signal handler. The |
| 348 | // bottom frame is always correct as it is picked up from the signal |
| 349 | // structure, not the stack. Check if this is the case and if so, |
| 350 | // remove. |
| 351 | |
| 352 | // Remove up to two frames. |
| 353 | maxiter := 2 |
| 354 | // Allow one different sample for this many samples with the same |
| 355 | // second-to-last frame. |
| 356 | similarSamples := 32 |
| 357 | margin := len(p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample.) / similarSamples |
| 358 | |
| 359 | for iter := 0; iter < maxiter; iter++ { |
| 360 | addr1 := make(map[uint64]int) |
| 361 | for _, s := range p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. { |
| 362 | if len(s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.) > 1 { |
| 363 | a := s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[1].Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address. |
| 364 | addr1[a] = addr1[a] + 1 |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | for id1, count := range addr1 { |
| 369 | if count >= len(p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample.)-margin { |
| 370 | // Found uninteresting frame, strip it out from all samples |
| 371 | for _, s := range p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. { |
| 372 | if len(s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.) > 1 && s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[1].Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address. == id1 { |
| 373 | s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location. = append(s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[:1], s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[2:]...) |
| 374 | } |
| 375 | } |
| 376 | break |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | if err := p.ParseMemoryMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#ParseMemoryMap().(bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/NewBuffer().(b)); err != nil { |
| 382 | return nil, err |
| 383 | } |
| 384 | |
| 385 | cleanupDuplicateLocationsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cleanupDuplicateLocations().(p) |
| 386 | return p, nil |
| 387 | } |
| 388 | |
| 389 | func cleanupDuplicateLocationsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cleanupDuplicateLocations().(p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) { |
| 390 | // The profile handler may duplicate the leaf frame, because it gets |
| 391 | // its address both from stack unwinding and from the signal |
| 392 | // context. Detect this and delete the duplicate, which has been |
| 393 | // adjusted by -1. The leaf address should not be adjusted as it is |
| 394 | // not a call. |
| 395 | for _, s := range p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. { |
| 396 | if len(s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.) > 1 && s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[0].Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address. == s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[1].Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.+1 { |
| 397 | s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location. = append(s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[:1], s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.[2:]...) |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | // parseCPUSamples parses a collection of profilez samples from a |
| 403 | // profile. |
| 404 | // |
| 405 | // profilez samples are a repeated sequence of stack frames of the |
| 406 | // form: |
| 407 | // |
| 408 | // 1st word -- The number of times this stack was encountered. |
| 409 | // 2nd word -- The size of the stack (StackSize). |
| 410 | // 3rd word -- The first address on the stack. |
| 411 | // ... |
| 412 | // StackSize + 2 -- The last address on the stack |
| 413 | // |
| 414 | // The last stack trace is of the form: |
| 415 | // |
| 416 | // 1st word -- 0 |
| 417 | // 2nd word -- 1 |
| 418 | // 3rd word -- 0 |
| 419 | // |
| 420 | // Addresses from stack traces may point to the next instruction after |
| 421 | // each call. Optionally adjust by -1 to land somewhere on the actual |
| 422 | // call (except for the leaf, which is not a call). |
| 423 | func parseCPUSamplesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseCPUSamples().(b []byte, parse func(b []byte) (uint64, []byte), adjust bool, p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) ([]byte, map[uint64]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#, error) { |
| 424 | locs := make(map[uint64]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#) |
| 425 | for len(b) > 0 { |
| 426 | var count, nstk uint64 |
| 427 | count, b = parse(b) |
| 428 | nstk, b = parse(b) |
| 429 | if b == nil || nstk > uint64(len(b)/4) { |
| 430 | return nil, nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 431 | } |
| 432 | var sloc []*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# |
| 433 | addrs := make([]uint64, nstk) |
| 434 | for i := 0; i < int(nstk); i++ { |
| 435 | addrs[i], b = parse(b) |
| 436 | } |
| 437 | |
| 438 | if count == 0 && nstk == 1 && addrs[0] == 0 { |
| 439 | // End of data marker |
| 440 | break |
| 441 | } |
| 442 | for i, addr := range addrs { |
| 443 | if adjust && i > 0 { |
| 444 | addr-- |
| 445 | } |
| 446 | loc := locs[addr] |
| 447 | if loc == nil { |
| 448 | loc = &Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{ |
| 449 | Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.: addr, |
| 450 | } |
| 451 | locs[addr] = loc |
| 452 | p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. = append(p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location., loc) |
| 453 | } |
| 454 | sloc = append(sloc, loc) |
| 455 | } |
| 456 | p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. = append(p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample., |
| 457 | &Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#{ |
| 458 | Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.: []int64{int64(count), int64(count) * p.Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period.}, |
| 459 | Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.: sloc, |
| 460 | }) |
| 461 | } |
| 462 | // Reached the end without finding the EOD marker. |
| 463 | return b, locs, nil |
| 464 | } |
| 465 | |
| 466 | // parseHeap parses a heapz legacy or a growthz profile and |
| 467 | // returns a newly populated Profile. |
| 468 | func parseHeapscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseHeap().(b []byte) (p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, err error) { |
| 469 | s := bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/NewScanner().(bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/NewBuffer().(b)) |
| 470 | if !s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 471 | if err := s.Errscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Err().(); err != nil { |
| 472 | return nil, err |
| 473 | } |
| 474 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 475 | } |
| 476 | p = &Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#{} |
| 477 | |
| 478 | sampling := "" |
| 479 | hasAlloc := false |
| 480 | |
| 481 | line := s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().() |
| 482 | p.PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType. = &ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "space", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "bytes"} |
| 483 | if header := heapHeaderREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/heapHeaderRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(line); header != nil { |
| 484 | sampling, p.Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period., hasAlloc, err = parseHeapHeaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseHeapHeader().(line) |
| 485 | if err != nil { |
| 486 | return nil, err |
| 487 | } |
| 488 | } else if header = growthHeaderREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/growthHeaderRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(line); header != nil { |
| 489 | p.Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period. = 1 |
| 490 | } else if header = fragmentationHeaderREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/fragmentationHeaderRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(line); header != nil { |
| 491 | p.Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period. = 1 |
| 492 | } else { |
| 493 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 494 | } |
| 495 | |
| 496 | if hasAlloc { |
| 497 | // Put alloc before inuse so that default pprof selection |
| 498 | // will prefer inuse_space. |
| 499 | p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType. = []*ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{ |
| 500 | {Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "alloc_objects", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "count"}, |
| 501 | {Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "alloc_space", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "bytes"}, |
| 502 | {Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "inuse_objects", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "count"}, |
| 503 | {Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "inuse_space", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "bytes"}, |
| 504 | } |
| 505 | } else { |
| 506 | p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType. = []*ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{ |
| 507 | {Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "objects", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "count"}, |
| 508 | {Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "space", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "bytes"}, |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | locs := make(map[uint64]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#) |
| 513 | for s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 514 | line := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 strings/TrimSpace().(s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().()) |
| 515 | |
| 516 | if isSpaceOrCommentscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isSpaceOrComment().(line) { |
| 517 | continue |
| 518 | } |
| 519 | |
| 520 | if isMemoryMapSentinelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isMemoryMapSentinel().(line) { |
| 521 | break |
| 522 | } |
| 523 | |
| 524 | value, blocksize, addrs, err := parseHeapSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseHeapSample().(line, p.Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period., sampling, hasAlloc) |
| 525 | if err != nil { |
| 526 | return nil, err |
| 527 | } |
| 528 | |
| 529 | var sloc []*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# |
| 530 | for _, addr := range addrs { |
| 531 | // Addresses from stack traces point to the next instruction after |
| 532 | // each call. Adjust by -1 to land somewhere on the actual call. |
| 533 | addr-- |
| 534 | loc := locs[addr] |
| 535 | if locs[addr] == nil { |
| 536 | loc = &Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{ |
| 537 | Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.: addr, |
| 538 | } |
| 539 | p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. = append(p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location., loc) |
| 540 | locs[addr] = loc |
| 541 | } |
| 542 | sloc = append(sloc, loc) |
| 543 | } |
| 544 | |
| 545 | p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. = append(p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample., &Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#{ |
| 546 | Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.: value, |
| 547 | Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.: sloc, |
| 548 | NumLabelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#NumLabel.: map[string][]int64{"bytes": {blocksize}}, |
| 549 | }) |
| 550 | } |
| 551 | if err := s.Errscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Err().(); err != nil { |
| 552 | return nil, err |
| 553 | } |
| 554 | if err := parseAdditionalSectionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseAdditionalSections().(s, p); err != nil { |
| 555 | return nil, err |
| 556 | } |
| 557 | return p, nil |
| 558 | } |
| 559 | |
| 560 | func parseHeapHeaderscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseHeapHeader().(line string) (sampling string, period int64, hasAlloc bool, err error) { |
| 561 | header := heapHeaderREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/heapHeaderRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(line) |
| 562 | if header == nil { |
| 563 | return "", 0, false, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 564 | } |
| 565 | |
| 566 | if len(header[6]) > 0 { |
| 567 | if period, 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().(header[6], 10, 64); err != nil { |
| 568 | return "", 0, false, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | if (header[3] != header[1] && header[3] != "0") || (header[4] != header[2] && header[4] != "0") { |
| 573 | hasAlloc = true |
| 574 | } |
| 575 | |
| 576 | switch header[5] { |
| 577 | case "heapz_v2", "heap_v2": |
| 578 | return "v2", period, hasAlloc, nil |
| 579 | case "heapprofile": |
| 580 | return "", 1, hasAlloc, nil |
| 581 | case "heap": |
| 582 | return "v2", period / 2, hasAlloc, nil |
| 583 | default: |
| 584 | return "", 0, false, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | // parseHeapSample parses a single row from a heap profile into a new Sample. |
| 589 | func parseHeapSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseHeapSample().(line string, rate int64, sampling string, includeAlloc bool) (value []int64, blocksize int64, addrs []uint64, err error) { |
| 590 | sampleData := heapSampleREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/heapSampleRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(line) |
| 591 | if len(sampleData) != 6 { |
| 592 | return nil, 0, 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().("unexpected number of sample values: got %d, want 6", len(sampleData)) |
| 593 | } |
| 594 | |
| 595 | // This is a local-scoped helper function to avoid needing to pass |
| 596 | // around rate, sampling and many return parameters. |
| 597 | addValues := func(countString, sizeString string, label string) error { |
| 598 | count, 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().(countString, 10, 64) |
| 599 | if err != nil { |
| 600 | return 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().("malformed sample: %s: %v", line, err) |
| 601 | } |
| 602 | size, 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().(sizeString, 10, 64) |
| 603 | if err != nil { |
| 604 | return 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().("malformed sample: %s: %v", line, err) |
| 605 | } |
| 606 | if count == 0 && size != 0 { |
| 607 | return 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().("%s count was 0 but %s bytes was %d", label, label, size) |
| 608 | } |
| 609 | if count != 0 { |
| 610 | blocksize = size / count |
| 611 | if sampling == "v2" { |
| 612 | count, size = scaleHeapSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/scaleHeapSample().(count, size, rate) |
| 613 | } |
| 614 | } |
| 615 | value = append(value, count, size) |
| 616 | return nil |
| 617 | } |
| 618 | |
| 619 | if includeAlloc { |
| 620 | if err := addValues(sampleData[3], sampleData[4], "allocation"); err != nil { |
| 621 | return nil, 0, nil, err |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | if err := addValues(sampleData[1], sampleData[2], "inuse"); err != nil { |
| 626 | return nil, 0, nil, err |
| 627 | } |
| 628 | |
| 629 | addrs, err = parseHexAddressesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseHexAddresses().(sampleData[5]) |
| 630 | if err != nil { |
| 631 | return nil, 0, 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().("malformed sample: %s: %v", line, err) |
| 632 | } |
| 633 | |
| 634 | return value, blocksize, addrs, nil |
| 635 | } |
| 636 | |
| 637 | // parseHexAddresses extracts hex numbers from a string, attempts to convert |
| 638 | // each to an unsigned 64-bit number and returns the resulting numbers as a |
| 639 | // slice, or an error if the string contains hex numbers which are too large to |
| 640 | // handle (which means a malformed profile). |
| 641 | func parseHexAddressesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseHexAddresses().(s string) ([]uint64, error) { |
| 642 | hexStrings := hexNumberREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/hexNumberRE..FindAllStringscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindAllString().(s, -1) |
| 643 | var addrs []uint64 |
| 644 | for _, s := range hexStrings { |
| 645 | if addr, err := strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.ParseUintscip-go gomod github.com/golang/go/src go1.24.0 strconv/ParseUint().(s, 0, 64); err == nil { |
| 646 | addrs = append(addrs, addr) |
| 647 | } else { |
| 648 | 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().("failed to parse as hex 64-bit number: %s", s) |
| 649 | } |
| 650 | } |
| 651 | return addrs, nil |
| 652 | } |
| 653 | |
| 654 | // scaleHeapSample adjusts the data from a heapz Sample to |
| 655 | // account for its probability of appearing in the collected |
| 656 | // data. heapz profiles are a sampling of the memory allocations |
| 657 | // requests in a program. We estimate the unsampled value by dividing |
| 658 | // each collected sample by its probability of appearing in the |
| 659 | // profile. heapz v2 profiles rely on a poisson process to determine |
| 660 | // which samples to collect, based on the desired average collection |
| 661 | // rate R. The probability of a sample of size S to appear in that |
| 662 | // profile is 1-exp(-S/R). |
| 663 | func scaleHeapSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/scaleHeapSample().(count, size, rate int64) (int64, int64) { |
| 664 | if count == 0 || size == 0 { |
| 665 | return 0, 0 |
| 666 | } |
| 667 | |
| 668 | if rate <= 1 { |
| 669 | // if rate==1 all samples were collected so no adjustment is needed. |
| 670 | // if rate<1 treat as unknown and skip scaling. |
| 671 | return count, size |
| 672 | } |
| 673 | |
| 674 | avgSize := float64(size) / float64(count) |
| 675 | scale := 1 / (1 - mathscip-go gomod github.com/golang/go/src go1.24.0 math/.Expscip-go gomod github.com/golang/go/src go1.24.0 math/Exp().(-avgSize/float64(rate))) |
| 676 | |
| 677 | return int64(float64(count) * scale), int64(float64(size) * scale) |
| 678 | } |
| 679 | |
| 680 | // parseContention parses a mutex or contention profile. There are 2 cases: |
| 681 | // "--- contentionz " for legacy C++ profiles (and backwards compatibility) |
| 682 | // "--- mutex:" or "--- contention:" for profiles generated by the Go runtime. |
| 683 | func parseContentionscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseContention().(b []byte) (*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, error) { |
| 684 | s := bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/NewScanner().(bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/NewBuffer().(b)) |
| 685 | if !s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 686 | if err := s.Errscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Err().(); err != nil { |
| 687 | return nil, err |
| 688 | } |
| 689 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 690 | } |
| 691 | |
| 692 | switch l := s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().(); { |
| 693 | case stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(l, "--- contentionz "): |
| 694 | case stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(l, "--- mutex:"): |
| 695 | case stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(l, "--- contention:"): |
| 696 | default: |
| 697 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 698 | } |
| 699 | |
| 700 | p := &Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#{ |
| 701 | PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType.: &ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "contentions", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "count"}, |
| 702 | Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period.: 1, |
| 703 | SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.: []*ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{ |
| 704 | {Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "contentions", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "count"}, |
| 705 | {Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "delay", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "nanoseconds"}, |
| 706 | }, |
| 707 | } |
| 708 | |
| 709 | var cpuHz int64 |
| 710 | // Parse text of the form "attribute = value" before the samples. |
| 711 | const delimiter = "=" |
| 712 | for s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 713 | line := s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().() |
| 714 | if line = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 strings/TrimSpace().(line); isSpaceOrCommentscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isSpaceOrComment().(line) { |
| 715 | continue |
| 716 | } |
| 717 | if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(line, "---") { |
| 718 | break |
| 719 | } |
| 720 | attr := 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().(line, delimiter, 2) |
| 721 | if len(attr) != 2 { |
| 722 | break |
| 723 | } |
| 724 | key, val := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 strings/TrimSpace().(attr[0]), stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 strings/TrimSpace().(attr[1]) |
| 725 | var err error |
| 726 | switch key { |
| 727 | case "cycles/second": |
| 728 | if cpuHz, 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().(val, 0, 64); err != nil { |
| 729 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 730 | } |
| 731 | case "sampling period": |
| 732 | if p.Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period., 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().(val, 0, 64); err != nil { |
| 733 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 734 | } |
| 735 | case "ms since reset": |
| 736 | ms, 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().(val, 0, 64) |
| 737 | if err != nil { |
| 738 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 739 | } |
| 740 | p.DurationNanosscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DurationNanos. = ms * 1000 * 1000 |
| 741 | case "format": |
| 742 | // CPP contentionz profiles don't have format. |
| 743 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 744 | case "resolution": |
| 745 | // CPP contentionz profiles don't have resolution. |
| 746 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 747 | case "discarded samples": |
| 748 | default: |
| 749 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 750 | } |
| 751 | } |
| 752 | if err := s.Errscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Err().(); err != nil { |
| 753 | return nil, err |
| 754 | } |
| 755 | |
| 756 | locs := make(map[uint64]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#) |
| 757 | for { |
| 758 | line := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 strings/TrimSpace().(s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().()) |
| 759 | if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(line, "---") { |
| 760 | break |
| 761 | } |
| 762 | if !isSpaceOrCommentscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isSpaceOrComment().(line) { |
| 763 | value, addrs, err := parseContentionSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseContentionSample().(line, p.Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period., cpuHz) |
| 764 | if err != nil { |
| 765 | return nil, err |
| 766 | } |
| 767 | var sloc []*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# |
| 768 | for _, addr := range addrs { |
| 769 | // Addresses from stack traces point to the next instruction after |
| 770 | // each call. Adjust by -1 to land somewhere on the actual call. |
| 771 | addr-- |
| 772 | loc := locs[addr] |
| 773 | if locs[addr] == nil { |
| 774 | loc = &Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{ |
| 775 | Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.: addr, |
| 776 | } |
| 777 | p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. = append(p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location., loc) |
| 778 | locs[addr] = loc |
| 779 | } |
| 780 | sloc = append(sloc, loc) |
| 781 | } |
| 782 | p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. = append(p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample., &Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#{ |
| 783 | Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.: value, |
| 784 | Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.: sloc, |
| 785 | }) |
| 786 | } |
| 787 | if !s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 788 | break |
| 789 | } |
| 790 | } |
| 791 | if err := s.Errscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Err().(); err != nil { |
| 792 | return nil, err |
| 793 | } |
| 794 | |
| 795 | if err := parseAdditionalSectionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseAdditionalSections().(s, p); err != nil { |
| 796 | return nil, err |
| 797 | } |
| 798 | |
| 799 | return p, nil |
| 800 | } |
| 801 | |
| 802 | // parseContentionSample parses a single row from a contention profile |
| 803 | // into a new Sample. |
| 804 | func parseContentionSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseContentionSample().(line string, period, cpuHz int64) (value []int64, addrs []uint64, err error) { |
| 805 | sampleData := contentionSampleREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/contentionSampleRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(line) |
| 806 | if sampleData == nil { |
| 807 | return nil, nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 808 | } |
| 809 | |
| 810 | v1, 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().(sampleData[1], 10, 64) |
| 811 | if err != nil { |
| 812 | return nil, 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().("malformed sample: %s: %v", line, err) |
| 813 | } |
| 814 | v2, 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().(sampleData[2], 10, 64) |
| 815 | if err != nil { |
| 816 | return nil, 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().("malformed sample: %s: %v", line, err) |
| 817 | } |
| 818 | |
| 819 | // Unsample values if period and cpuHz are available. |
| 820 | // - Delays are scaled to cycles and then to nanoseconds. |
| 821 | // - Contentions are scaled to cycles. |
| 822 | if period > 0 { |
| 823 | if cpuHz > 0 { |
| 824 | cpuGHz := float64(cpuHz) / 1e9 |
| 825 | v1 = int64(float64(v1) * float64(period) / cpuGHz) |
| 826 | } |
| 827 | v2 = v2 * period |
| 828 | } |
| 829 | |
| 830 | value = []int64{v2, v1} |
| 831 | addrs, err = parseHexAddressesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseHexAddresses().(sampleData[3]) |
| 832 | if err != nil { |
| 833 | return nil, 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().("malformed sample: %s: %v", line, err) |
| 834 | } |
| 835 | |
| 836 | return value, addrs, nil |
| 837 | } |
| 838 | |
| 839 | // parseThread parses a Threadz profile and returns a new Profile. |
| 840 | func parseThreadscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseThread().(b []byte) (*Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, error) { |
| 841 | s := bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/NewScanner().(bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.24.0 bytes/NewBuffer().(b)) |
| 842 | // Skip past comments and empty lines seeking a real header. |
| 843 | for s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() && isSpaceOrCommentscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isSpaceOrComment().(s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().()) { |
| 844 | } |
| 845 | |
| 846 | line := s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().() |
| 847 | if m := threadzStartREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/threadzStartRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(line); m != nil { |
| 848 | // Advance over initial comments until first stack trace. |
| 849 | for s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 850 | if line = s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().(); isMemoryMapSentinelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isMemoryMapSentinel().(line) || stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(line, "-") { |
| 851 | break |
| 852 | } |
| 853 | } |
| 854 | } else if t := threadStartREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/threadStartRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(line); len(t) != 4 { |
| 855 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 856 | } |
| 857 | |
| 858 | p := &Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#{ |
| 859 | SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.: []*ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{{Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "thread", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "count"}}, |
| 860 | PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType.: &ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#{Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.: "thread", Unitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Unit.: "count"}, |
| 861 | Periodscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Period.: 1, |
| 862 | } |
| 863 | |
| 864 | locs := make(map[uint64]*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#) |
| 865 | // Recognize each thread and populate profile samples. |
| 866 | for !isMemoryMapSentinelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isMemoryMapSentinel().(line) { |
| 867 | if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(line, "---- no stack trace for") { |
| 868 | break |
| 869 | } |
| 870 | if t := threadStartREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/threadStartRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(line); len(t) != 4 { |
| 871 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 872 | } |
| 873 | |
| 874 | var addrs []uint64 |
| 875 | var err error |
| 876 | line, addrs, err = parseThreadSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseThreadSample().(s) |
| 877 | if err != nil { |
| 878 | return nil, err |
| 879 | } |
| 880 | if len(addrs) == 0 { |
| 881 | // We got a --same as previous threads--. Bump counters. |
| 882 | if len(p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample.) > 0 { |
| 883 | s := p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample.[len(p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample.)-1] |
| 884 | s.Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.[0]++ |
| 885 | } |
| 886 | continue |
| 887 | } |
| 888 | |
| 889 | var sloc []*Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location# |
| 890 | for i, addr := range addrs { |
| 891 | // Addresses from stack traces point to the next instruction after |
| 892 | // each call. Adjust by -1 to land somewhere on the actual call |
| 893 | // (except for the leaf, which is not a call). |
| 894 | if i > 0 { |
| 895 | addr-- |
| 896 | } |
| 897 | loc := locs[addr] |
| 898 | if locs[addr] == nil { |
| 899 | loc = &Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#{ |
| 900 | Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.: addr, |
| 901 | } |
| 902 | p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location. = append(p.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Location., loc) |
| 903 | locs[addr] = loc |
| 904 | } |
| 905 | sloc = append(sloc, loc) |
| 906 | } |
| 907 | |
| 908 | p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. = append(p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample., &Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#{ |
| 909 | Valuescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Value.: []int64{1}, |
| 910 | Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location.: sloc, |
| 911 | }) |
| 912 | } |
| 913 | |
| 914 | if err := parseAdditionalSectionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseAdditionalSections().(s, p); err != nil { |
| 915 | return nil, err |
| 916 | } |
| 917 | |
| 918 | cleanupDuplicateLocationsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cleanupDuplicateLocations().(p) |
| 919 | return p, nil |
| 920 | } |
| 921 | |
| 922 | // parseThreadSample parses a symbolized or unsymbolized stack trace. |
| 923 | // Returns the first line after the traceback, the sample (or nil if |
| 924 | // it hits a 'same-as-previous' marker) and an error. |
| 925 | func parseThreadSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseThreadSample().(s *bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.Scannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#) (nextl string, addrs []uint64, err error) { |
| 926 | var line string |
| 927 | sameAsPrevious := false |
| 928 | for s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 929 | line = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 strings/TrimSpace().(s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().()) |
| 930 | if line == "" { |
| 931 | continue |
| 932 | } |
| 933 | |
| 934 | if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.24.0 strings/HasPrefix().(line, "---") { |
| 935 | break |
| 936 | } |
| 937 | if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.0 strings/Contains().(line, "same as previous thread") { |
| 938 | sameAsPrevious = true |
| 939 | continue |
| 940 | } |
| 941 | |
| 942 | curAddrs, err := parseHexAddressesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseHexAddresses().(line) |
| 943 | if err != nil { |
| 944 | 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().("malformed sample: %s: %v", line, err) |
| 945 | } |
| 946 | addrs = append(addrs, curAddrs...) |
| 947 | } |
| 948 | if err := s.Errscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Err().(); err != nil { |
| 949 | return "", nil, err |
| 950 | } |
| 951 | if sameAsPrevious { |
| 952 | return line, nil, nil |
| 953 | } |
| 954 | return line, addrs, nil |
| 955 | } |
| 956 | |
| 957 | // parseAdditionalSections parses any additional sections in the |
| 958 | // profile, ignoring any unrecognized sections. |
| 959 | func parseAdditionalSectionsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseAdditionalSections().(s *bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.Scannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#, p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) error { |
| 960 | for !isMemoryMapSentinelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isMemoryMapSentinel().(s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().()) && s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 961 | } |
| 962 | if err := s.Errscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Err().(); err != nil { |
| 963 | return err |
| 964 | } |
| 965 | return p.ParseMemoryMapFromScannerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#ParseMemoryMapFromScanner().(s) |
| 966 | } |
| 967 | |
| 968 | // ParseProcMaps parses a memory map in the format of /proc/self/maps. |
| 969 | // ParseMemoryMap should be called after setting on a profile to |
| 970 | // associate locations to the corresponding mapping based on their |
| 971 | // address. |
| 972 | func ParseProcMapsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ParseProcMaps().(rd ioscip-go gomod github.com/golang/go/src go1.24.0 io/.Readerscip-go gomod github.com/golang/go/src go1.24.0 io/Reader#) ([]*Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#, error) { |
| 973 | s := bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/NewScanner().(rd) |
| 974 | return parseProcMapsFromScannerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseProcMapsFromScanner().(s) |
| 975 | } |
| 976 | |
| 977 | func parseProcMapsFromScannerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseProcMapsFromScanner().(s *bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.Scannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#) ([]*Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#, error) { |
| 978 | var mapping []*Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping# |
| 979 | |
| 980 | var attrs []string |
| 981 | const delimiter = "=" |
| 982 | r := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.NewReplacerscip-go gomod github.com/golang/go/src go1.24.0 strings/NewReplacer().() |
| 983 | for s.Scanscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Scan().() { |
| 984 | line := r.Replacescip-go gomod github.com/golang/go/src go1.24.0 strings/Replacer#Replace().(removeLoggingInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/removeLoggingInfo().(s.Textscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Text().())) |
| 985 | m, err := parseMappingEntryscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseMappingEntry().(line) |
| 986 | if err != nil { |
| 987 | if err == errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. { |
| 988 | // Recognize assignments of the form: attr=value, and replace |
| 989 | // $attr with value on subsequent mappings. |
| 990 | if attr := 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().(line, delimiter, 2); len(attr) == 2 { |
| 991 | attrs = append(attrs, "$"+stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 strings/TrimSpace().(attr[0]), stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.24.0 strings/TrimSpace().(attr[1])) |
| 992 | r = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.NewReplacerscip-go gomod github.com/golang/go/src go1.24.0 strings/NewReplacer().(attrs...) |
| 993 | } |
| 994 | // Ignore any unrecognized entries |
| 995 | continue |
| 996 | } |
| 997 | return nil, err |
| 998 | } |
| 999 | if m == nil { |
| 1000 | continue |
| 1001 | } |
| 1002 | mapping = append(mapping, m) |
| 1003 | } |
| 1004 | if err := s.Errscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#Err().(); err != nil { |
| 1005 | return nil, err |
| 1006 | } |
| 1007 | return mapping, nil |
| 1008 | } |
| 1009 | |
| 1010 | // removeLoggingInfo detects and removes log prefix entries generated |
| 1011 | // by the glog package. If no logging prefix is detected, the string |
| 1012 | // is returned unmodified. |
| 1013 | func removeLoggingInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/removeLoggingInfo().(line string) string { |
| 1014 | if match := logInfoREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/logInfoRE..FindStringIndexscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringIndex().(line); match != nil { |
| 1015 | return line[match[1]:] |
| 1016 | } |
| 1017 | return line |
| 1018 | } |
| 1019 | |
| 1020 | // ParseMemoryMap parses a memory map in the format of |
| 1021 | // /proc/self/maps, and overrides the mappings in the current profile. |
| 1022 | // It renumbers the samples and locations in the profile correspondingly. |
| 1023 | func (p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) ParseMemoryMapscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#ParseMemoryMap().(rd ioscip-go gomod github.com/golang/go/src go1.24.0 io/.Readerscip-go gomod github.com/golang/go/src go1.24.0 io/Reader#) error { |
| 1024 | return p.ParseMemoryMapFromScannerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#ParseMemoryMapFromScanner().(bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/NewScanner().(rd)) |
| 1025 | } |
| 1026 | |
| 1027 | // ParseMemoryMapFromScanner parses a memory map in the format of |
| 1028 | // /proc/self/maps or a variety of legacy format, and overrides the |
| 1029 | // mappings in the current profile. It renumbers the samples and |
| 1030 | // locations in the profile correspondingly. |
| 1031 | func (p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) ParseMemoryMapFromScannerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#ParseMemoryMapFromScanner().(s *bufioscip-go gomod github.com/golang/go/src go1.24.0 bufio/.Scannerscip-go gomod github.com/golang/go/src go1.24.0 bufio/Scanner#) error { |
| 1032 | mapping, err := parseProcMapsFromScannerscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseProcMapsFromScanner().(s) |
| 1033 | if err != nil { |
| 1034 | return err |
| 1035 | } |
| 1036 | p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping. = append(p.Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Mapping., mapping...) |
| 1037 | p.massageMappingsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#massageMappings().() |
| 1038 | p.remapLocationIDsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#remapLocationIDs().() |
| 1039 | p.remapFunctionIDsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#remapFunctionIDs().() |
| 1040 | p.remapMappingIDsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#remapMappingIDs().() |
| 1041 | return nil |
| 1042 | } |
| 1043 | |
| 1044 | func parseMappingEntryscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseMappingEntry().(l string) (*Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#, error) { |
| 1045 | var start, end, perm, file, offset, buildID string |
| 1046 | if me := procMapsREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/procMapsRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(l); len(me) == 6 { |
| 1047 | start, end, perm, offset, file = me[1], me[2], me[3], me[4], me[5] |
| 1048 | } else if me := briefMapsREscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/briefMapsRE..FindStringSubmatchscip-go gomod github.com/golang/go/src go1.24.0 regexp/Regexp#FindStringSubmatch().(l); len(me) == 7 { |
| 1049 | start, end, perm, file, offset, buildID = me[1], me[2], me[3], me[4], me[5], me[6] |
| 1050 | } else { |
| 1051 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 1052 | } |
| 1053 | |
| 1054 | var err error |
| 1055 | mapping := &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 1056 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: file, |
| 1057 | BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID.: buildID, |
| 1058 | } |
| 1059 | if perm != "" && !stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.0 strings/Contains().(perm, "x") { |
| 1060 | // Skip non-executable entries. |
| 1061 | return nil, nil |
| 1062 | } |
| 1063 | if mapping.Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start., err = strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.ParseUintscip-go gomod github.com/golang/go/src go1.24.0 strconv/ParseUint().(start, 16, 64); err != nil { |
| 1064 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 1065 | } |
| 1066 | if mapping.Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit., err = strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.ParseUintscip-go gomod github.com/golang/go/src go1.24.0 strconv/ParseUint().(end, 16, 64); err != nil { |
| 1067 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 1068 | } |
| 1069 | if offset != "" { |
| 1070 | if mapping.Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset., err = strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/.ParseUintscip-go gomod github.com/golang/go/src go1.24.0 strconv/ParseUint().(offset, 16, 64); err != nil { |
| 1071 | return nil, errUnrecognizedscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/errUnrecognized. |
| 1072 | } |
| 1073 | } |
| 1074 | return mapping, nil |
| 1075 | } |
| 1076 | |
| 1077 | var memoryMapSentinelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/memoryMapSentinels. = []string{ |
| 1078 | "--- Memory map: ---", |
| 1079 | "MAPPED_LIBRARIES:", |
| 1080 | } |
| 1081 | |
| 1082 | // isMemoryMapSentinel returns true if the string contains one of the |
| 1083 | // known sentinels for memory map information. |
| 1084 | func isMemoryMapSentinelscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isMemoryMapSentinel().(line string) bool { |
| 1085 | for _, s := range memoryMapSentinelsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/memoryMapSentinels. { |
| 1086 | if stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.0 strings/Contains().(line, s) { |
| 1087 | return true |
| 1088 | } |
| 1089 | } |
| 1090 | return false |
| 1091 | } |
| 1092 | |
| 1093 | func (p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) addLegacyFrameInfoscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#addLegacyFrameInfo().() { |
| 1094 | switch { |
| 1095 | case isProfileTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isProfileType().(p, heapzSampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/heapzSampleTypes.): |
| 1096 | p.DropFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DropFrames., p.KeepFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#KeepFrames. = allocRxStrscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/allocRxStr., allocSkipRxStrscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/allocSkipRxStr. |
| 1097 | case isProfileTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isProfileType().(p, contentionzSampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/contentionzSampleTypes.): |
| 1098 | p.DropFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DropFrames., p.KeepFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#KeepFrames. = lockRxStrscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/lockRxStr., "" |
| 1099 | default: |
| 1100 | p.DropFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#DropFrames., p.KeepFramesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#KeepFrames. = cpuProfilerRxStrscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cpuProfilerRxStr., "" |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | var heapzSampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/heapzSampleTypes. = [][]string{ |
| 1105 | {"allocations", "size"}, // early Go pprof profiles |
| 1106 | {"objects", "space"}, |
| 1107 | {"inuse_objects", "inuse_space"}, |
| 1108 | {"alloc_objects", "alloc_space"}, |
| 1109 | {"alloc_objects", "alloc_space", "inuse_objects", "inuse_space"}, // Go pprof legacy profiles |
| 1110 | } |
| 1111 | var contentionzSampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/contentionzSampleTypes. = [][]string{ |
| 1112 | {"contentions", "delay"}, |
| 1113 | } |
| 1114 | |
| 1115 | func isProfileTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isProfileType().(p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, types [][]string) bool { |
| 1116 | st := p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType. |
| 1117 | nextType: |
| 1118 | for _, t := range types { |
| 1119 | if len(st) != len(t) { |
| 1120 | continue |
| 1121 | } |
| 1122 | |
| 1123 | for i := range st { |
| 1124 | if st[i].Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type. != t[i] { |
| 1125 | continue nextType |
| 1126 | } |
| 1127 | } |
| 1128 | return true |
| 1129 | } |
| 1130 | return false |
| 1131 | } |
| 1132 | |
| 1133 | var allocRxStrscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/allocRxStr. = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().([]string{ |
| 1134 | // POSIX entry points. |
| 1135 | `calloc`, |
| 1136 | `cfree`, |
| 1137 | `malloc`, |
| 1138 | `free`, |
| 1139 | `memalign`, |
| 1140 | `do_memalign`, |
| 1141 | `(__)?posix_memalign`, |
| 1142 | `pvalloc`, |
| 1143 | `valloc`, |
| 1144 | `realloc`, |
| 1145 | |
| 1146 | // TC malloc. |
| 1147 | `tcmalloc::.*`, |
| 1148 | `tc_calloc`, |
| 1149 | `tc_cfree`, |
| 1150 | `tc_malloc`, |
| 1151 | `tc_free`, |
| 1152 | `tc_memalign`, |
| 1153 | `tc_posix_memalign`, |
| 1154 | `tc_pvalloc`, |
| 1155 | `tc_valloc`, |
| 1156 | `tc_realloc`, |
| 1157 | `tc_new`, |
| 1158 | `tc_delete`, |
| 1159 | `tc_newarray`, |
| 1160 | `tc_deletearray`, |
| 1161 | `tc_new_nothrow`, |
| 1162 | `tc_newarray_nothrow`, |
| 1163 | |
| 1164 | // Memory-allocation routines on OS X. |
| 1165 | `malloc_zone_malloc`, |
| 1166 | `malloc_zone_calloc`, |
| 1167 | `malloc_zone_valloc`, |
| 1168 | `malloc_zone_realloc`, |
| 1169 | `malloc_zone_memalign`, |
| 1170 | `malloc_zone_free`, |
| 1171 | |
| 1172 | // Go runtime |
| 1173 | `runtime\..*`, |
| 1174 | |
| 1175 | // Other misc. memory allocation routines |
| 1176 | `BaseArena::.*`, |
| 1177 | `(::)?do_malloc_no_errno`, |
| 1178 | `(::)?do_malloc_pages`, |
| 1179 | `(::)?do_malloc`, |
| 1180 | `DoSampledAllocation`, |
| 1181 | `MallocedMemBlock::MallocedMemBlock`, |
| 1182 | `_M_allocate`, |
| 1183 | `__builtin_(vec_)?delete`, |
| 1184 | `__builtin_(vec_)?new`, |
| 1185 | `__gnu_cxx::new_allocator::allocate`, |
| 1186 | `__libc_malloc`, |
| 1187 | `__malloc_alloc_template::allocate`, |
| 1188 | `allocate`, |
| 1189 | `cpp_alloc`, |
| 1190 | `operator new(\[\])?`, |
| 1191 | `simple_alloc::allocate`, |
| 1192 | }, `|`) |
| 1193 | |
| 1194 | var allocSkipRxStrscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/allocSkipRxStr. = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().([]string{ |
| 1195 | // Preserve Go runtime frames that appear in the middle/bottom of |
| 1196 | // the stack. |
| 1197 | `runtime\.panic`, |
| 1198 | `runtime\.reflectcall`, |
| 1199 | `runtime\.call[0-9]*`, |
| 1200 | }, `|`) |
| 1201 | |
| 1202 | var cpuProfilerRxStrscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cpuProfilerRxStr. = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().([]string{ |
| 1203 | `ProfileData::Add`, |
| 1204 | `ProfileData::prof_handler`, |
| 1205 | `CpuProfiler::prof_handler`, |
| 1206 | `__pthread_sighandler`, |
| 1207 | `__restore`, |
| 1208 | }, `|`) |
| 1209 | |
| 1210 | var lockRxStrscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/lockRxStr. = stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.24.0 strings/Join().([]string{ |
| 1211 | `RecordLockProfileData`, |
| 1212 | `(base::)?RecordLockProfileData.*`, |
| 1213 | `(base::)?SubmitMutexProfileData.*`, |
| 1214 | `(base::)?SubmitSpinLockProfileData.*`, |
| 1215 | `(base::Mutex::)?AwaitCommon.*`, |
| 1216 | `(base::Mutex::)?Unlock.*`, |
| 1217 | `(base::Mutex::)?UnlockSlow.*`, |
| 1218 | `(base::Mutex::)?ReaderUnlock.*`, |
| 1219 | `(base::MutexLock::)?~MutexLock.*`, |
| 1220 | `(Mutex::)?AwaitCommon.*`, |
| 1221 | `(Mutex::)?Unlock.*`, |
| 1222 | `(Mutex::)?UnlockSlow.*`, |
| 1223 | `(Mutex::)?ReaderUnlock.*`, |
| 1224 | `(MutexLock::)?~MutexLock.*`, |
| 1225 | `(SpinLock::)?Unlock.*`, |
| 1226 | `(SpinLock::)?SlowUnlock.*`, |
| 1227 | `(SpinLockHolder::)?~SpinLockHolder.*`, |
| 1228 | }, `|`) |