From f907c7a0bc53cc3075f4b183a8bf68a5a1d10cd9 Mon Sep 17 00:00:00 2001 From: Denis Maksimov Date: Thu, 2 Feb 2023 14:12:18 +0300 Subject: [PATCH] feat: add allocs handler --- pprof.go | 9 +++++++++ pprof_test.go | 2 ++ 2 files changed, 11 insertions(+) diff --git a/pprof.go b/pprof.go index d52d8c0..6ed8396 100644 --- a/pprof.go +++ b/pprof.go @@ -34,6 +34,7 @@ func WrapGroup(prefix string, g *echo.Group) { {"POST", "/symbol", SymbolHandler()}, {"GET", "/trace", TraceHandler()}, {"GET", "/mutex", MutexHandler()}, + {"GET", "/allocs", AllocsHandler()}, } for _, r := range routers { @@ -125,3 +126,11 @@ func MutexHandler() echo.HandlerFunc { return nil } } + +// AllocsHandler will pass the call from /debug/pprof/allocs to pprof. +func AllocsHandler() echo.HandlerFunc { + return func(ctx echo.Context) error { + pprof.Handler("allocs").ServeHTTP(ctx.Response().Writer, ctx.Request()) + return nil + } +} diff --git a/pprof_test.go b/pprof_test.go index f06a220..0a2e15f 100644 --- a/pprof_test.go +++ b/pprof_test.go @@ -44,6 +44,7 @@ func TestWrap(t *testing.T) { "/debug/pprof/symbol": "SymbolHandler", "/debug/pprof/trace": "TraceHandler", "/debug/pprof/mutex": "MutexHandler", + "/debug/pprof/allocs": "AllocsHandler", } checkRouters(e.Routes(), t, expectedRouters) @@ -67,6 +68,7 @@ func TestWrapGroup(t *testing.T) { "/symbol": "SymbolHandler", "/trace": "TraceHandler", "/mutex": "MutexHandler", + "/allocs": "AllocsHandler", } expectedRouters := make(map[string]string, len(baseRouters)) for r, h := range baseRouters {