alby-hub/service/profiler.go
Adithya Vardhan e23bfa6af0
chore: remove datadog profiling (#1406)
chore: remove unused datadog dependency
2025-07-29 16:20:29 +05:30

38 lines
810 B
Go

package service
import (
"context"
"errors"
"net/http"
"net/http/pprof"
)
func startProfiler(ctx context.Context, addr string) {
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
server := &http.Server{
Addr: addr,
Handler: mux,
}
go func() {
<-ctx.Done()
err := server.Shutdown(context.Background())
if err != nil {
panic("pprof server shutdown failed: " + err.Error())
}
}()
go func() {
err := server.ListenAndServe()
if err != nil && !errors.Is(err, http.ErrServerClosed) {
panic("pprof server failed: " + err.Error())
}
}()
}