47 lines
667 B
Go
47 lines
667 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/http"
|
|
_ "net/http/pprof"
|
|
)
|
|
|
|
const (
|
|
pprofAddress = ":9999"
|
|
)
|
|
|
|
type pprof struct {
|
|
listener net.Listener
|
|
server *http.Server
|
|
}
|
|
|
|
func newPprof(p *program) (*pprof, error) {
|
|
listener, err := net.Listen("tcp", pprofAddress)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pp := &pprof{
|
|
listener: listener,
|
|
}
|
|
|
|
pp.server = &http.Server{
|
|
Handler: http.DefaultServeMux,
|
|
}
|
|
|
|
p.log("[pprof] opened on " + pprofAddress)
|
|
return pp, nil
|
|
}
|
|
|
|
func (pp *pprof) run() {
|
|
err := pp.server.Serve(pp.listener)
|
|
if err != http.ErrServerClosed {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (pp *pprof) close() {
|
|
pp.server.Shutdown(context.Background())
|
|
}
|