This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* uses net/http/pprof to help expose debug info * will be used to help diagnose memory growth
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package pprof | ||
|
||
import ( | ||
"context" | ||
log "github.com/sirupsen/logrus" | ||
"net/http" | ||
_ "net/http/pprof" | ||
) | ||
|
||
func NewServer(listenAddr string) http.Server { | ||
server := http.Server{Addr: listenAddr, Handler: http.DefaultServeMux} | ||
return server | ||
} | ||
|
||
// Starts server and shuts down when context signals | ||
func ListenAndWait(ctx context.Context, server http.Server) { | ||
go func() { | ||
err := server.ListenAndServe() | ||
if err != nil { | ||
log.Errorf("error starting pprof http server: %s", err.Error()) | ||
} | ||
}() | ||
<-ctx.Done() | ||
log.Infof("shutting down pprof server") | ||
server.Shutdown(context.Background()) | ||
} |