enable pprof http handler.

This commit is contained in:
Raúl Kripalani 2019-04-08 19:31:22 +01:00
parent 0daab6089f
commit e82c10b039
2 changed files with 40 additions and 1 deletions

View File

@ -17,8 +17,31 @@ import (
identify "github.com/libp2p/go-libp2p/p2p/protocol/identify"
multiaddr "github.com/multiformats/go-multiaddr"
promhttp "github.com/prometheus/client_golang/prometheus/promhttp"
_ "net/http/pprof"
)
func init() {
go func() {
for i := 6060; i < 7080; i++ {
addr := fmt.Sprintf("localhost:%d", i)
fmt.Printf("registering pprof debug http handler: %s\n", addr)
switch err := http.ListenAndServe(addr, nil); err {
case nil:
// all good, server is running and exited normally.
return
case http.ErrServerClosed:
// all good, server was shut down.
return
default:
// error, try another port
fmt.Printf("error registering pprof debug http handler on %s: %s\n", addr, err)
continue
}
}
}()
}
func main() {
identify.ClientVersion = "p2pd/0.1"

View File

@ -3,6 +3,7 @@
package p2pd
import (
"fmt"
"os"
"os/signal"
"syscall"
@ -27,8 +28,23 @@ func (d *Daemon) trapSignals() {
}
func (d *Daemon) handleSIGUSR1() {
// this is the state dump signal; for now just dht routing table if present
// this is the state dump signal
fmt.Println("dht routing table:")
if d.dht != nil {
d.dht.RoutingTable().Print()
}
fmt.Println("---")
fmt.Println("connections and streams:")
for _, c := range d.host.Network().Conns() {
streams := c.GetStreams()
protos, _ := d.host.Peerstore().GetProtocols(c.RemotePeer())
protoVersion, _ := d.host.Peerstore().Get(c.RemotePeer(), "ProtocolVersion")
agent, _ := d.host.Peerstore().Get(c.RemotePeer(), "AgentVersion")
fmt.Printf("to=%s; multiaddr=%s; stream_cnt= %d\n, protocols=%v; protoversion=%s; agent=%s\n",
c.RemotePeer().Pretty(), c.RemoteMultiaddr(), len(streams), protos, protoVersion, agent)
for _, s := range streams {
fmt.Println("\tprotocol: ", s.Protocol())
}
}
}