From c5e916b3948b852a2355f5cb404916da7e05e4a7 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 21 Nov 2024 23:42:01 +0000 Subject: [PATCH] add file --- disperser/apiserver/pprof.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 disperser/apiserver/pprof.go 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) + } +}