aboutsummaryrefslogtreecommitdiff
path: root/src/internal/profile
AgeCommit message (Collapse)Author
2026-02-03all: prealloc slice with possible minimum capabilitiesShulhan
2025-11-03internal/profile: optimize Parse allocsMaxim Merzhanov
In our case, it greatly improves the performance of continuously collecting diff profiles from the net/http/pprof endpoint, such as /debug/pprof/allocs?seconds=30. This CL is a cherry-pick of my PR upstream: https://github.com/google/pprof/pull/951 Benchmark of profile Parse func: goos: linux goarch: amd64 pkg: github.com/google/pprof/profile cpu: 13th Gen Intel(R) Core(TM) i7-1360P │ old-parse.txt │ new-parse.txt │ │ sec/op │ sec/op vs base │ Parse-16 62.07m ± 13% 55.54m ± 13% -10.52% (p=0.035 n=10) │ old-parse.txt │ new-parse.txt │ │ B/op │ B/op vs base │ Parse-16 47.56Mi ± 0% 41.09Mi ± 0% -13.59% (p=0.000 n=10) │ old-parse.txt │ new-parse.txt │ │ allocs/op │ allocs/op vs base │ Parse-16 272.9k ± 0% 175.8k ± 0% -35.58% (p=0.000 n=10) Change-Id: I737ff9b9f815fdc56bc3b5743403717c4b6f07fd GitHub-Last-Rev: a09108f7ff7e6a27509f300d617e7adb36a9eb8a GitHub-Pull-Request: golang/go#76145 Reviewed-on: https://go-review.googlesource.com/c/go/+/717081 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Florian Lehner <lehner.florian86@gmail.com>
2025-04-18internal,runtime: use the builtin clearapocelipes
To simplify the code. Change-Id: I023de705504c0b580718eec3c7c563b6cf2c8184 GitHub-Last-Rev: 026b32c799b13d0c7ded54f2e61429e6c5ed0aa8 GitHub-Pull-Request: golang/go#73412 Reviewed-on: https://go-review.googlesource.com/c/go/+/666118 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com>
2024-07-25go,internal,io,mime: use slices and maps to clean testsapocelipes
Replace reflect.DeepEqual with slices.Equal/maps.Equal, which is much faster. Change-Id: Id9cb550884da817da96befdeccfecb3325fb4414 GitHub-Last-Rev: 7d64d78feb86e3ea1af6c24ea6782cb85731bb52 GitHub-Pull-Request: golang/go#67612 Reviewed-on: https://go-review.googlesource.com/c/go/+/587819 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-02-08internal/pprof: remove unused codeqiulaidongfeng
Change-Id: I47e98122668960321124e426b345d36f6916b738 GitHub-Last-Rev: b72c9ab33e1c9c49b3b44dc8782344d1ed481123 GitHub-Pull-Request: golang/go#65594 Reviewed-on: https://go-review.googlesource.com/c/go/+/562324 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-02-05cmd/compile: delete unused code and fix typo in commentJun10ng
Change-Id: Ia1f1c7d5563a74950c47cf3ebdcb600b34c83e85 GitHub-Last-Rev: bd58214e5e66e32c0055936820b8f0adf7f388c6 GitHub-Pull-Request: golang/go#65527 Reviewed-on: https://go-review.googlesource.com/c/go/+/561355 Auto-Submit: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2024-01-31internal/profile: remove legacy profile supportMichael Pratt
internal/profile.Parse is only used in two places: cmd/compile for parsing PGO profiles, and net/http/pprof for parsing runtime/pprof profiles for delta profiles. Neither case ever encounters legacy profiles, so we can remove support entirely from the package. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest Change-Id: Ic5f85b3fc1e1367131b6039dac9378913cbf9f2c Reviewed-on: https://go-review.googlesource.com/c/go/+/548035 Auto-Submit: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-01-31cmd/preprofile: Implement a tool to preprocess the PGO profile.Jin Lin
It fixes the issue https://github.com/golang/go/issues/65220. It also includes https://go.dev/cl/557458 from Michael. Change-Id: Ic6109e1b6a9045459ff4a54dea11cbfe732b01e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/557918 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-01-22Revert "cmd/preprofile: Add preprocess tool to pre-parse the profile file."Michael Pratt
This reverts CL 529738. Reason for revert: Breaking longtest builders For #58102. Fixes #65220. Change-Id: Id295e3249da9d82f6a9e4fc571760302a1362def Reviewed-on: https://go-review.googlesource.com/c/go/+/557460 Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-01-22cmd/preprofile: Add preprocess tool to pre-parse the profile file.Jin Lin
The pgo compilation time is very long if the profile file is large. We added a preprocess tool to pre-parse profile file in order to expedite the compile time. Change-Id: I6f50bbd01f242448e2463607a9b63483c6ca9a12 Reviewed-on: https://go-review.googlesource.com/c/go/+/529738 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-12-07internal/profile: fully decode proto even if there are no samplesMichael Pratt
This is a partial revert of CL 483137. CL 483137 started checking errors in postDecode, which is good. Now we can catch more malformed pprof protos. However this made TestEmptyProfile fail, so an early return was added when the profile was "empty" (no samples). Unfortunately, this was problematic. Profiles with no samples can still be valid, but skipping postDecode meant that the resulting Profile was missing values from the string table. In particular, net/http/pprof needs to parse empty profiles in order to pass through the sample and period types to a final output proto. CL 483137 broke this behavior. internal/profile.Parse is only used in two places: in cmd/compile to parse PGO pprof profiles, and in net/http/pprof to parse before/after pprof profiles for delta profiles. In both cases, the input is never literally empty (0 bytes). Even a pprof proto with no samples still contains some header fields, such as sample and period type. Upstream github.com/google/pprof/profile even has an explicit error on 0 byte input, so `go tool pprof` will not support such an input. Thus TestEmptyProfile was misleading; this profile doesn't need to support empty input at all. Resolve this by removing TestEmptyProfile and replacing it with an explicit error on empty input, as upstream github.com/google/pprof/profile has. For non-empty input, always run postDecode to ensure the string table is processed. TestConvertCPUProfileEmpty is reverted back to assert the values from before CL 483137. Note that in this case "Empty" means no samples, not a 0 byte input. Continue to allow empty files for PGO in order to minimize the chance of last minute breakage if some users have empty files. Fixes #64566. Change-Id: I83a1f0200ae225ac6da0009d4b2431fe215b283f Reviewed-on: https://go-review.googlesource.com/c/go/+/547996 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-10-26internal/profile: actually return errors in postDecodeDaniel Martí
As spotted by staticcheck, the body did keep track of errors by sharing a single err variable, but its last value was never used as the function simply finished by returning nil. To prevent postDecode from erroring on empty profiles, which breaks TestEmptyProfile, add a check at the top of the function. Update the runtime/pprof test accordingly, since the default units didn't make sense for an empty profile anyway. Change-Id: I188cd8337434adf9169651ab5c914731b8b20f39 Reviewed-on: https://go-review.googlesource.com/c/go/+/483137 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-01-20internal/profile: use internal/lazyregexp for the legacy parserDaniel Martí
Per benchinit, this makes a big difference to init times: name old time/op new time/op delta InternalProfile 185µs ± 1% 6µs ± 1% -96.51% (p=0.008 n=5+5) name old alloc/op new alloc/op delta InternalProfile 101kB ± 0% 4kB ± 0% -95.72% (p=0.008 n=5+5) name old allocs/op new allocs/op delta InternalProfile 758 ± 0% 25 ± 0% -96.70% (p=0.008 n=5+5) The fixed 0.2ms init cost is saved for any importer of net/http/pprof, but also for cmd/compile, as it supports PGO now. A Go program parsing profiles might not even need to compile these regular expressions at all, if it doesn't encounter any legacy files. I suspect this will be the case with most invocations of cmd/compile. Updates #26775. Change-Id: I8374dc64459f0b6bb09bbdf9d0b6c55d7ae1646e Reviewed-on: https://go-review.googlesource.com/c/go/+/460545 Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-18all: add missing periods in commentscui fliter
Change-Id: I69065f8adf101fdb28682c55997f503013a50e29 Reviewed-on: https://go-review.googlesource.com/c/go/+/449757 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Joedian Reid <joedian@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-11-17internal/profile: remove unused encodeStringOptTobias Klauser
Change-Id: Icaee8064c5ab61cc2ad28c2d1d06d70f845754fa Reviewed-on: https://go-review.googlesource.com/c/go/+/451535 Reviewed-by: Joedian Reid <joedian@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
2022-11-09all: add missing copyright headercui fliter
Change-Id: Ia5a090953d324f0f8aa9c1808c88125ad5eb6f98 Reviewed-on: https://go-review.googlesource.com/c/go/+/448955 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2022-10-28cmd/compile: Enables PGO in Go and performs profile-guided inliningRaj Barik
For #55022 Change-Id: I51f1ba166d5a66dcaf4b280756be4a6bf9545c5e Reviewed-on: https://go-review.googlesource.com/c/go/+/429863 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com>
2022-09-30internal: fix a few function names on commentscui fliter
Change-Id: I53169e386b8c789b092de348fa891fe50e11c2ef GitHub-Last-Rev: 75232393b4ba415bddc731f15550d7094ccfd953 GitHub-Pull-Request: golang/go#55965 Reviewed-on: https://go-review.googlesource.com/c/go/+/436883 Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-09-30internal/profile: omit comparison tool bool constantcuiweixie
Change-Id: I59b3e72382433a6dd82306f026171f3af4a6cba7 Reviewed-on: https://go-review.googlesource.com/c/go/+/436717 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com>
2022-08-23runtime/pprof: remove round-to-file-start adjustmentKeith Randall
This causes a problem in the test sometimes. With a mapping like: 00400000-00411000 r--p 00000000 fe:01 4459044 /tmp/go-build1710804385/b001/pprof.test 00411000-00645000 r-xp 00011000 fe:01 4459044 /tmp/go-build1710804385/b001/pprof.test The removed code would make the first mapping 0x400000-0x645000. Tests then grab the first few addresses to use as PCs, thinking they are in an executable range. But those addresses are really not in an executable range, causing the tests to fail. Change-Id: I5a69d0259d1fd70ff9745df1cbad4d54c5898e7b Reviewed-on: https://go-review.googlesource.com/c/go/+/424295 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Keith Randall <khr@golang.org>
2022-08-11internal/pprof/profile: simplify variable useAbirdcfly
Change-Id: I73b5d7602fccec00e68e4516f483f90163088ad1 GitHub-Last-Rev: 9366b89c47d5a209e2f239dbc473d851f9fed37e GitHub-Pull-Request: golang/go#54083 Reviewed-on: https://go-review.googlesource.com/c/go/+/419635 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-10-06all: use bytes.Cut, strings.CutRuss Cox
Many uses of Index/IndexByte/IndexRune/Split/SplitN can be written more clearly using the new Cut functions. Do that. Also rewrite to other functions if that's clearer. For #46336. Change-Id: I68d024716ace41a57a8bf74455c62279bde0f448 Reviewed-on: https://go-review.googlesource.com/c/go/+/351711 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-20all: update references to symbols moved from io/ioutil to ioRuss Cox
The old ioutil references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-17net/http/pprof: support the "seconds" param for block, mutex profilesHana Kim
When the seconds param is given, the block and mutex profile endpoints report the difference between two measurements collected the given seconds apart. Historically, the block and mutex profiles have reported the cumulative counts since the process start, and it turned out they are more useful when interpreted along with the time duration. Note: cpu profile and trace endpoints already accept the "seconds" parameter. With this CL, the block and mutex profile endpoints will accept the "seconds" parameter. Providing the "seconds" parameter to other types of profiles is an error. This change moves runtime/pprof/internal/profile to internal/profile and adds part of merge logic from github.com/google/pprof/profile/merge.go to internal/profile, in order to allow both net/http/pprof and runtime/pprof to access it. Fixes #23401 Change-Id: Ie2486f1a63eb8ff210d7d3bc2de683e9335fd5cd Reviewed-on: https://go-review.googlesource.com/c/go/+/147598 Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>