diff --git a/disperser/apiserver/pprof.go b/disperser/apiserver/pprof.go new file mode 100644 index 0000000000..606b8aa09e --- /dev/null +++ b/disperser/apiserver/pprof.go @@ -0,0 +1,31 @@ +package apiserver + +import ( + "fmt" + "net/http" + + _ "net/http/pprof" + + "github.com/Layr-Labs/eigensdk-go/logging" +) + +type PprofProfiler struct { + logger logging.Logger + httpPort string +} + +func NewPprofProfiler(httpPort string, logger logging.Logger) *PprofProfiler { + return &PprofProfiler{ + logger: logger.With("component", "PprofProfiler"), + httpPort: httpPort, + } +} + +// Start the pprof server +func (p *PprofProfiler) Start(logger logging.Logger) { + pprofAddr := fmt.Sprintf("%s:%s", "0.0.0.0", p.httpPort) + + if err := http.ListenAndServe(pprofAddr, nil); err != nil { + p.logger.Error("pprof server failed", "error", err, "pprofAddr", pprofAddr) + } +}