github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/web/tools/tools.go (about)

     1  package tools
     2  
     3  import (
     4  	"runtime"
     5  	"runtime/pprof"
     6  
     7  	"github.com/labstack/echo/v4"
     8  )
     9  
    10  func HeapProfiling(c echo.Context) error {
    11  	res := c.Response()
    12  	res.Header().Set(echo.HeaderContentType, echo.MIMEOctetStream)
    13  	res.Header().Set(echo.HeaderContentDisposition, `attachment; filename="heap.pprof"`)
    14  	runtime.GC() // get up-to-date statistics
    15  	return pprof.WriteHeapProfile(res)
    16  }
    17  
    18  // Routes sets the routing for the tools (like profiling).
    19  func Routes(router *echo.Group) {
    20  	router.GET("/pprof/heap", HeapProfiling)
    21  }