From 0ee4b13830572ad66cdcc045d1e4ae1e15a87ebb Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Wed, 22 Apr 2020 16:24:30 -0400 Subject: [PATCH] net/http/pprof: allow "seconds" parameters to most profiles golang.org/cl/147598 added the support for delta computation for mutex and block profiles. In fact, this delta computation makes sense for other types of profiles. For example, /debug/pprof/allocs?seconds=x will provide how much allocation was made during the specified period. /debug/pprof/goroutine?seconds=x will provide the changes in the list of goroutines. This also makes sense for custom profiles. Update #23401 Update google/pprof#526 Change-Id: I45e9073eb001ea5b3f3d16e5a57f635193610656 Reviewed-on: https://go-review.googlesource.com/c/go/+/229537 Run-TryBot: Hyang-Ah Hana Kim TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor Reviewed-by: Emmanuel Odeke --- src/net/http/pprof/pprof.go | 8 ++++++-- src/net/http/pprof/pprof_test.go | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/net/http/pprof/pprof.go b/src/net/http/pprof/pprof.go index 36b0af452d..4fd19eb539 100644 --- a/src/net/http/pprof/pprof.go +++ b/src/net/http/pprof/pprof.go @@ -334,8 +334,12 @@ func collectProfile(p *pprof.Profile) (*profile.Profile, error) { } var profileSupportsDelta = map[handler]bool{ - "block": true, - "mutex": true, + "allocs": true, + "block": true, + "goroutine": true, + "heap": true, + "mutex": true, + "threadcreate": true, } var profileDescriptions = map[string]string{ diff --git a/src/net/http/pprof/pprof_test.go b/src/net/http/pprof/pprof_test.go index 49c4c81caa..f6f9ef5b04 100644 --- a/src/net/http/pprof/pprof_test.go +++ b/src/net/http/pprof/pprof_test.go @@ -49,6 +49,7 @@ func TestHandlers(t *testing.T) { {"/debug/pprof/trace", Trace, http.StatusOK, "application/octet-stream", `attachment; filename="trace"`, nil}, {"/debug/pprof/mutex", Index, http.StatusOK, "application/octet-stream", `attachment; filename="mutex"`, nil}, {"/debug/pprof/block?seconds=1", Index, http.StatusOK, "application/octet-stream", `attachment; filename="block-delta"`, nil}, + {"/debug/pprof/goroutine?seconds=1", Index, http.StatusOK, "application/octet-stream", `attachment; filename="goroutine-delta"`, nil}, {"/debug/pprof/", Index, http.StatusOK, "text/html; charset=utf-8", "", []byte("Types of profiles available:")}, } for _, tc := range testCases { -- 2.48.1