Files
renovate-sh-app[bot]GitHubrenovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>A. Stoewer
92ce383d0e fix(deps): update github.com/grafana/dskit digest to 10fce42 (#5749)
* fix(deps): update github.com/grafana/dskit digest to 10fce42

Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>

* make generate-manifest

---------

Signed-off-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>
Co-authored-by: renovate-sh-app[bot] <219655108+renovate-sh-app[bot]@users.noreply.github.com>
Co-authored-by: A. Stoewer <[email protected]>
2025-10-28 08:29:23 +10:00

52 lines
1.3 KiB
Go

package pprof
import (
"fmt"
"io"
"net/http"
"runtime"
"strconv"
"github.com/grafana/pyroscope-go/godeltaprof"
)
var (
deltaHeapProfiler = godeltaprof.NewHeapProfiler() //nolint:gochecknoglobals
deltaBlockProfiler = godeltaprof.NewBlockProfiler() //nolint:gochecknoglobals
deltaMutexProfiler = godeltaprof.NewMutexProfiler() //nolint:gochecknoglobals
)
type deltaProfiler interface {
Profile(w io.Writer) error
}
func init() {
prefix := routePrefix()
http.HandleFunc(prefix+"/debug/pprof/delta_heap", Heap)
http.HandleFunc(prefix+"/debug/pprof/delta_block", Block)
http.HandleFunc(prefix+"/debug/pprof/delta_mutex", Mutex)
}
func Heap(w http.ResponseWriter, r *http.Request) {
gc, _ := strconv.Atoi(r.FormValue("gc"))
if gc > 0 {
runtime.GC()
}
writeDeltaProfile(deltaHeapProfiler, "heap", w)
}
func Block(w http.ResponseWriter, r *http.Request) {
writeDeltaProfile(deltaBlockProfiler, "block", w)
}
func Mutex(w http.ResponseWriter, r *http.Request) {
writeDeltaProfile(deltaMutexProfiler, "mutex", w)
}
func writeDeltaProfile(p deltaProfiler, name string, w http.ResponseWriter) {
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.pprof.gz"`, name))
_ = p.Profile(w)
}