| 1 | // Copyright 2014 Google Inc. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ |
| 16 | |
| 17 | import ( |
| 18 | "bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/" |
| 19 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 20 | "reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/" |
| 21 | "strconvscip-go gomod github.com/golang/go/src go1.24.0 strconv/" |
| 22 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 23 | "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/" |
| 24 | ) |
| 25 | |
| 26 | func TestLegacyProfileTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/TestLegacyProfileType().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 27 | type testcase struct { |
| 28 | sampleTypes []string |
| 29 | typeSet [][]string |
| 30 | want bool |
| 31 | setName string |
| 32 | } |
| 33 | |
| 34 | heap := heapzSampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/heapzSampleTypes. |
| 35 | cont := contentionzSampleTypesscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/contentionzSampleTypes. |
| 36 | testcases := []testcase{ |
| 37 | // True cases |
| 38 | {[]string{"allocations", "size"}, heap, true, "heapzSampleTypes"}, |
| 39 | {[]string{"objects", "space"}, heap, true, "heapzSampleTypes"}, |
| 40 | {[]string{"inuse_objects", "inuse_space"}, heap, true, "heapzSampleTypes"}, |
| 41 | {[]string{"alloc_objects", "alloc_space"}, heap, true, "heapzSampleTypes"}, |
| 42 | {[]string{"alloc_objects", "alloc_space", "inuse_objects", "inuse_space"}, heap, true, "heapzSampleTypes"}, |
| 43 | {[]string{"contentions", "delay"}, cont, true, "contentionzSampleTypes"}, |
| 44 | // False cases |
| 45 | {[]string{"objects"}, heap, false, "heapzSampleTypes"}, |
| 46 | {[]string{"objects", "unknown"}, heap, false, "heapzSampleTypes"}, |
| 47 | {[]string{"inuse_objects", "inuse_space", "alloc_objects", "alloc_space"}, heap, false, "heapzSampleTypes"}, |
| 48 | {[]string{"contentions", "delay"}, heap, false, "heapzSampleTypes"}, |
| 49 | {[]string{"samples", "cpu"}, heap, false, "heapzSampleTypes"}, |
| 50 | {[]string{"samples", "cpu"}, cont, false, "contentionzSampleTypes"}, |
| 51 | } |
| 52 | |
| 53 | for _, tc := range testcases { |
| 54 | p := profileOfTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileOfType().(tc.sampleTypes) |
| 55 | if got := isProfileTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/isProfileType().(p, tc.typeSet); got != tc.want { |
| 56 | t.Errorscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Error().("isProfileType({"+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().(tc.sampleTypes, ",")+"},", tc.setName, "), got", got, "want", tc.want) |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | func TestCpuParsescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/TestCpuParse().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 62 | // profileString is a legacy encoded profile, represented by words separated by ":" |
| 63 | // Each sample has the form value : N : stack1..stackN |
| 64 | // EOF is represented as "0:1:0" |
| 65 | profileString := "1:3:100:999:100:" // sample with bogus 999 and duplicate leaf |
| 66 | profileString += "1:5:200:999:200:501:502:" // sample with bogus 999 and duplicate leaf |
| 67 | profileString += "1:12:300:999:300:601:602:603:604:605:606:607:608:609:" // sample with bogus 999 and duplicate leaf |
| 68 | profileString += "0:1:0000" // EOF -- must use 4 bytes for the final zero |
| 69 | |
| 70 | p, err := cpuProfilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/cpuProfile().([]byte(profileString), 1, parseStringscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseString().) |
| 71 | if err != nil { |
| 72 | t.Fatalscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatal().(err) |
| 73 | } |
| 74 | |
| 75 | if err := checkTestSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/checkTestSample().(p, []uint64{100}); err != nil { |
| 76 | t.Errorscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Error().(err) |
| 77 | } |
| 78 | if err := checkTestSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/checkTestSample().(p, []uint64{200, 500, 501}); err != nil { |
| 79 | t.Errorscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Error().(err) |
| 80 | } |
| 81 | if err := checkTestSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/checkTestSample().(p, []uint64{300, 600, 601, 602, 603, 604, 605, 606, 607, 608}); err != nil { |
| 82 | t.Errorscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Error().(err) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | func parseStringscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseString().(b []byte) (uint64, []byte) { |
| 87 | slices := bytesscip-go gomod github.com/golang/go/src go1.24.0 bytes/.SplitNscip-go gomod github.com/golang/go/src go1.24.0 bytes/SplitN().(b, []byte(":"), 2) |
| 88 | var value, remainder []byte |
| 89 | if len(slices) > 0 { |
| 90 | value = slices[0] |
| 91 | } |
| 92 | if len(slices) > 1 { |
| 93 | remainder = slices[1] |
| 94 | } |
| 95 | v, _ := 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().(string(value), 10, 64) |
| 96 | return v, remainder |
| 97 | } |
| 98 | |
| 99 | func checkTestSamplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/checkTestSample().(p *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#, want []uint64) error { |
| 100 | for _, s := range p.Samplescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#Sample. { |
| 101 | got := []uint64{} |
| 102 | for _, l := range s.Locationscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Sample#Location. { |
| 103 | got = append(got, l.Addressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Location#Address.) |
| 104 | } |
| 105 | if reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.24.0 reflect/DeepEqual().(got, want) { |
| 106 | return nil |
| 107 | } |
| 108 | } |
| 109 | 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().("Could not find sample : %v", want) |
| 110 | } |
| 111 | |
| 112 | // profileOfType creates an empty profile with only sample types set, |
| 113 | // for testing purposes only. |
| 114 | func profileOfTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/profileOfType().(sampleTypes []string) *Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile# { |
| 115 | p := new(Profilescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#) |
| 116 | p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType. = make([]*ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#, len(sampleTypes)) |
| 117 | for i, t := range sampleTypes { |
| 118 | p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.[i] = new(ValueTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#) |
| 119 | p.SampleTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#SampleType.[i].Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type. = t |
| 120 | } |
| 121 | return p |
| 122 | } |
| 123 | |
| 124 | func TestParseMappingEntryscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/TestParseMappingEntry().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 125 | for _, test := range []*struct { |
| 126 | entry string |
| 127 | want *Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping# |
| 128 | }{ |
| 129 | { |
| 130 | entry: "00400000-02e00000 r-xp 00000000 00:00 0", |
| 131 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 132 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x400000, |
| 133 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x2e00000, |
| 134 | }, |
| 135 | }, |
| 136 | { |
| 137 | entry: "02e00000-02e8a000 r-xp 02a00000 00:00 15953927 /foo/bin", |
| 138 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 139 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x2e00000, |
| 140 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x2e8a000, |
| 141 | Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset.: 0x2a00000, |
| 142 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "/foo/bin", |
| 143 | }, |
| 144 | }, |
| 145 | { |
| 146 | entry: "02e00000-02e8a000 r-xp 000000 00:00 15953927 [vdso]", |
| 147 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 148 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x2e00000, |
| 149 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x2e8a000, |
| 150 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "[vdso]", |
| 151 | }, |
| 152 | }, |
| 153 | { |
| 154 | entry: " 02e00000-02e8a000: /foo/bin (@2a00000)", |
| 155 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 156 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x2e00000, |
| 157 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x2e8a000, |
| 158 | Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset.: 0x2a00000, |
| 159 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "/foo/bin", |
| 160 | }, |
| 161 | }, |
| 162 | { |
| 163 | entry: " 02e00000-02e8a000: /foo/bin (deleted)", |
| 164 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 165 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x2e00000, |
| 166 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x2e8a000, |
| 167 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "/foo/bin", |
| 168 | }, |
| 169 | }, |
| 170 | { |
| 171 | entry: " 02e00000-02e8a000: /foo/bin", |
| 172 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 173 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x2e00000, |
| 174 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x2e8a000, |
| 175 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "/foo/bin", |
| 176 | }, |
| 177 | }, |
| 178 | { |
| 179 | entry: " 02e00000-02e8a000: [vdso]", |
| 180 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 181 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x2e00000, |
| 182 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x2e8a000, |
| 183 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "[vdso]", |
| 184 | }, |
| 185 | }, |
| 186 | {entry: "0xff6810563000 0xff6810565000 r-xp abc_exe 87c4d547f895cfd6a370e08dc5c5ee7bd4199d5b", |
| 187 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 188 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0xff6810563000, |
| 189 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0xff6810565000, |
| 190 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "abc_exe", |
| 191 | BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID.: "87c4d547f895cfd6a370e08dc5c5ee7bd4199d5b", |
| 192 | }, |
| 193 | }, |
| 194 | {entry: "7f5e5435e000-7f5e5455e000 --xp 00002000 00:00 1531 myprogram", |
| 195 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 196 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x7f5e5435e000, |
| 197 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x7f5e5455e000, |
| 198 | Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset.: 0x2000, |
| 199 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "myprogram", |
| 200 | }, |
| 201 | }, |
| 202 | {entry: "7f7472710000-7f7472722000 r-xp 00000000 fc:00 790190 /usr/lib/libfantastic-1.2.so", |
| 203 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 204 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x7f7472710000, |
| 205 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x7f7472722000, |
| 206 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "/usr/lib/libfantastic-1.2.so", |
| 207 | }, |
| 208 | }, |
| 209 | {entry: "7f47a542f000-7f47a5447000: /lib/libpthread-2.15.so", |
| 210 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 211 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x7f47a542f000, |
| 212 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x7f47a5447000, |
| 213 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "/lib/libpthread-2.15.so", |
| 214 | }, |
| 215 | }, |
| 216 | {entry: "0x40000-0x80000 /path/to/binary (@FF00) abc123456", |
| 217 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 218 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x40000, |
| 219 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x80000, |
| 220 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "/path/to/binary", |
| 221 | Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset.: 0xFF00, |
| 222 | BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID.: "abc123456", |
| 223 | }, |
| 224 | }, |
| 225 | {entry: "W1220 15:07:15.201776 8272 logger.cc:12033] --- Memory map: ---\n" + |
| 226 | "0x40000-0x80000 /path/to/binary (@FF00) abc123456", |
| 227 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 228 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x40000, |
| 229 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x80000, |
| 230 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "/path/to/binary", |
| 231 | Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset.: 0xFF00, |
| 232 | BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID.: "abc123456", |
| 233 | }, |
| 234 | }, |
| 235 | {entry: "W1220 15:07:15.201776 8272 logger.cc:12033] --- Memory map: ---\n" + |
| 236 | "W1220 15:07:15.202776 8272 logger.cc:12036] 0x40000-0x80000 /path/to/binary (@FF00) abc123456", |
| 237 | want: &Mappingscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#{ |
| 238 | Startscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Start.: 0x40000, |
| 239 | Limitscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Limit.: 0x80000, |
| 240 | Filescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#File.: "/path/to/binary", |
| 241 | Offsetscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#Offset.: 0xFF00, |
| 242 | BuildIDscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Mapping#BuildID.: "abc123456", |
| 243 | }, |
| 244 | }, |
| 245 | {entry: "7f5e5435e000-7f5e5455e000 ---p 00002000 00:00 1531 myprogram", |
| 246 | want: nil, |
| 247 | }, |
| 248 | } { |
| 249 | got, err := ParseProcMapsscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ParseProcMaps().(stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.24.0 strings/NewReader().(test.entry)) |
| 250 | if err != nil { |
| 251 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("%s: %v", test.entry, err) |
| 252 | continue |
| 253 | } |
| 254 | if test.want == nil { |
| 255 | if got, want := len(got), 0; got != want { |
| 256 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("%s: got %d mappings, want %d", test.entry, got, want) |
| 257 | } |
| 258 | continue |
| 259 | } |
| 260 | if got, want := len(got), 1; got != want { |
| 261 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("%s: got %d mappings, want %d", test.entry, got, want) |
| 262 | continue |
| 263 | } |
| 264 | if !reflectscip-go gomod github.com/golang/go/src go1.24.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.24.0 reflect/DeepEqual().(test.want, got[0]) { |
| 265 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("%s want=%v got=%v", test.entry, test.want, got[0]) |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | func TestParseThreadProfileWithInvalidAddressscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/TestParseThreadProfileWithInvalidAddress().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 271 | profile := ` |
| 272 | --- threadz 1 --- |
| 273 | |
| 274 | --- Thread 7eff063d9940 (name: main/25376) stack: --- |
| 275 | PC: 0x40b688 0x4d5f51 0x40be31 0x473add693e639c6f0 |
| 276 | --- Memory map: --- |
| 277 | 00400000-00fcb000: /home/rsilvera/cppbench/cppbench_server_main.unstripped |
| 278 | ` |
| 279 | wantErr := "failed to parse as hex 64-bit number: 0x473add693e639c6f0" |
| 280 | if _, gotErr := parseThreadscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseThread().([]byte(profile)); !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().(gotErr.Error(), wantErr) { |
| 281 | t.Errorfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Errorf().("parseThread(): got error %q, want error containing %q", gotErr, wantErr) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | func TestParseGoCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/TestParseGoCount().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 286 | for _, test := range []struct { |
| 287 | in string |
| 288 | typ string |
| 289 | }{ |
| 290 | { |
| 291 | in: `# ignored comment |
| 292 | |
| 293 | threadcreate profile: total 123 |
| 294 | `, |
| 295 | typ: "threadcreate", |
| 296 | }, |
| 297 | { |
| 298 | in: ` |
| 299 | # ignored comment |
| 300 | goroutine profile: total 123456 |
| 301 | `, |
| 302 | typ: "goroutine", |
| 303 | }, |
| 304 | { |
| 305 | in: ` |
| 306 | sub/dir-ect_o.ry profile: total 999 |
| 307 | `, |
| 308 | typ: "sub/dir-ect_o.ry", |
| 309 | }, |
| 310 | } { |
| 311 | t.Runscip-go gomod github.com/golang/go/src go1.24.0 testing/T#Run().(test.typ, func(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) { |
| 312 | p, err := parseGoCountscip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/parseGoCount().([]byte(test.in)) |
| 313 | if err != nil { |
| 314 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("parseGoCount(%q) = %v", test.in, err) |
| 315 | } |
| 316 | if typ := p.PeriodTypescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/Profile#PeriodType..Typescip-go gomod github.com/google/pprof . `github.com/google/pprof/profile`/ValueType#Type.; typ != test.typ { |
| 317 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24.0 testing/common#Fatalf().("parseGoCount(%q).PeriodType.Type = %q want %q", test.in, typ, test.typ) |
| 318 | } |
| 319 | }) |
| 320 | } |
| 321 | } |